blob: faff77e78295f47e5e250a15db718c84231a09a8 [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;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000151import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800152import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800153import android.telephony.satellite.ISatelliteProvisionStateCallback;
154import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800155import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000156import android.telephony.satellite.NtnSignalStrength;
157import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800158import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000159import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800161import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800162import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800164import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700165import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800167import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800168
Andrew Lee312e8172014-10-23 17:01:36 -0700169import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800170import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800171import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800172import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800173import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700175import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700176import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800177import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800178import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700179import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800181import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700182import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800183import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800184import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800185import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700186import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000187import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700188import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800189import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800191import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800192import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800193import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700194import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700195import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700196import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700198import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800199import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700200import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700201import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700202import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700203import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800204import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800205import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700206import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000207import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700208import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700209import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800210import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800211import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700212import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000213import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800214import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700215import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700216import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800217import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700218import com.android.internal.telephony.imsphone.ImsPhone;
219import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000220import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800221import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000222import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800223import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
224import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700225import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226import com.android.internal.telephony.uicc.IccIoResult;
227import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800228import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700229import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800230import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700231import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000232import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800233import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000234import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800235import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000236import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700237import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700238import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800239import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800240import com.android.phone.callcomposer.CallComposerPictureManager;
241import com.android.phone.callcomposer.CallComposerPictureTransfer;
242import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700243import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700244import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000245import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700246import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800247import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700248import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700249import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800250import com.android.services.telephony.TelecomAccountRegistry;
251import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800252import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800253
Hall Liu82694d52020-12-11 18:22:04 -0800254import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700255import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800256import java.io.IOException;
257import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700258import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000261import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800262import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800263import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800264import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800265import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100266import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800267import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700268import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800270import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700271import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800272import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800273import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800274import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275
276/**
277 * Implementation of the ITelephony interface.
278 */
Santos Cordon117fee72014-05-16 17:56:12 -0700279public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 private static final String LOG_TAG = "PhoneInterfaceManager";
281 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
282 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284
285 // Message codes used with mMainThreadHandler
286 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700287 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
288 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700289 private static final int CMD_OPEN_CHANNEL = 9;
290 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
291 private static final int CMD_CLOSE_CHANNEL = 11;
292 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800293 private static final int CMD_NV_READ_ITEM = 13;
294 private static final int EVENT_NV_READ_ITEM_DONE = 14;
295 private static final int CMD_NV_WRITE_ITEM = 15;
296 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
297 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
298 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700299 private static final int CMD_RESET_MODEM_CONFIG = 19;
300 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800301 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
302 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800303 private static final int CMD_SEND_ENVELOPE = 25;
304 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700305 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
306 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
307 private static final int CMD_EXCHANGE_SIM_IO = 31;
308 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800309 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
310 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700311 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
312 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700313 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
314 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700315 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
316 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
317 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
318 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700319 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
320 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
321 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
322 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700323 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800324 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
325 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000326 private static final int CMD_SWITCH_SLOTS = 50;
327 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700328 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
329 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
330 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
331 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
332 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
333 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
334 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
335 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700336 private static final int CMD_GET_ALL_CELL_INFO = 60;
337 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
338 private static final int CMD_GET_CELL_LOCATION = 62;
339 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700340 private static final int CMD_MODEM_REBOOT = 64;
341 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700342 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
343 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800344 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
345 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700346 private static final int CMD_GET_MODEM_STATUS = 70;
347 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700348 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
349 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700350 private static final int CMD_ERASE_MODEM_CONFIG = 74;
351 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800352 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
353 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
354 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
355 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800356 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
357 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800359 private static final int CMD_GET_CALL_FORWARDING = 83;
360 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
361 private static final int CMD_SET_CALL_FORWARDING = 85;
362 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
363 private static final int CMD_GET_CALL_WAITING = 87;
364 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
365 private static final int CMD_SET_CALL_WAITING = 89;
366 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700367 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
368 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
369 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
370 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700371 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
372 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800373 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
374 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800375 private static final int CMD_SET_DATA_THROTTLING = 99;
376 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800377 private static final int CMD_SET_SIM_POWER = 101;
378 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800379 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
380 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
381 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
382 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800383 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
384 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000385 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800386 private static final int CMD_GET_SLICING_CONFIG = 110;
387 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800388 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700389 private static final int CMD_ENABLE_VONR = 113;
390 private static final int EVENT_ENABLE_VONR_DONE = 114;
391 private static final int CMD_IS_VONR_ENABLED = 115;
392 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700393 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
394 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000395
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800396 // Parameters of select command.
397 private static final int SELECT_COMMAND = 0xA4;
398 private static final int SELECT_P1 = 0x04;
399 private static final int SELECT_P2 = 0;
400 private static final int SELECT_P3 = 0x10;
401
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000402 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
403 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
404
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 /** The singleton instance. */
406 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800407 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
Sarah Chin4beb2b72023-02-14 14:47:54 -0800409 private final PhoneGlobals mApp;
Sarah Chincc5446f2023-10-23 17:57:19 -0700410 private final FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800411 private final CallManager mCM;
412 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000413
414 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800415 private final UserManager mUserManager;
416 private final AppOpsManager mAppOps;
417 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800418 private final SharedPreferences mTelephonySharedPreferences;
419 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800420 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Peter Wangdafb9ac2020-01-15 14:13:38 -0800422 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800423 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800424 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
425
Sarah Chin4beb2b72023-02-14 14:47:54 -0800426 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800427
Derek Tan97ebb422014-09-05 16:55:38 -0700428 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
429 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800430 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800431 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700432
Michelecea4cf22018-12-21 15:00:11 -0800433 // String to store multi SIM allowed
434 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
435
Derek Tan740e1672017-06-27 14:56:27 -0700436 // The AID of ISD-R.
437 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
438
yinxub1bed742017-04-17 11:45:04 -0700439 private NetworkScanRequestTracker mNetworkScanRequestTracker;
440
David Kelly5e06a7f2018-03-12 14:10:59 +0000441 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
442 private static final int MANUFACTURER_CODE_LENGTH = 8;
443
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800444 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800445 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800446
Sarah Chin2ec39f62022-08-31 17:03:26 -0700447 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
448 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
449
Derek Tan89e89d42014-07-08 17:00:10 -0700450 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700451 * Experiment flag to enable erase modem config on reset network, default value is false
452 */
453 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
454 "reset_network_erase_modem_config_enabled";
455
Rambo Wang0f050d82021-02-12 11:43:36 -0800456 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800457
Gary Jian76280a42022-12-07 16:18:33 +0800458 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
459
sandeepjsb6c87872021-09-27 15:34:44 +0000460 /**
461 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
462 * one ICCID active at the same time.
463 * Apps should use below API signatures if targeting SDK is T and beyond.
464 *
465 * @hide
466 */
467 @ChangeId
468 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
469 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800470
Naina Nallurid63128d2019-09-17 14:10:30 -0700471 /**
Chen Xu540470b2021-12-14 17:15:47 -0800472 * Apps targeting on Android T and beyond will get exception whenever icc close channel
473 * operation fails.
474 */
475 @ChangeId
476 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
477 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
478
479 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 * A request object to use for transmitting data to an ICC.
481 */
482 private static final class IccAPDUArgument {
483 public int channel, cla, command, p1, p2, p3;
484 public String data;
485
486 public IccAPDUArgument(int channel, int cla, int command,
487 int p1, int p2, int p3, String data) {
488 this.channel = channel;
489 this.cla = cla;
490 this.command = command;
491 this.p1 = p1;
492 this.p2 = p2;
493 this.p3 = p3;
494 this.data = data;
495 }
496 }
497
498 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700499 * A request object to use for transmitting data to an ICC.
500 */
501 private static final class ManualNetworkSelectionArgument {
502 public OperatorInfo operatorInfo;
503 public boolean persistSelection;
504
505 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
506 this.operatorInfo = operatorInfo;
507 this.persistSelection = persistSelection;
508 }
509 }
510
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 private static final class PurchasePremiumCapabilityArgument {
512 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 public @NonNull IIntegerConsumer callback;
514
515 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800516 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700517 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700518 this.callback = callback;
519 }
520 }
521
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700522 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
524 * request after sending. The main thread will notify the request when it is complete.
525 */
526 private static final class MainThreadRequest {
527 /** The argument to use for the request */
528 public Object argument;
529 /** The result of the request that is run on the main thread */
530 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800531 // The subscriber id that this request applies to. Defaults to
532 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
533 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534
Nathan Harold92bed182018-10-12 18:16:49 -0700535 // In cases where subId is unavailable, the caller needs to specify the phone.
536 public Phone phone;
537
vagdeviaf9a5b92018-08-15 16:01:53 -0700538 public WorkSource workSource;
539
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 public MainThreadRequest(Object argument) {
541 this.argument = argument;
542 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800543
Nathan Harold92bed182018-10-12 18:16:49 -0700544 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
545 this.argument = argument;
546 if (phone != null) {
547 this.phone = phone;
548 }
549 this.workSource = workSource;
550 }
551
vagdeviaf9a5b92018-08-15 16:01:53 -0700552 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800553 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800554 if (subId != null) {
555 this.subId = subId;
556 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700557 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700559 }
560
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800561 private static final class IncomingThirdPartyCallArgs {
562 public final ComponentName component;
563 public final String callId;
564 public final String callerDisplayName;
565
566 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
567 String callerDisplayName) {
568 this.component = component;
569 this.callId = callId;
570 this.callerDisplayName = callerDisplayName;
571 }
572 }
573
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 /**
575 * A handler that processes messages on the main thread in the phone process. Since many
576 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
577 * inbound binder threads to the main thread in the phone process. The Binder thread
578 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
579 * on, which will be notified when the operation completes and will contain the result of the
580 * request.
581 *
582 * <p>If a MainThreadRequest object is provided in the msg.obj field,
583 * note that request.result must be set to something non-null for the calling thread to
584 * unblock.
585 */
586 private final class MainThreadHandler extends Handler {
587 @Override
588 public void handleMessage(Message msg) {
589 MainThreadRequest request;
590 Message onCompleted;
591 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000592 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800594 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595
596 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 case CMD_HANDLE_USSD_REQUEST: {
598 request = (MainThreadRequest) msg.obj;
599 final Phone phone = getPhoneFromRequest(request);
600 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800601 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700603
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 if (!isUssdApiAllowed(request.subId)) {
605 // Carrier does not support use of this API, return failure.
606 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
607 UssdResponse response = new UssdResponse(ussdRequest, null);
608 Bundle returnData = new Bundle();
609 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
610 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700611
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 request.result = true;
613 notifyRequester(request);
614 return;
615 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700616
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 try {
618 request.result = phone != null
619 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
620 } catch (CallStateException cse) {
621 request.result = false;
622 }
623 // Wake up the requesting thread
624 notifyRequester(request);
625 break;
pkanwar32d516d2016-10-14 19:37:38 -0700626 }
627
Yorke Lee716f67e2015-06-17 15:39:16 -0700628 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700630 final Phone phone = getPhoneFromRequest(request);
631 request.result = phone != null ?
632 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
633 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700638
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000642 uiccPort = getUiccPortFromRequest(request);
643 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800651 iccArgument.channel, iccArgument.cla, iccArgument.command,
652 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
653 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 break;
656
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result;
662 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800663 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 if (ar.result == null) {
665 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800666 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800668 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
670 loge("iccTransmitApduLogicalChannel: Unknown exception");
671 }
672 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
678 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000679 uiccPort = getUiccPortFromRequest(request);
680 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800688 iccArgument.cla, iccArgument.command, iccArgument.p1,
689 iccArgument.p2,
690 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 }
692 break;
693
694 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
697 if (ar.exception == null && ar.result != null) {
698 request.result = ar.result;
699 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 if (ar.result == null) {
702 loge("iccTransmitApduBasicChannel: Empty response");
703 } else if (ar.exception instanceof CommandException) {
704 loge("iccTransmitApduBasicChannel: CommandException: " +
705 ar.exception);
706 } else {
707 loge("iccTransmitApduBasicChannel: Unknown exception");
708 }
709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 break;
712
713 case CMD_EXCHANGE_SIM_IO:
714 request = (MainThreadRequest) msg.obj;
715 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000716 uiccPort = getUiccPortFromRequest(request);
717 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800719 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 } else {
722 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
723 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
726 iccArgument.data, onCompleted);
727 }
728 break;
729
730 case EVENT_EXCHANGE_SIM_IO_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result;
735 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800736 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 break;
740
Derek Tan4d5e5c12014-02-04 11:54:58 -0800741 case CMD_SEND_ENVELOPE:
742 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort = getUiccPortFromRequest(request);
744 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800746 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 } else {
749 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800750 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800752 break;
753
754 case EVENT_SEND_ENVELOPE_DONE:
755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700757 if (ar.exception == null && ar.result != null) {
758 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800759 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800760 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700761 if (ar.result == null) {
762 loge("sendEnvelopeWithStatus: Empty response");
763 } else if (ar.exception instanceof CommandException) {
764 loge("sendEnvelopeWithStatus: CommandException: " +
765 ar.exception);
766 } else {
767 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
768 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800771 break;
772
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 case CMD_OPEN_CHANNEL:
774 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000775 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800776 IccLogicalChannelRequest openChannelRequest =
777 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000778 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800780 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700782 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 } else {
784 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800785 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
786 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 break;
789
790 case EVENT_OPEN_CHANNEL_DONE:
791 ar = (AsyncResult) msg.obj;
792 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700793 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700794 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700795 int[] result = (int[]) ar.result;
796 int channelId = result[0];
797 byte[] selectResponse = null;
798 if (result.length > 1) {
799 selectResponse = new byte[result.length - 1];
800 for (int i = 1; i < result.length; ++i) {
801 selectResponse[i - 1] = (byte) result[i];
802 }
803 }
804 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800805 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800806
807 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700808 if (uiccPort == null) {
809 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
810 } else {
811 IccLogicalChannelRequest channelRequest =
812 (IccLogicalChannelRequest) request.argument;
813 channelRequest.channel = channelId;
814 uiccPort.onLogicalChannelOpened(channelRequest);
815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 if (ar.result == null) {
818 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700820 if (ar.exception != null) {
821 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
822 }
823
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700824 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700825 if (ar.exception instanceof CommandException) {
826 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800827 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700828 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700829 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700830 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700831 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700832 }
833 }
834 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800835 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700837 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700838 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 break;
840
841 case CMD_CLOSE_CHANNEL:
842 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000843 uiccPort = getUiccPortFromRequest(request);
844 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800846 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800847 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800848 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700849 } else {
850 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000851 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 break;
854
855 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null) {
859 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800860 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700861 if (uiccPort == null) {
862 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
863 } else {
864 final int channelId = (Integer) request.argument;
865 uiccPort.onLogicalChannelClosed(channelId);
866 }
Chen Xu540470b2021-12-14 17:15:47 -0800867 } else {
868 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800869 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800870 if (ar.exception instanceof CommandException) {
871 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800874 if (error == CommandException.Error.INVALID_ARGUMENTS) {
875 // should only throw exceptions from the binder threads.
876 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800877 "iccCloseLogicalChannel: invalid argument ");
878 }
879 } else {
880 loge("iccCloseLogicalChannel: Unknown exception");
881 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800882 request.result = (exception != null) ? exception :
883 new IllegalStateException(
884 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800885 }
886 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
889 case CMD_NV_READ_ITEM:
890 request = (MainThreadRequest) msg.obj;
891 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800892 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
893 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800894 break;
895
896 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700901 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800902 request.result = "";
903 if (ar.result == null) {
904 loge("nvReadItem: Empty response");
905 } else if (ar.exception instanceof CommandException) {
906 loge("nvReadItem: CommandException: " +
907 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700908 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800909 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700913 break;
914
Jake Hambye994d462014-02-03 13:10:13 -0800915 case CMD_NV_WRITE_ITEM:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
918 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700920 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800921 break;
922
923 case EVENT_NV_WRITE_ITEM_DONE:
924 handleNullReturnEvent(msg, "nvWriteItem");
925 break;
926
927 case CMD_NV_WRITE_CDMA_PRL:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800930 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800931 break;
932
933 case EVENT_NV_WRITE_CDMA_PRL_DONE:
934 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
935 break;
936
chen xu6dac5ab2018-10-26 17:39:23 -0700937 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800938 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700939 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800940 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
chen xu6dac5ab2018-10-26 17:39:23 -0700943 case EVENT_RESET_MODEM_CONFIG_DONE:
944 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800945 break;
946
Sooraj Sasindran37444802020-08-11 10:40:43 -0700947 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
950 request);
951 Phone phone = getPhoneFromRequest(request);
952 if (phone != null) {
953 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
954 } else {
955 loge("isNRDualConnectivityEnabled: No phone object");
956 request.result = false;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null && ar.result != null) {
966 request.result = ar.result;
967 } else {
968 // request.result must be set to something non-null
969 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700970 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700971 request.result = ar.result;
972 } else {
973 request.result = false;
974 }
975 if (ar.result == null) {
976 loge("isNRDualConnectivityEnabled: Empty response");
977 } else if (ar.exception instanceof CommandException) {
978 loge("isNRDualConnectivityEnabled: CommandException: "
979 + ar.exception);
980 } else {
981 loge("isNRDualConnectivityEnabled: Unknown exception");
982 }
983 }
984 notifyRequester(request);
985 break;
986
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700987 case CMD_IS_VONR_ENABLED: {
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
990 request);
991 Phone phone = getPhoneFromRequest(request);
992 if (phone != null) {
993 phone.isVoNrEnabled(onCompleted, request.workSource);
994 } else {
995 loge("isVoNrEnabled: No phone object");
996 request.result = false;
997 notifyRequester(request);
998 }
999 break;
1000 }
1001
1002 case EVENT_IS_VONR_ENABLED_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 if (ar.exception == null && ar.result != null) {
1006 request.result = ar.result;
1007 } else {
1008 // request.result must be set to something non-null
1009 // for the calling thread to unblock
1010 if (ar.result != null) {
1011 request.result = ar.result;
1012 } else {
1013 request.result = false;
1014 }
1015 if (ar.result == null) {
1016 loge("isVoNrEnabled: Empty response");
1017 } else if (ar.exception instanceof CommandException) {
1018 loge("isVoNrEnabled: CommandException: "
1019 + ar.exception);
1020 } else {
1021 loge("isVoNrEnabled: Unknown exception");
1022 }
1023 }
1024 notifyRequester(request);
1025 break;
1026
Sooraj Sasindran37444802020-08-11 10:40:43 -07001027 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1030 Phone phone = getPhoneFromRequest(request);
1031 if (phone != null) {
1032 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1033 request.workSource);
1034 } else {
1035 loge("enableNrDualConnectivity: No phone object");
1036 request.result =
1037 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1038 notifyRequester(request);
1039 }
1040 break;
1041 }
1042
1043 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 if (ar.exception == null) {
1047 request.result =
1048 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1049 } else {
1050 request.result =
1051 TelephonyManager
1052 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1053 if (ar.exception instanceof CommandException) {
1054 CommandException.Error error =
1055 ((CommandException) (ar.exception)).getCommandError();
1056 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1057 request.result =
1058 TelephonyManager
1059 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1061 request.result =
1062 TelephonyManager
1063 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001064 }
1065 loge("enableNrDualConnectivity" + ": CommandException: "
1066 + ar.exception);
1067 } else {
1068 loge("enableNrDualConnectivity" + ": Unknown exception");
1069 }
1070 }
1071 notifyRequester(request);
1072 break;
1073 }
1074
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001075 case CMD_ENABLE_VONR: {
1076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1078 Phone phone = getPhoneFromRequest(request);
1079 if (phone != null) {
1080 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1081 request.workSource);
1082 } else {
1083 loge("setVoNrEnabled: No phone object");
1084 request.result =
1085 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1086 notifyRequester(request);
1087 }
1088 break;
1089 }
1090
1091 case EVENT_ENABLE_VONR_DONE: {
1092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1096 } else {
1097 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1098 if (ar.exception instanceof CommandException) {
1099 CommandException.Error error =
1100 ((CommandException) (ar.exception)).getCommandError();
1101 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1103 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1104 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1105 } else {
1106 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1107 }
1108 loge("setVoNrEnabled" + ": CommandException: "
1109 + ar.exception);
1110 } else {
1111 loge("setVoNrEnabled" + ": Unknown exception");
1112 }
1113 }
1114 notifyRequester(request);
1115 break;
1116 }
1117
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1121 request);
1122 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 break;
1124
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
1128 if (ar.exception == null && ar.result != null) {
1129 request.result = ar.result; // Integer
1130 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301131 // request.result must be set to something non-null
1132 // for the calling thread to unblock
1133 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 loge("getAllowedNetworkTypesBitmask: CommandException: "
1138 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 }
1142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 break;
1145
SongFerngWang3ef3e072020-12-21 16:41:52 +08001146 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001147 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1149 request);
1150 Pair<Integer, Long> reasonWithNetworkTypes =
1151 (Pair<Integer, Long>) request.argument;
1152 getPhoneFromRequest(request).setAllowedNetworkTypes(
1153 reasonWithNetworkTypes.first,
1154 reasonWithNetworkTypes.second,
1155 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1159 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 break;
1161
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001162 case CMD_SET_VOICEMAIL_NUMBER:
1163 request = (MainThreadRequest) msg.obj;
1164 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1165 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001166 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1167 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001168 break;
1169
1170 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1171 handleNullReturnEvent(msg, "setVoicemailNumber");
1172 break;
1173
Stuart Scott54788802015-03-30 13:18:01 -07001174 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1175 request = (MainThreadRequest) msg.obj;
1176 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1177 request);
1178 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1179 break;
1180
1181 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1182 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1183 break;
1184
Shishir Agrawal302c8692015-06-19 13:49:39 -07001185 case CMD_PERFORM_NETWORK_SCAN:
1186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1188 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1189 break;
1190
Hall Liu27d24262020-09-18 19:04:59 -07001191 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001194 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1195 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1196 request.argument;
1197 int callForwardingReason = args.first;
1198 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001199 break;
Hall Liu27d24262020-09-18 19:04:59 -07001200 }
1201 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001204 TelephonyManager.CallForwardingInfoCallback callback =
1205 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1206 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001208 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1210 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1211 // Service Class is a bit mask per 3gpp 27.007. Search for
1212 // any service for voice call.
1213 if ((callForwardInfo.serviceClass
1214 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001215 callForwardingInfo = new CallForwardingInfo(
1216 callForwardInfo.status
1217 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001218 callForwardInfo.reason,
1219 callForwardInfo.number,
1220 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 break;
1222 }
1223 }
1224 // Didn't find a call forward info for voice call.
1225 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001226 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1227 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
Hall Liu27d24262020-09-18 19:04:59 -07001229 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 } else {
1231 if (ar.result == null) {
1232 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1233 }
1234 if (ar.exception != null) {
1235 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1236 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 int errorCode = TelephonyManager
1238 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 if (ar.exception instanceof CommandException) {
1240 CommandException.Error error =
1241 ((CommandException) (ar.exception)).getCommandError();
1242 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 errorCode = TelephonyManager
1244 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001245 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 errorCode = TelephonyManager
1247 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001248 }
1249 }
Hall Liu27d24262020-09-18 19:04:59 -07001250 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252 break;
Hall Liu27d24262020-09-18 19:04:59 -07001253 }
Shuo Qian4a594052020-01-23 11:59:30 -08001254
Hall Liu27d24262020-09-18 19:04:59 -07001255 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001256 request = (MainThreadRequest) msg.obj;
1257 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001258 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001259 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001260 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1261 request.argument).first;
1262 request.phone.setCallForwardingOption(
1263 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001264 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001265 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001266 callForwardingInfoToSet.getReason(),
1267 callForwardingInfoToSet.getNumber(),
1268 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1269 break;
Hall Liu27d24262020-09-18 19:04:59 -07001270 }
Shuo Qian4a594052020-01-23 11:59:30 -08001271
Hall Liu27d24262020-09-18 19:04:59 -07001272 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001273 ar = (AsyncResult) msg.obj;
1274 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001275 Consumer<Integer> callback =
1276 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1277 request.argument).second;
1278 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001279 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001280 int errorCode = TelephonyManager.CallForwardingInfoCallback
1281 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001282 if (ar.exception instanceof CommandException) {
1283 CommandException.Error error =
1284 ((CommandException) (ar.exception)).getCommandError();
1285 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001286 errorCode = TelephonyManager.CallForwardingInfoCallback
1287 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001288 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 errorCode = TelephonyManager.CallForwardingInfoCallback
1290 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001291 }
1292 }
1293 callback.accept(errorCode);
1294 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001295 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001296 }
Shuo Qian4a594052020-01-23 11:59:30 -08001297 break;
Hall Liu27d24262020-09-18 19:04:59 -07001298 }
Shuo Qian4a594052020-01-23 11:59:30 -08001299
Hall Liu27d24262020-09-18 19:04:59 -07001300 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 request = (MainThreadRequest) msg.obj;
1302 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1303 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001310 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001311 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001312 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001313 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001314 // Service Class is a bit mask per 3gpp 27.007.
1315 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001316 if (callForwardResults.length > 1
1317 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001318 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001320 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1321 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001322 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001323 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001324 }
1325 } else {
1326 if (ar.result == null) {
1327 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1328 }
1329 if (ar.exception != null) {
1330 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1331 }
1332 if (ar.exception instanceof CommandException) {
1333 CommandException.Error error =
1334 ((CommandException) (ar.exception)).getCommandError();
1335 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001337 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1339 callWaitingStatus =
1340 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
1342 }
1343 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001344 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001345 break;
Hall Liu27d24262020-09-18 19:04:59 -07001346 }
Shuo Qian4a594052020-01-23 11:59:30 -08001347
Hall Liu27d24262020-09-18 19:04:59 -07001348 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001349 request = (MainThreadRequest) msg.obj;
1350 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001351 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1352 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001353 break;
Hall Liu27d24262020-09-18 19:04:59 -07001354 }
Shuo Qian4a594052020-01-23 11:59:30 -08001355
Hall Liu27d24262020-09-18 19:04:59 -07001356 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001357 ar = (AsyncResult) msg.obj;
1358 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001359 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1360 Consumer<Integer> callback =
1361 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1362 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001363 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001364 if (ar.exception instanceof CommandException) {
1365 CommandException.Error error =
1366 ((CommandException) (ar.exception)).getCommandError();
1367 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1368 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001369 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1370 callback.accept(
1371 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001372 } else {
1373 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1374 }
1375 } else {
1376 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1377 }
1378 } else {
1379 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1380 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001381 }
Shuo Qian4a594052020-01-23 11:59:30 -08001382 break;
Hall Liu27d24262020-09-18 19:04:59 -07001383 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001384 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 CellNetworkScanResult cellScanResult;
1388 if (ar.exception == null && ar.result != null) {
1389 cellScanResult = new CellNetworkScanResult(
1390 CellNetworkScanResult.STATUS_SUCCESS,
1391 (List<OperatorInfo>) ar.result);
1392 } else {
1393 if (ar.result == null) {
1394 loge("getCellNetworkScanResults: Empty response");
1395 }
1396 if (ar.exception != null) {
1397 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1398 }
1399 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1400 if (ar.exception instanceof CommandException) {
1401 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001402 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1404 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1405 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1406 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1407 }
1408 }
1409 cellScanResult = new CellNetworkScanResult(errorCode, null);
1410 }
1411 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001412 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001413 break;
1414
1415 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1416 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001417 ManualNetworkSelectionArgument selArg =
1418 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001419 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1420 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001421 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1422 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001423 break;
1424
1425 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception == null) {
1429 request.result = true;
1430 } else {
1431 request.result = false;
1432 loge("setNetworkSelectionModeManual " + ar.exception);
1433 }
1434 notifyRequester(request);
1435 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 break;
1437
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001438 case CMD_GET_MODEM_ACTIVITY_INFO:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001441 if (defaultPhone != null) {
1442 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001443 } else {
1444 ResultReceiver result = (ResultReceiver) request.argument;
1445 Bundle bundle = new Bundle();
1446 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001447 new ModemActivityInfo(0, 0, 0,
1448 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001449 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001450 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 break;
1452
Hall Liud0f208c2020-10-14 16:54:44 -07001453 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001457 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001458 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001459 if (mLastModemActivityInfo == null) {
1460 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1461 mLastModemActivitySpecificInfo[0] =
1462 new ActivityStatsTechSpecificInfo(
1463 0,
1464 0,
1465 new int[ModemActivityInfo.getNumTxPowerLevels()],
1466 0);
1467 mLastModemActivityInfo =
1468 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1469 }
1470
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 // Update the last modem activity info and the result of the request.
1473 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1474 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001475 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001476 } else {
1477 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 }
Kai Shi917fdc62022-11-28 14:01:02 -08001479 // This is needed to decouple ret from mLastModemActivityInfo
1480 // We don't want to return mLastModemActivityInfo which is updated
1481 // inside mergeModemActivityInfo()
1482 ret = new ModemActivityInfo(
1483 mLastModemActivityInfo.getTimestampMillis(),
1484 mLastModemActivityInfo.getSleepTimeMillis(),
1485 mLastModemActivityInfo.getIdleTimeMillis(),
1486 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001487
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 } else {
1489 if (ar.result == null) {
1490 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001491 error = TelephonyManager.ModemActivityInfoException
1492 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001494 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001495 error = TelephonyManager.ModemActivityInfoException
1496 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 } else {
1498 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001499 error = TelephonyManager.ModemActivityInfoException
1500 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001501 }
1502 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001503 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001504 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001505 bundle.putParcelable(
1506 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001507 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001508 } else {
1509 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1510 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001511 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001512 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001513 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001514 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001516 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001518 CarrierRestrictionRules argument =
1519 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001521 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001523 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524
1525 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 if (ar.exception == null && ar.result != null) {
1529 request.result = ar.result;
1530 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001531 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1532 if (ar.exception instanceof CommandException) {
1533 loge("setAllowedCarriers: CommandException: " + ar.exception);
1534 CommandException.Error error =
1535 ((CommandException) (ar.exception)).getCommandError();
1536 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1537 request.result =
1538 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1539 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 } else {
1541 loge("setAllowedCarriers: Unknown exception");
1542 }
1543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
1546
1547 case CMD_GET_ALLOWED_CARRIERS:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001550 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551 break;
1552
1553 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1554 ar = (AsyncResult) msg.obj;
1555 request = (MainThreadRequest) ar.userObj;
1556 if (ar.exception == null && ar.result != null) {
1557 request.result = ar.result;
1558 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001559 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001560 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001561 if (ar.result == null) {
1562 loge("getAllowedCarriers: Empty response");
1563 } else if (ar.exception instanceof CommandException) {
1564 loge("getAllowedCarriers: CommandException: " +
1565 ar.exception);
1566 } else {
1567 loge("getAllowedCarriers: Unknown exception");
1568 }
1569 }
arunvoddud7401012022-12-15 16:08:12 +00001570 if (request.argument != null) {
1571 // This is for the implementation of carrierRestrictionStatus.
1572 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1573 Consumer<Integer> callback = callbackInfo.getConsumer();
1574 int callerCarrierId = callbackInfo.getCarrierId();
1575 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1576 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1577 CarrierRestrictionRules carrierRestrictionRules =
1578 (CarrierRestrictionRules) ar.result;
1579 int carrierId = -1;
1580 try {
1581 CarrierIdentifier carrierIdentifier =
1582 carrierRestrictionRules.getAllowedCarriers().get(0);
1583 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1584 carrierIdentifier);
1585 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1586 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1587 }
1588 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1589 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1590 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001591 lockStatus = TelephonyManager
1592 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001593 }
1594 } else {
1595 Rlog.e(LOG_TAG,
1596 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1597 }
1598 callback.accept(lockStatus);
1599 } else {
1600 // This is for the implementation of getAllowedCarriers.
1601 notifyRequester(request);
1602 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001603 break;
1604
Nathan Haroldb3014052017-01-25 15:57:32 -08001605 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
1608 if (ar.exception == null && ar.result != null) {
1609 request.result = ar.result;
1610 } else {
1611 request.result = new IllegalArgumentException(
1612 "Failed to retrieve Forbidden Plmns");
1613 if (ar.result == null) {
1614 loge("getForbiddenPlmns: Empty response");
1615 } else {
1616 loge("getForbiddenPlmns: Unknown exception");
1617 }
1618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001619 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001620 break;
1621
1622 case CMD_GET_FORBIDDEN_PLMNS:
1623 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001624 uiccPort = getUiccPortFromRequest(request);
1625 if (uiccPort == null) {
1626 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001627 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001628 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001629 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 break;
1631 }
1632 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001633 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 if (uiccApp == null) {
1635 loge("getForbiddenPlmns() no app with specified type -- "
1636 + appType);
1637 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 break;
1640 } else {
1641 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1642 + " specified type -- " + appType);
1643 }
1644 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1645 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001646 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 break;
1648
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001649 case CMD_SWITCH_SLOTS:
1650 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001651 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001652 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001653 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001654 break;
1655
1656 case EVENT_SWITCH_SLOTS_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
1659 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001660 notifyRequester(request);
1661 break;
1662 case CMD_GET_NETWORK_SELECTION_MODE:
1663 request = (MainThreadRequest) msg.obj;
1664 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1665 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1666 break;
1667
1668 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1669 ar = (AsyncResult) msg.obj;
1670 request = (MainThreadRequest) ar.userObj;
1671 if (ar.exception != null) {
1672 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1673 } else {
1674 int mode = ((int[]) ar.result)[0];
1675 if (mode == 0) {
1676 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1677 } else {
1678 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1679 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001681 notifyRequester(request);
1682 break;
1683 case CMD_GET_CDMA_ROAMING_MODE:
1684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1686 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1687 break;
1688 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
1691 if (ar.exception != null) {
1692 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1693 } else {
1694 request.result = ((int[]) ar.result)[0];
1695 }
1696 notifyRequester(request);
1697 break;
1698 case CMD_SET_CDMA_ROAMING_MODE:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1701 int mode = (int) request.argument;
1702 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1703 break;
1704 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 request.result = ar.exception == null;
1708 notifyRequester(request);
1709 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001710 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1711 request = (MainThreadRequest) msg.obj;
1712 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1713 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1714 break;
1715 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 if (ar.exception != null) {
1719 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1720 } else {
1721 request.result = ((int[]) ar.result)[0];
1722 }
1723 notifyRequester(request);
1724 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001725 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1728 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001729 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1730 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001731 break;
1732 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 request.result = ar.exception == null;
1736 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001737 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 case CMD_GET_ALL_CELL_INFO:
1739 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001741 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001743 case EVENT_GET_ALL_CELL_INFO_DONE:
1744 ar = (AsyncResult) msg.obj;
1745 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001746 // If a timeout occurs, the response will be null
1747 request.result = (ar.exception == null && ar.result != null)
1748 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 synchronized (request) {
1750 request.notifyAll();
1751 }
1752 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001753 case CMD_REQUEST_CELL_INFO_UPDATE:
1754 request = (MainThreadRequest) msg.obj;
1755 request.phone.requestCellInfoUpdate(request.workSource,
1756 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1757 break;
1758 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
1761 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1762 try {
1763 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001764 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001765 cb.onError(
1766 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1767 ar.exception.getClass().getName(),
1768 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001769 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001770 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001771 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001772 } else {
1773 // use the result as returned
1774 cb.onCellInfo((List<CellInfo>) ar.result);
1775 }
1776 } catch (RemoteException re) {
1777 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1778 }
1779 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001780 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001781 request = (MainThreadRequest) msg.obj;
1782 WorkSource ws = (WorkSource) request.argument;
1783 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001784 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001785 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001786 }
1787 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790 if (ar.exception == null) {
1791 request.result = ar.result;
1792 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001793 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001795 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001796 }
1797
1798 synchronized (request) {
1799 request.notifyAll();
1800 }
1801 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 }
chen xu6dac5ab2018-10-26 17:39:23 -07001803 case CMD_MODEM_REBOOT:
1804 request = (MainThreadRequest) msg.obj;
1805 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001806 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001807 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001808 case EVENT_CMD_MODEM_REBOOT_DONE:
1809 handleNullReturnEvent(msg, "rebootModem");
1810 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001811 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001812 request = (MainThreadRequest) msg.obj;
1813 boolean enable = (boolean) request.argument;
1814 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001815 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001816 PhoneConfigurationManager.getInstance()
1817 .enablePhone(request.phone, enable, onCompleted);
1818 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001819 }
Michele Berionne5e411512020-11-13 02:36:59 +00001820 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001821 ar = (AsyncResult) msg.obj;
1822 request = (MainThreadRequest) ar.userObj;
1823 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001824 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001825 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001826 if ((boolean) request.result) {
1827 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1828 updateModemStateMetrics();
1829 } else {
1830 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1831 + ar.exception);
1832 }
1833 notifyRequester(request);
1834 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001835 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001836 case CMD_GET_MODEM_STATUS:
1837 request = (MainThreadRequest) msg.obj;
1838 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1839 PhoneConfigurationManager.getInstance()
1840 .getPhoneStatusFromModem(request.phone, onCompleted);
1841 break;
1842 case EVENT_GET_MODEM_STATUS_DONE:
1843 ar = (AsyncResult) msg.obj;
1844 request = (MainThreadRequest) ar.userObj;
1845 int id = request.phone.getPhoneId();
1846 if (ar.exception == null && ar.result != null) {
1847 request.result = ar.result;
1848 //update the cache as modem status has changed
1849 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1850 (boolean) request.result);
1851 } else {
1852 // Return true if modem status cannot be retrieved. For most cases,
1853 // modem status is on. And for older version modems, GET_MODEM_STATUS
1854 // and disable modem are not supported. Modem is always on.
1855 // TODO: this should be fixed in R to support a third
1856 // status UNKNOWN b/131631629
1857 request.result = true;
1858 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1859 + ar.exception);
1860 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001861 notifyRequester(request);
1862 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001863 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1864 request = (MainThreadRequest) msg.obj;
1865 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1866 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1867 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1868 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1869 break;
1870 }
1871 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1872 ar = (AsyncResult) msg.obj;
1873 request = (MainThreadRequest) ar.userObj;
1874 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1875 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1876 args.second.accept(ar.exception == null);
1877 notifyRequester(request);
1878 break;
1879 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001880 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1883 Phone phone = getPhoneFromRequest(request);
1884 if (phone != null) {
1885 phone.getSystemSelectionChannels(onCompleted);
1886 } else {
1887 loge("getSystemSelectionChannels: No phone object");
1888 request.result = new ArrayList<RadioAccessSpecifier>();
1889 notifyRequester(request);
1890 }
1891 break;
1892 }
1893 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1894 ar = (AsyncResult) msg.obj;
1895 request = (MainThreadRequest) ar.userObj;
1896 if (ar.exception == null && ar.result != null) {
1897 request.result = ar.result;
1898 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001899 request.result = new IllegalStateException(
1900 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001901 if (ar.result == null) {
1902 loge("getSystemSelectionChannels: Empty response");
1903 } else {
1904 loge("getSystemSelectionChannels: Unknown exception");
1905 }
1906 }
1907 notifyRequester(request);
1908 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001909 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912 if (ar.exception == null && ar.result != null) {
1913 request.result = ar.result;
1914 } else {
1915 request.result = -1;
1916 loge("Failed to set Forbidden Plmns");
1917 if (ar.result == null) {
1918 loge("setForbidenPlmns: Empty response");
1919 } else if (ar.exception != null) {
1920 loge("setForbiddenPlmns: Exception: " + ar.exception);
1921 request.result = -1;
1922 } else {
1923 loge("setForbiddenPlmns: Unknown exception");
1924 }
1925 }
1926 notifyRequester(request);
1927 break;
1928 case CMD_SET_FORBIDDEN_PLMNS:
1929 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001930 uiccPort = getUiccPortFromRequest(request);
1931 if (uiccPort == null) {
1932 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001933 request.result = -1;
1934 notifyRequester(request);
1935 break;
1936 }
1937 Pair<Integer, List<String>> setFplmnsArgs =
1938 (Pair<Integer, List<String>>) request.argument;
1939 appType = setFplmnsArgs.first;
1940 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001941 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001942 if (uiccApp == null) {
1943 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1944 request.result = -1;
1945 loge("Failed to get UICC App");
1946 notifyRequester(request);
1947 } else {
1948 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1949 ((SIMRecords) uiccApp.getIccRecords())
1950 .setForbiddenPlmns(onCompleted, fplmns);
1951 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001952 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001953 case CMD_ERASE_MODEM_CONFIG:
1954 request = (MainThreadRequest) msg.obj;
1955 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1956 defaultPhone.eraseModemConfig(onCompleted);
1957 break;
1958 case EVENT_ERASE_MODEM_CONFIG_DONE:
1959 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001960 break;
zoey chene02881a2019-12-30 16:11:23 +08001961
Kai Shif70f46f2021-03-03 13:59:46 -08001962 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1963 request = (MainThreadRequest) msg.obj;
1964 request.result = defaultPhone.eraseDataInSharedPreferences();
1965 notifyRequester(request);
1966 break;
1967
zoey chene02881a2019-12-30 16:11:23 +08001968 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1969 request = (MainThreadRequest) msg.obj;
1970 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1971 Pair<String, String> changed = (Pair<String, String>) request.argument;
1972 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1973 changed.first, changed.second, onCompleted);
1974 break;
1975 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1976 ar = (AsyncResult) msg.obj;
1977 request = (MainThreadRequest) ar.userObj;
1978 if (ar.exception == null) {
1979 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001980 // If the operation is successful, update the PIN storage
1981 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1982 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001983 UiccController.getInstance().getPinStorage()
1984 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001985 } else {
1986 request.result = msg.arg1;
1987 }
1988 notifyRequester(request);
1989 break;
1990
Michele Berionne5e411512020-11-13 02:36:59 +00001991 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001992 request = (MainThreadRequest) msg.obj;
1993 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1994 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1995 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1996 enabled.first, enabled.second, onCompleted);
1997 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001998 }
zoey chene02881a2019-12-30 16:11:23 +08001999 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 if (ar.exception == null) {
2003 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002004 // If the operation is successful, update the PIN storage
2005 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2006 int phoneId = getPhoneFromRequest(request).getPhoneId();
2007 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002008 UiccController.getInstance().getPinStorage()
2009 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002010 } else {
2011 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2012 }
zoey chene02881a2019-12-30 16:11:23 +08002013 } else {
2014 request.result = msg.arg1;
2015 }
Michele Berionne5e411512020-11-13 02:36:59 +00002016
2017
zoey chene02881a2019-12-30 16:11:23 +08002018 notifyRequester(request);
2019 break;
2020
Peter Wangdafb9ac2020-01-15 14:13:38 -08002021 case MSG_NOTIFY_USER_ACTIVITY:
2022 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002023 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002024 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2025 getDefaultPhone().getContext().sendBroadcastAsUser(
2026 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2027 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002028
2029 case CMD_SET_DATA_THROTTLING: {
2030 request = (MainThreadRequest) msg.obj;
2031 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2032 DataThrottlingRequest dataThrottlingRequest =
2033 (DataThrottlingRequest) request.argument;
2034 Phone phone = getPhoneFromRequest(request);
2035 if (phone != null) {
2036 phone.setDataThrottling(onCompleted,
2037 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2038 dataThrottlingRequest.getCompletionDurationMillis());
2039 } else {
2040 loge("setDataThrottling: No phone object");
2041 request.result =
2042 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2043 notifyRequester(request);
2044 }
2045
2046 break;
2047 }
2048 case EVENT_SET_DATA_THROTTLING_DONE:
2049 ar = (AsyncResult) msg.obj;
2050 request = (MainThreadRequest) ar.userObj;
2051
2052 if (ar.exception == null) {
2053 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2054 } else if (ar.exception instanceof CommandException) {
2055 loge("setDataThrottling: CommandException: " + ar.exception);
2056 CommandException.Error error =
2057 ((CommandException) (ar.exception)).getCommandError();
2058
2059 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2060 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002061 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002062 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2063 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002064 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2065 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002066 } else {
2067 request.result =
2068 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2069 }
2070 } else {
2071 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2072 }
2073 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2074 notifyRequester(request);
2075 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002076
2077 case CMD_SET_SIM_POWER: {
2078 request = (MainThreadRequest) msg.obj;
2079 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2080 request = (MainThreadRequest) msg.obj;
2081 int stateToSet =
2082 ((Pair<Integer, IIntegerConsumer>)
2083 request.argument).first;
2084 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2085 break;
2086 }
2087 case EVENT_SET_SIM_POWER_DONE: {
2088 ar = (AsyncResult) msg.obj;
2089 request = (MainThreadRequest) ar.userObj;
2090 IIntegerConsumer callback =
2091 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2092 if (ar.exception != null) {
2093 loge("setSimPower exception: " + ar.exception);
2094 int errorCode = TelephonyManager.CallForwardingInfoCallback
2095 .RESULT_ERROR_UNKNOWN;
2096 if (ar.exception instanceof CommandException) {
2097 CommandException.Error error =
2098 ((CommandException) (ar.exception)).getCommandError();
2099 if (error == CommandException.Error.SIM_ERR) {
2100 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2101 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2102 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2103 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2104 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2105 } else {
2106 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2107 }
2108 }
2109 try {
2110 callback.accept(errorCode);
2111 } catch (RemoteException e) {
2112 // Ignore if the remote process is no longer available to call back.
2113 Log.w(LOG_TAG, "setSimPower: callback not available.");
2114 }
2115 } else {
2116 try {
2117 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2118 } catch (RemoteException e) {
2119 // Ignore if the remote process is no longer available to call back.
2120 Log.w(LOG_TAG, "setSimPower: callback not available.");
2121 }
2122 }
2123 break;
2124 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002125 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2126 request = (MainThreadRequest) msg.obj;
2127
2128 final Phone phone = getPhoneFromRequest(request);
2129 if (phone == null || phone.getServiceStateTracker() == null) {
2130 request.result = new IllegalStateException("Phone or SST is null");
2131 notifyRequester(request);
2132 break;
2133 }
2134
2135 Pair<Integer, SignalStrengthUpdateRequest> pair =
2136 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2137 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2138 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002139 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002140 request.subId, pair.first /*callingUid*/,
2141 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002142 break;
2143 }
2144 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2145 ar = (AsyncResult) msg.obj;
2146 request = (MainThreadRequest) ar.userObj;
2147 // request.result will be the exception of ar if present, true otherwise.
2148 // Be cautious not to leave result null which will wait() forever
2149 request.result = ar.exception != null ? ar.exception : true;
2150 notifyRequester(request);
2151 break;
2152 }
2153 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2154 request = (MainThreadRequest) msg.obj;
2155
2156 Phone phone = getPhoneFromRequest(request);
2157 if (phone == null || phone.getServiceStateTracker() == null) {
2158 request.result = new IllegalStateException("Phone or SST is null");
2159 notifyRequester(request);
2160 break;
2161 }
2162
2163 Pair<Integer, SignalStrengthUpdateRequest> pair =
2164 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2165 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2166 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002167 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002168 request.subId, pair.first /*callingUid*/,
2169 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002170 break;
2171 }
2172 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2173 ar = (AsyncResult) msg.obj;
2174 request = (MainThreadRequest) ar.userObj;
2175 request.result = ar.exception != null ? ar.exception : true;
2176 notifyRequester(request);
2177 break;
2178 }
Jordan Liu109698e2020-11-24 14:50:34 -08002179
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002180 case CMD_GET_SLICING_CONFIG: {
2181 request = (MainThreadRequest) msg.obj;
2182 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2183 request.phone.getSlicingConfig(onCompleted);
2184 break;
2185 }
2186 case EVENT_GET_SLICING_CONFIG_DONE: {
2187 ar = (AsyncResult) msg.obj;
2188 request = (MainThreadRequest) ar.userObj;
2189 ResultReceiver result = (ResultReceiver) request.argument;
2190
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002191 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002192 Bundle bundle = new Bundle();
2193 int resultCode = 0;
2194 if (ar.exception != null) {
2195 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2196 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002197 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002198 } else if (ar.result == null) {
2199 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002200 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002201 } else {
2202 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002203 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2204 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 }
2206
2207 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 }
2210 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2211 result.send(resultCode, bundle);
2212 notifyRequester(request);
2213 break;
2214 }
2215
Sarah Chin71b3a852022-09-28 15:54:19 -07002216 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002217 request = (MainThreadRequest) msg.obj;
2218 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002219 PurchasePremiumCapabilityArgument arg =
2220 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002221 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2222 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002223 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002224 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002225
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227 ar = (AsyncResult) msg.obj;
2228 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 PurchasePremiumCapabilityArgument arg =
2230 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 try {
2232 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002236 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237 + TelephonyManager.convertPurchaseResultToString(result));
2238 } catch (RemoteException e) {
2239 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 + " failed: " + e;
2242 if (DBG) log(logStr);
2243 AnomalyReporter.reportAnomaly(
2244 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2245 }
2246 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002247 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248
Michele Berionne5e411512020-11-13 02:36:59 +00002249 case CMD_PREPARE_UNATTENDED_REBOOT:
2250 request = (MainThreadRequest) msg.obj;
2251 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002252 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002253 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002254 notifyRequester(request);
2255 break;
2256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 default:
2258 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2259 break;
2260 }
2261 }
Jake Hambye994d462014-02-03 13:10:13 -08002262
Pengquan Menga1bb6272018-09-06 09:59:22 -07002263 private void notifyRequester(MainThreadRequest request) {
2264 synchronized (request) {
2265 request.notifyAll();
2266 }
2267 }
2268
Jake Hambye994d462014-02-03 13:10:13 -08002269 private void handleNullReturnEvent(Message msg, String command) {
2270 AsyncResult ar = (AsyncResult) msg.obj;
2271 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2272 if (ar.exception == null) {
2273 request.result = true;
2274 } else {
2275 request.result = false;
2276 if (ar.exception instanceof CommandException) {
2277 loge(command + ": CommandException: " + ar.exception);
2278 } else {
2279 loge(command + ": Unknown exception");
2280 }
2281 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002282 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
2286 /**
2287 * Posts the specified command to be executed on the main thread,
2288 * waits for the request to complete, and returns the result.
2289 * @see #sendRequestAsync
2290 */
2291 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002292 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2293 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002294 }
2295
2296 /**
2297 * Posts the specified command to be executed on the main thread,
2298 * waits for the request to complete, and returns the result.
2299 * @see #sendRequestAsync
2300 */
2301 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2302 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002303 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
2306 /**
2307 * Posts the specified command to be executed on the main thread,
2308 * waits for the request to complete, and returns the result.
2309 * @see #sendRequestAsync
2310 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002311 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2318 * if not timeout or null otherwise.
2319 * @see #sendRequestAsync
2320 */
2321 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2322 long timeoutInMs) {
2323 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002324 }
2325
2326 /**
2327 * Posts the specified command to be executed on the main thread,
2328 * waits for the request to complete, and returns the result.
2329 * @see #sendRequestAsync
2330 */
Nathan Harold92bed182018-10-12 18:16:49 -07002331 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002332 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete, and returns the result.
2338 * @see #sendRequestAsync
2339 */
2340 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2342 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002343 }
2344
2345 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002346 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2347 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2348 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002349 * @see #sendRequestAsync
2350 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002351 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2352 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2354 throw new RuntimeException("This method will deadlock if called from the main thread.");
2355 }
2356
Nathan Harold92bed182018-10-12 18:16:49 -07002357 MainThreadRequest request = null;
2358 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2359 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2360 } else if (phone != null) {
2361 request = new MainThreadRequest(argument, phone, workSource);
2362 } else {
2363 request = new MainThreadRequest(argument, subId, workSource);
2364 }
2365
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 Message msg = mMainThreadHandler.obtainMessage(command, request);
2367 msg.sendToTarget();
2368
Rambo Wang0f050d82021-02-12 11:43:36 -08002369
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 if (timeoutInMs >= 0) {
2372 // Wait for at least timeoutInMs before returning null request result
2373 long now = SystemClock.elapsedRealtime();
2374 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002375 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 try {
2377 request.wait(deadline - now);
2378 } catch (InterruptedException e) {
2379 // Do nothing, go back and check if request is completed or timeout
2380 } finally {
2381 now = SystemClock.elapsedRealtime();
2382 }
2383 }
2384 } else {
2385 // Wait for the request to complete
2386 while (request.result == null) {
2387 try {
2388 request.wait();
2389 } catch (InterruptedException e) {
2390 // Do nothing, go back and wait until the request is complete
2391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 }
2393 }
2394 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 if (request.result == null) {
2396 Log.wtf(LOG_TAG,
2397 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 return request.result;
2400 }
2401
2402 /**
2403 * Asynchronous ("fire and forget") version of sendRequest():
2404 * Posts the specified command to be executed on the main thread, and
2405 * returns immediately.
2406 * @see #sendRequest
2407 */
2408 private void sendRequestAsync(int command) {
2409 mMainThreadHandler.sendEmptyMessage(command);
2410 }
2411
2412 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002413 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002414 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002415 */
2416 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002417 sendRequestAsync(command, argument, null, null);
2418 }
2419
2420 /**
2421 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2422 * @see {@link #sendRequest(int,Object)}
2423 */
2424 private void sendRequestAsync(
2425 int command, Object argument, Phone phone, WorkSource workSource) {
2426 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002427 Message msg = mMainThreadHandler.obtainMessage(command, request);
2428 msg.sendToTarget();
2429 }
2430
2431 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 * Initialize the singleton PhoneInterfaceManager instance.
2433 * This is only done once, at startup, from PhoneApp.onCreate().
2434 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002435 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 synchronized (PhoneInterfaceManager.class) {
2437 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002438 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 } else {
2440 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2441 }
2442 return sInstance;
2443 }
2444 }
2445
2446 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002447 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002449 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002451 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002452 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002453 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2455 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002456 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002457 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002458 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002459 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002460 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002461 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 publish();
arunvoddud7401012022-12-15 16:08:12 +00002463 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002466 @VisibleForTesting
2467 public SharedPreferences getSharedPreferences() {
2468 return mTelephonySharedPreferences;
2469 }
2470
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002471 /**
2472 * Get the default phone for this device.
2473 */
2474 @VisibleForTesting
2475 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002476 Phone thePhone = getPhone(getDefaultSubscription());
2477 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2478 }
2479
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 private void publish() {
2481 if (DBG) log("publish: " + this);
2482
Peter Wangc035ce42020-01-08 21:00:22 -08002483 TelephonyFrameworkInitializer
2484 .getTelephonyServiceManager()
2485 .getTelephonyServiceRegisterer()
2486 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
Stuart Scott584921c2015-01-15 17:10:34 -08002489 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002490 if (request.phone != null) {
2491 return request.phone;
2492 } else {
2493 return getPhoneFromSubId(request.subId);
2494 }
2495 }
2496
2497 private Phone getPhoneFromSubId(int subId) {
2498 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2499 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002500 }
2501
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002502 /**
2503 * Get phone object associated with a subscription.
2504 * Return default phone if phone object associated with subscription is null
2505 * @param subId - subscriptionId
2506 * @return phone object associated with a subscription or default phone if null.
2507 */
Ling Mac28f0212023-03-24 16:07:15 -07002508 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002509 Phone phone = getPhoneFromSubId(subId);
2510 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002511 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002512 phone = getDefaultPhone();
2513 }
2514 return phone;
2515 }
2516
Rambo Wange53e07d2022-05-10 13:01:13 -07002517 @Nullable
2518 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 Phone phone = getPhoneFromRequest(request);
2520 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002521 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 }
2523
Ling Mac28f0212023-03-24 16:07:15 -07002524 /**
2525 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2526 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2527 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2528 * @return The Phone associated the sub Id
2529 */
2530 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002531 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533
Kai Shif70f46f2021-03-03 13:59:46 -08002534 private void sendEraseModemConfig(@NonNull Phone phone) {
2535 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2536 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2537 }
2538
2539 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2540 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2541 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002542 }
2543
Peter Wang44b186e2020-01-13 23:33:09 -08002544 private boolean isImsAvailableOnDevice() {
2545 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2546 if (pm == null) {
2547 // For some reason package manger is not available.. This will fail internally anyway,
2548 // so do not throw error and allow.
2549 return true;
2550 }
2551 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2552 }
2553
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002555 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002556 }
2557
Wink Savilleb564aae2014-10-23 10:18:09 -07002558 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 if (DBG) log("dial: " + number);
2560 // No permission check needed here: This is just a wrapper around the
2561 // ACTION_DIAL intent, which is available to any app since it puts up
2562 // the UI before it does anything.
2563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 String url = createTelUrl(number);
2567 if (url == null) {
2568 return;
2569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571 // PENDING: should we just silently fail if phone is offhook or ringing?
2572 PhoneConstants.State state = mCM.getState(subId);
2573 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2574 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2575 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2576 mApp.startActivity(intent);
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 }
2581 }
2582
2583 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002584 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002585 }
2586
Wink Savilleb564aae2014-10-23 10:18:09 -07002587 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 if (DBG) log("call: " + number);
2589
2590 // This is just a wrapper around the ACTION_CALL intent, but we still
2591 // need to do a permission check since we're calling startActivity()
2592 // from the context of the phone app.
2593 enforceCallPermission();
2594
Jordan Liu1617b712019-07-10 15:06:26 -07002595 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 != AppOpsManager.MODE_ALLOWED) {
2597 return;
2598 }
2599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 String url = createTelUrl(number);
2603 if (url == null) {
2604 return;
2605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 boolean isValid = false;
2608 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2609 if (slist != null) {
2610 for (SubscriptionInfo subInfoRecord : slist) {
2611 if (subInfoRecord.getSubscriptionId() == subId) {
2612 isValid = true;
2613 break;
2614 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002615 }
Wink Saville08874612014-08-31 19:19:58 -07002616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 if (!isValid) {
2618 return;
2619 }
Wink Saville08874612014-08-31 19:19:58 -07002620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2622 intent.putExtra(SUBSCRIPTION_KEY, subId);
2623 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2624 mApp.startActivity(intent);
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629
Wink Savilleb564aae2014-10-23 10:18:09 -07002630 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002631 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002632 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2633 }
2634
Wink Savilleb564aae2014-10-23 10:18:09 -07002635 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002636 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002637 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2638 }
2639
Wink Savilleb564aae2014-10-23 10:18:09 -07002640 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002645 Phone phone = getPhone(subId);
2646 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 checkSimPin.start();
2648 return checkSimPin.unlockSim(null, pin);
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
2651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
Wink Savilleb564aae2014-10-23 10:18:09 -07002654 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002659 Phone phone = getPhone(subId);
2660 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 checkSimPuk.start();
2662 return checkSimPuk.unlockSim(puk, pin);
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
2668 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002669 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 * a synchronous one.
2671 */
2672 private static class UnlockSim extends Thread {
2673
2674 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002675 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676
2677 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002678 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2679 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680
2681 // For replies from SimCard interface
2682 private Handler mHandler;
2683
2684 // For async handler to identify request type
2685 private static final int SUPPLY_PIN_COMPLETE = 100;
2686
Michele Berionne5e411512020-11-13 02:36:59 +00002687 UnlockSim(int phoneId, IccCard simCard) {
2688 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 mSimCard = simCard;
2690 }
2691
2692 @Override
2693 public void run() {
2694 Looper.prepare();
2695 synchronized (UnlockSim.this) {
2696 mHandler = new Handler() {
2697 @Override
2698 public void handleMessage(Message msg) {
2699 AsyncResult ar = (AsyncResult) msg.obj;
2700 switch (msg.what) {
2701 case SUPPLY_PIN_COMPLETE:
2702 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2703 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002704 mRetryCount = msg.arg1;
2705 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002706 CommandException.Error error = null;
2707 if (ar.exception instanceof CommandException) {
2708 error = ((CommandException) (ar.exception))
2709 .getCommandError();
2710 }
2711 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002712 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002713 } else if (error == CommandException.Error.ABORTED) {
2714 /* When UiccCardApp dispose, handle message and return
2715 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002716 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002717 } else {
2718 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2719 }
2720 } else {
2721 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 mDone = true;
2724 UnlockSim.this.notifyAll();
2725 }
2726 break;
2727 }
2728 }
2729 };
2730 UnlockSim.this.notifyAll();
2731 }
2732 Looper.loop();
2733 }
2734
2735 /*
2736 * Use PIN or PUK to unlock SIM card
2737 *
2738 * If PUK is null, unlock SIM card with PIN
2739 *
2740 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302741 *
2742 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2743 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 */
Wink Saville9de0f752013-10-22 19:04:03 -07002745 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746
2747 while (mHandler == null) {
2748 try {
2749 wait();
2750 } catch (InterruptedException e) {
2751 Thread.currentThread().interrupt();
2752 }
2753 }
2754 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2755
2756 if (puk == null) {
2757 mSimCard.supplyPin(pin, callback);
2758 } else {
2759 mSimCard.supplyPuk(puk, pin, callback);
2760 }
2761
2762 while (!mDone) {
2763 try {
2764 Log.d(LOG_TAG, "wait for done");
2765 wait();
2766 } catch (InterruptedException e) {
2767 // Restore the interrupted status
2768 Thread.currentThread().interrupt();
2769 }
2770 }
2771 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002772 int[] resultArray = new int[2];
2773 resultArray[0] = mResult;
2774 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002775
2776 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002777 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002778 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302779 // This instance is no longer reused, so quit its thread's looper.
2780 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002781
Wink Saville9de0f752013-10-22 19:04:03 -07002782 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784 }
2785
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002786 /**
2787 * This method has been removed due to privacy and stability concerns.
2788 */
2789 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002791 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2792 return;
Wink Saville36469e72014-06-11 15:17:00 -07002793 }
2794
Nathan Harold1f889d82020-06-04 17:05:26 -07002795 @Override
2796 public void updateServiceLocationWithPackageName(String callingPackage) {
2797 mApp.getSystemService(AppOpsManager.class)
2798 .checkPackage(Binder.getCallingUid(), callingPackage);
2799
Nathan Haroldf096d982020-11-18 17:18:06 -08002800 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002801 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2802 // Callers targeting S have no business invoking this method.
2803 return;
2804 }
2805
2806 LocationAccessPolicy.LocationPermissionResult locationResult =
2807 LocationAccessPolicy.checkLocationPermission(mApp,
2808 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2809 .setCallingPackage(callingPackage)
2810 .setCallingFeatureId(null)
2811 .setCallingPid(Binder.getCallingPid())
2812 .setCallingUid(Binder.getCallingUid())
2813 .setMethod("updateServiceLocation")
2814 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2815 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2816 .build());
2817 // Apps that lack location permission have no business calling this method;
2818 // however, because no permission was declared in the public API, denials must
2819 // all be "soft".
2820 switch (locationResult) {
2821 case DENIED_HARD: /* fall through */
2822 case DENIED_SOFT:
2823 return;
2824 }
2825
2826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
Ling Mac28f0212023-03-24 16:07:15 -07002829 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 }
2834
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002835 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002836 @Override
2837 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002838 return isRadioOnWithFeature(callingPackage, null);
2839 }
2840
2841
2842 @Override
2843 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2844 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2845 callingFeatureId);
2846 }
2847
2848 @Deprecated
2849 @Override
2850 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2851 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002852 }
2853
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002854 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002855 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2856 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002858 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002859 return false;
2860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 return isRadioOnForSubscriber(subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002868 }
2869
2870 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 final Phone phone = getPhone(subId);
2874 if (phone != null) {
2875 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2876 } else {
2877 return false;
2878 }
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
2884 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002885 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
Wink Saville36469e72014-06-11 15:17:00 -07002887
Wink Savilleb564aae2014-10-23 10:18:09 -07002888 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
2895 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2896 }
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 }
Wink Saville36469e72014-06-11 15:17:00 -07002900 }
2901
2902 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002903 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002904 }
2905
Wink Savilleb564aae2014-10-23 10:18:09 -07002906 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone == null) {
2913 return false;
2914 }
2915 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2916 toggleRadioOnOffForSubscriber(subId);
2917 }
2918 return true;
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
Wink Saville36469e72014-06-11 15:17:00 -07002923
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002924 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002925 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002926 /*
2927 * If any of the Radios are available, it will need to be
2928 * shutdown. So return true if any Radio is available.
2929 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2933 Phone phone = PhoneFactory.getPhone(i);
2934 if (phone != null && phone.isRadioAvailable()) return true;
2935 }
2936 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2937 return false;
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002940 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002941 }
2942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002944 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 enforceModifyPermission();
2946
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2950 logv("Shutting down Phone " + i);
2951 shutdownRadioUsingPhoneId(i);
2952 }
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002955 }
2956 }
2957
2958 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002959 Phone phone = PhoneFactory.getPhone(phoneId);
2960 if (phone != null && phone.isRadioAvailable()) {
2961 phone.shutdownRadio();
2962 }
2963 }
2964
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967
Ling Ma83dc5ea2023-01-12 15:06:04 -08002968 if (!turnOn) {
2969 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2970 }
2971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2975 if (defaultPhone != null) {
2976 defaultPhone.setRadioPower(turnOn);
2977 return true;
2978 } else {
2979 loge("There's no default phone.");
2980 return false;
2981 }
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002984 }
Wink Saville36469e72014-06-11 15:17:00 -07002985 }
2986
Wink Savilleb564aae2014-10-23 10:18:09 -07002987 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989
Ling Ma83dc5ea2023-01-12 15:06:04 -08002990 if (!turnOn) {
2991 log("setRadioPowerForSubscriber off: subId=" + subId
2992 + ",callingPackage=" + getCurrentPackageName());
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 final Phone phone = getPhone(subId);
2997 if (phone != null) {
2998 phone.setRadioPower(turnOn);
2999 return true;
3000 } else {
3001 return false;
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 }
3007
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003008 /**
3009 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3010 * no reason to power it off. When any of the voters want to power it off, it will be turned
3011 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3012 * powering it off, and these radio off votes will be cleared.
3013 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3014 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3015 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3016 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3017 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3018 * check its vote.
3019 *
3020 * @param subId The subscription ID.
3021 * @param reason The reason for powering off radio.
3022 * @return true on success and false on failure.
3023 */
3024 public boolean requestRadioPowerOffForReason(int subId,
3025 @TelephonyManager.RadioPowerReason int reason) {
3026 enforceModifyPermission();
3027
Ling Ma83dc5ea2023-01-12 15:06:04 -08003028 log("requestRadioPowerOffForReason: subId=" + subId
3029 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003030 final long identity = Binder.clearCallingIdentity();
3031 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003032 boolean result = false;
3033 for (Phone phone : PhoneFactory.getPhones()) {
3034 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003035 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003036 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003037 if (!result) {
3038 loge("requestRadioPowerOffForReason: no phone exists");
3039 }
3040 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 /**
3047 * Remove the vote on powering off the radio for a reason, as requested by
3048 * {@link requestRadioPowerOffForReason}.
3049 *
3050 * @param subId The subscription ID.
3051 * @param reason The reason for powering off radio.
3052 * @return true on success and false on failure.
3053 */
3054 public boolean clearRadioPowerOffForReason(int subId,
3055 @TelephonyManager.RadioPowerReason int reason) {
3056 enforceModifyPermission();
3057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003060 boolean result = false;
3061 for (Phone phone : PhoneFactory.getPhones()) {
3062 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003063 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003064 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003065 if (!result) {
3066 loge("clearRadioPowerOffForReason: no phone exists");
3067 }
3068 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 /**
3075 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3076 *
3077 * @param subId The subscription ID.
3078 * @param callingPackage The package making the call.
3079 * @param callingFeatureId The feature in the package.
3080 * @return List of reasons for powering off radio.
3081 */
3082 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3083 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3084
3085 final long identity = Binder.clearCallingIdentity();
3086 List result = new ArrayList();
3087 try {
3088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3089 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3090 return result;
3091 }
3092
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003093 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 if (phone != null) {
3095 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003096 } else {
3097 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003098 }
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
3102 return result;
3103 }
3104
Wink Saville36469e72014-06-11 15:17:00 -07003105 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003106 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003107 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
Jack Yu285100e2022-12-02 22:48:35 -08003112 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final Phone phone = getPhone(subId);
3114 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003115 phone.getDataSettingsManager().setDataEnabled(
3116 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 return true;
3118 } else {
3119 return false;
3120 }
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 }
3125
Wink Saville36469e72014-06-11 15:17:00 -07003126 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003127 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003128 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
Jack Yu285100e2022-12-02 22:48:35 -08003133 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final Phone phone = getPhone(subId);
3135 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003136 phone.getDataSettingsManager().setDataEnabled(
3137 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 return true;
3139 } else {
3140 return false;
3141 }
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 }
3146
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003148 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 final Phone phone = getPhone(subId);
3152 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003153 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154 } else {
3155 return false;
3156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
3162 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003163 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003164 }
3165
pkanwarae03a6b2016-11-06 20:37:09 -08003166 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 enforceCallPermission();
3168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3172 return;
3173 }
3174 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3175 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
pkanwar32d516d2016-10-14 19:37:38 -07003179 };
3180
Wink Savilleb564aae2014-10-23 10:18:09 -07003181 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3187 return false;
3188 }
3189 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 }
3194
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003195 /**
3196 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3197 * tag on getCallState Binder call.
3198 */
3199 @Deprecated
3200 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003202 if (CompatChanges.isChangeEnabled(
3203 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3204 Binder.getCallingUid())) {
3205 // Do not allow this API to be called on API version 31+, it should only be
3206 // called on old apps using this Binder call directly.
3207 throw new SecurityException("This method can only be used for applications "
3208 + "targeting API version 30 or less.");
3209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
Ling Mac28f0212023-03-24 16:07:15 -07003212 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3213 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
3220 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3221 if (CompatChanges.isChangeEnabled(
3222 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3223 Binder.getCallingUid())) {
3224 // Check READ_PHONE_STATE for API version 31+
3225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3226 featureId, "getCallStateForSubscription")) {
3227 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3228 + "targeting API level 31+.");
3229 }
3230 }
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3235 PhoneConstantConversions.convertCallState(phone.getState());
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 }
3240
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003242 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003243 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003244 }
3245
3246 @Override
3247 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003252 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 } else {
3254 return PhoneConstantConversions.convertDataState(
3255 PhoneConstants.DataState.DISCONNECTED);
3256 }
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 }
3261
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003263 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003264 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003265 }
3266
3267 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003268 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003271 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003273 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 } else {
3275 return TelephonyManager.DATA_ACTIVITY_NONE;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003283 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003284 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003285 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003286
3287 LocationAccessPolicy.LocationPermissionResult locationResult =
3288 LocationAccessPolicy.checkLocationPermission(mApp,
3289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3290 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003291 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003292 .setCallingPid(Binder.getCallingPid())
3293 .setCallingUid(Binder.getCallingUid())
3294 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003295 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003296 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3297 .build());
3298 switch (locationResult) {
3299 case DENIED_HARD:
3300 throw new SecurityException("Not allowed to access cell location");
3301 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003302 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3303 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 }
3305
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003310 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003311 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
Svetoslav64fad262015-04-14 14:35:21 -07003315 }
3316
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003318 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003319 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3320 // registered cell info, so return a NULL country instead.
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003323 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3324 // Get default phone in this case.
3325 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3326 }
Jack Yu285100e2022-12-02 22:48:35 -08003327 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003329 if (phone == null) return "";
3330 ServiceStateTracker sst = phone.getServiceStateTracker();
3331 if (sst == null) return "";
3332 LocaleTracker lt = sst.getLocaleTracker();
3333 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003334 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003338 }
3339
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003340 /**
3341 * This method was removed due to potential issues caused by performing partial
3342 * updates of service state, and lack of a credible use case.
3343 *
3344 * This has the ability to break the telephony implementation by disabling notification of
3345 * changes in device connectivity. DO NOT USE THIS!
3346 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 public void enableLocationUpdates() {
3349 mApp.enforceCallingOrSelfPermission(
3350 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 }
3352
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003353 /**
3354 * This method was removed due to potential issues caused by performing partial
3355 * updates of service state, and lack of a credible use case.
3356 *
3357 * This has the ability to break the telephony implementation by disabling notification of
3358 * changes in device connectivity. DO NOT USE THIS!
3359 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360 @Override
3361 public void disableLocationUpdates() {
3362 mApp.enforceCallingOrSelfPermission(
3363 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 }
3365
3366 @Override
3367 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003368 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3369 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003370 try {
3371 mApp.getSystemService(AppOpsManager.class)
3372 .checkPackage(Binder.getCallingUid(), callingPackage);
3373 } catch (SecurityException e) {
3374 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3375 throw e;
3376 }
3377
Nathan Haroldf096d982020-11-18 17:18:06 -08003378 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003379 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3380 throw new SecurityException(
3381 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3382 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003383
Jordan Liu1617b712019-07-10 15:06:26 -07003384 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3386 return null;
3387 }
Svetoslav64fad262015-04-14 14:35:21 -07003388
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003389 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003391 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003392 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393
Nathan Haroldf180aac2018-06-01 18:43:55 -07003394 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3395 for (CellInfo ci : info) {
3396 if (ci instanceof CellInfoGsm) {
3397 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3398 } else if (ci instanceof CellInfoWcdma) {
3399 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003402 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
3404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 private List<CellInfo> getCachedCellInfo() {
3406 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3407 for (Phone phone : PhoneFactory.getPhones()) {
3408 List<CellInfo> info = phone.getAllCellInfo();
3409 if (info != null) cellInfos.addAll(info);
3410 }
3411 return cellInfos;
3412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413
3414 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003415 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003416 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003417 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003418
3419 LocationAccessPolicy.LocationPermissionResult locationResult =
3420 LocationAccessPolicy.checkLocationPermission(mApp,
3421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3422 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003423 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003424 .setCallingPid(Binder.getCallingPid())
3425 .setCallingUid(Binder.getCallingUid())
3426 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003428 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3429 .build());
3430 switch (locationResult) {
3431 case DENIED_HARD:
3432 throw new SecurityException("Not allowed to access cell info");
3433 case DENIED_SOFT:
3434 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 }
3436
Nathan Haroldf096d982020-11-18 17:18:06 -08003437 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003438 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3439 return getCachedCellInfo();
3440 }
3441
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003442 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3447 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003448 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003449 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 if (info != null) cellInfos.addAll(info);
3451 }
3452 return cellInfos;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456 }
3457
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003459 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3460 String callingFeatureId) {
3461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3462 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003463 }
3464
3465 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003466 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3467 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003468 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003470 }
3471
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003472 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003475 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003476
3477 LocationAccessPolicy.LocationPermissionResult locationResult =
3478 LocationAccessPolicy.checkLocationPermission(mApp,
3479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3480 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003481 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003482 .setCallingPid(Binder.getCallingPid())
3483 .setCallingUid(Binder.getCallingUid())
3484 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003485 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3486 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003487 .build());
3488 switch (locationResult) {
3489 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003490 if (TelephonyPermissions
3491 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003492 // Safetynet logging for b/154934934
3493 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3494 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003495 throw new SecurityException("Not allowed to access cell info");
3496 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003497 if (TelephonyPermissions
3498 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003499 // Safetynet logging for b/154934934
3500 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3501 }
Nathan Harold5320c422019-05-09 10:26:08 -07003502 try {
3503 cb.onCellInfo(new ArrayList<CellInfo>());
3504 } catch (RemoteException re) {
3505 // Drop without consequences
3506 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003507 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003508 }
3509
Nathan Harolda939a962019-05-09 10:13:47 -07003510
3511 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003512 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3513
3514 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3515 }
3516
3517 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003518 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003519 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003524 Phone phone = getPhone(subId);
3525 if (phone == null) {
3526 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3527 } else {
3528 phone.setCellInfoListRate(rateInMillis, workSource);
3529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
Shishir Agrawala9f32182016-04-12 12:00:16 -07003535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 return null;
3540 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003542 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003543 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 return null;
3546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 return phone.getImei();
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003554 }
3555
3556 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003557 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3558 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3559 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3560 callingFeatureId, "getPrimaryImei")) {
3561 throw new SecurityException("Caller does not have permission");
3562 }
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 for (Phone phone : PhoneFactory.getPhones()) {
3566 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3567 return phone.getImei();
3568 }
3569 }
3570 throw new UnsupportedOperationException("Operation not supported");
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 }
3575
3576 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003577 public String getTypeAllocationCodeForSlot(int slotIndex) {
3578 Phone phone = PhoneFactory.getPhone(slotIndex);
3579 String tac = null;
3580 if (phone != null) {
3581 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003582 try {
3583 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3584 } catch (IndexOutOfBoundsException e) {
3585 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3586 return null;
3587 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003588 }
3589 return tac;
3590 }
3591
3592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003593 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003594 try {
3595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3596 } catch (SecurityException se) {
3597 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3598 throw new SecurityException("Package " + callingPackage + " does not belong to "
3599 + Binder.getCallingUid());
3600 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003601 Phone phone = PhoneFactory.getPhone(slotIndex);
3602 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003603 return null;
3604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605
Jeff Davidson913390f2018-02-23 17:11:49 -08003606 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003607 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003608 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003609 return null;
3610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611
3612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 return phone.getMeid();
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
Jack Yu2af8d712017-03-15 17:14:14 -07003618 }
3619
3620 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003621 public String getManufacturerCodeForSlot(int slotIndex) {
3622 Phone phone = PhoneFactory.getPhone(slotIndex);
3623 String manufacturerCode = null;
3624 if (phone != null) {
3625 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003626 try {
3627 manufacturerCode =
3628 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3629 } catch (IndexOutOfBoundsException e) {
3630 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3631 return null;
3632 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003633 }
3634 return manufacturerCode;
3635 }
3636
3637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3639 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 Phone phone = PhoneFactory.getPhone(slotIndex);
3641 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 return null;
3643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 int subId = phone.getSubId();
3645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003646 mApp, subId, callingPackage, callingFeatureId,
3647 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 return null;
3649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 return phone.getDeviceSvn();
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003657 }
3658
fionaxu43304da2017-11-27 22:51:16 -08003659 @Override
3660 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
3664 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
fionaxu43304da2017-11-27 22:51:16 -08003668 }
3669
3670 @Override
3671 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 final Phone phone = getPhone(subId);
3675 return phone == null ? null : phone.getCarrierName();
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
fionaxu43304da2017-11-27 22:51:16 -08003679 }
3680
calvinpanffe225e2018-11-01 19:43:06 +08003681 @Override
chen xu0026ca62019-03-06 15:28:50 -08003682 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003687 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
chen xu0026ca62019-03-06 15:28:50 -08003694 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003698 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 }
3703
chen xu651eec72018-11-11 19:03:44 -08003704 @Override
chen xu864e11c2018-12-06 22:10:03 -08003705 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3706 if (!isSubscriptionMccMnc) {
3707 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3708 }
chen xu651eec72018-11-11 19:03:44 -08003709 final Phone phone = PhoneFactory.getPhone(slotIndex);
3710 if (phone == null) {
3711 return TelephonyManager.UNKNOWN_CARRIER_ID;
3712 }
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
3719 }
3720
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 //
3722 // Internal helper methods.
3723 //
3724
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003725 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003726 * Make sure the caller is the calling package itself
3727 *
3728 * @throws SecurityException if the caller is not the calling package
3729 */
3730 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3731 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003732 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3733 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003734 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003735 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003736 } catch (PackageManager.NameNotFoundException e) {
3737 // packageUid is -1
3738 }
3739 if (packageUid != callingUid) {
3740 throw new SecurityException(message + ": Package " + callingPackage
3741 + " does not belong to " + callingUid);
3742 }
3743 }
3744
3745 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003746 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3747 *
3748 * @throws SecurityException if the caller does not have the required permission
3749 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003750 @VisibleForTesting
3751 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3753 }
3754
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003755 /**
arunvoddud7401012022-12-15 16:08:12 +00003756 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003757 *
3758 * @throws SecurityException if the caller does not have the required permission
3759 */
3760 @VisibleForTesting
3761 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003762 enforceReadPermission(null);
3763 }
3764
3765 /**
3766 * Make sure the caller has the READ_PHONE_STATE permissions.
3767 *
3768 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3769 */
3770 @VisibleForTesting
3771 public void enforceReadPermission(String msg) {
3772 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003773 }
3774
Shuo Qian3b6ee772019-11-13 17:43:31 -08003775 private void enforceActiveEmergencySessionPermission() {
3776 mApp.enforceCallingOrSelfPermission(
3777 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3778 }
3779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003780 /**
3781 * Make sure the caller has the CALL_PHONE permission.
3782 *
3783 * @throws SecurityException if the caller does not have the required permission
3784 */
3785 private void enforceCallPermission() {
3786 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3787 }
3788
paulhu5a773602019-08-23 19:17:33 +08003789 private void enforceSettingsPermission() {
3790 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003791 }
3792
Michele Berionne5e411512020-11-13 02:36:59 +00003793 private void enforceRebootPermission() {
3794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3795 }
3796
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003797 /**
3798 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3799 * @param message - log message to print.
3800 * @throws SecurityException if the caller does not have the required permission
3801 */
3802 private void enforceSatelliteCommunicationPermission(String message) {
3803 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3804 }
3805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003806 private String createTelUrl(String number) {
3807 if (TextUtils.isEmpty(number)) {
3808 return null;
3809 }
3810
Jake Hambye994d462014-02-03 13:10:13 -08003811 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 }
3813
Ihab Awadf9e92732013-12-05 18:02:52 -08003814 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003815 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003818 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003819 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003820 }
3821
Ihab Awadf9e92732013-12-05 18:02:52 -08003822 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003823 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003824 }
3825
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003827 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003828 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003829 }
3830
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003832 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 final Phone phone = PhoneFactory.getPhone(slotIndex);
3836 if (phone == null) {
3837 return PhoneConstants.PHONE_TYPE_NONE;
3838 } else {
3839 return phone.getPhoneType();
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003844 }
3845
3846 /**
3847 * Returns the CDMA ERI icon index to display
3848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3851 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003853 }
3854
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 mApp, subId, callingPackage, callingFeatureId,
3860 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003861 return -1;
3862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863
3864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 final Phone phone = getPhone(subId);
3867 if (phone != null) {
3868 return phone.getCdmaEriIconIndex();
3869 } else {
3870 return -1;
3871 }
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876
3877 /**
3878 * Returns the CDMA ERI icon mode,
3879 * 0 - ON
3880 * 1 - FLASHING
3881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003883 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3884 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3885 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003886 }
3887
Sanket Padawe356d7632015-06-22 14:03:32 -07003888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003889 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003892 mApp, subId, callingPackage, callingFeatureId,
3893 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003894 return -1;
3895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 final Phone phone = getPhone(subId);
3900 if (phone != null) {
3901 return phone.getCdmaEriIconMode();
3902 } else {
3903 return -1;
3904 }
3905 } finally {
3906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003908 }
3909
3910 /**
3911 * Returns the CDMA ERI text,
3912 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003913 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003914 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3915 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3916 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003917 }
3918
Sanket Padawe356d7632015-06-22 14:03:32 -07003919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003920 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003923 mApp, subId, callingPackage, callingFeatureId,
3924 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003925 return null;
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = getPhone(subId);
3931 if (phone != null) {
3932 return phone.getCdmaEriText();
3933 } else {
3934 return null;
3935 }
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 }
3940
3941 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003942 * Returns the CDMA MDN.
3943 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003945 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3947 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 return phone.getLine1Number();
3954 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 return null;
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003960 }
3961 }
3962
3963 /**
3964 * Returns the CDMA MIN.
3965 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003967 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3969 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 final Phone phone = getPhone(subId);
3974 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3975 return phone.getCdmaMin();
3976 } else {
3977 return null;
3978 }
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003981 }
3982 }
3983
Hall Liud892bec2018-11-30 14:51:45 -08003984 @Override
3985 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3986 INumberVerificationCallback callback, String callingPackage) {
3987 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3988 != PERMISSION_GRANTED) {
3989 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3990 }
3991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3992
3993 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3994 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003995 throw new SecurityException("Calling package must be configured in the device config: "
3996 + "calling package: " + callingPackage
3997 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003998 }
3999
4000 if (range == null) {
4001 throw new NullPointerException("Range must be non-null");
4002 }
4003
4004 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004005 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004006
4007 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4008 }
4009
Junda Liuca05d5d2014-08-14 22:36:34 -07004010 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004011 * Returns true if CDMA provisioning needs to run.
4012 */
4013 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004016 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
4022 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004023 * Sets the voice mail number of a given subId.
4024 */
4025 @Override
4026 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4028 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029
4030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4033 new Pair<String, String>(alphaTag, number), new Integer(subId));
4034 return success;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004038 }
4039
Ta-wei Yen87c49842016-05-13 21:19:52 -07004040 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004041 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004043 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4044 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004045 if (!TextUtils.equals(callingPackage, systemDialer)) {
4046 throw new SecurityException("caller must be system dialer");
4047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4052 if (phoneAccountHandle == null) {
4053 return null;
4054 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004058 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004059 }
4060
4061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004062 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4063 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 mApp, subId, callingPackage, callingFeatureId,
4067 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004068 return null;
4069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004071 final long identity = Binder.clearCallingIdentity();
4072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004077 }
4078
4079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004080 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4081 VisualVoicemailSmsFilterSettings settings) {
4082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004091 }
4092
4093 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004094 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4095 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004104 }
4105
4106 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004107 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4108 String callingPackage, int subId) {
4109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004118 }
4119
4120 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004121 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004127 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004131 }
4132
4133 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004134 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4135 String callingAttributionTag, int subId, String number, int port, String text,
4136 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004138 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004139 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004140 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004141 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4142 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004143 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004144
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004145 /**
fionaxu0152e512016-11-14 13:36:14 -08004146 * Sets the voice activation state of a given subId.
4147 */
4148 @Override
4149 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4151 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 final Phone phone = getPhone(subId);
4156 if (phone != null) {
4157 phone.setVoiceActivationState(activationState);
4158 } else {
4159 loge("setVoiceActivationState fails with invalid subId: " + subId);
4160 }
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004163 }
4164 }
4165
4166 /**
4167 * Sets the data activation state of a given subId.
4168 */
4169 @Override
4170 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4172 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 final Phone phone = getPhone(subId);
4177 if (phone != null) {
4178 phone.setDataActivationState(activationState);
4179 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004180 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 }
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004184 }
4185 }
4186
4187 /**
4188 * Returns the voice activation state of a given subId.
4189 */
4190 @Override
4191 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193
fionaxu0152e512016-11-14 13:36:14 -08004194 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 if (phone != null) {
4198 return phone.getVoiceActivationState();
4199 } else {
4200 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4201 }
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004204 }
4205 }
4206
4207 /**
4208 * Returns the data activation state of a given subId.
4209 */
4210 @Override
4211 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
fionaxu0152e512016-11-14 13:36:14 -08004214 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 if (phone != null) {
4218 return phone.getDataActivationState();
4219 } else {
4220 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4221 }
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004224 }
4225 }
4226
4227 /**
Wink Saville36469e72014-06-11 15:17:00 -07004228 * Returns the unread count of voicemails for a subId
4229 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004231 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4232 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 mApp, subId, callingPackage, callingFeatureId,
4235 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004236 return 0;
4237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 final Phone phone = getPhone(subId);
4241 if (phone != null) {
4242 return phone.getVoiceMessageCount();
4243 } else {
4244 return 0;
4245 }
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004249 }
4250
4251 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004252 * returns true, if the device is in a state where both voice and data
4253 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004254 */
4255 @Override
4256 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Ling Mac28f0212023-03-24 16:07:15 -07004259 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004263 }
4264
4265 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004266 * Send the dialer code if called from the current default dialer or the caller has
4267 * carrier privilege.
4268 * @param inputCode The dialer code to send
4269 */
4270 @Override
4271 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004274 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4275 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004276 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004277 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
fionaxu235cc5e2017-03-06 22:25:57 -08004287 }
4288
Pengquan Menga1bb6272018-09-06 09:59:22 -07004289 @Override
4290 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004291 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004292 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4293 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 if (!isActiveSubscription(subId)) {
4297 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4298 }
4299 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004303 }
4304
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004306 public boolean isInEmergencySmsMode() {
4307 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 for (Phone phone : PhoneFactory.getPhones()) {
4311 if (phone.isInEmergencySmsMode()) {
4312 return true;
4313 }
4314 }
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318 return false;
4319 }
4320
shilu366312e2019-12-17 09:28:10 -08004321 /**
4322 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4323 * @param subId The subscription to use to check the configuration.
4324 * @param c The callback that will be used to send the result.
4325 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004326 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004327 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4328 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004329 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004330 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004331
4332 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4334 "IMS not available on device.");
4335 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 final long token = Binder.clearCallingIdentity();
4337 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004338 int slotId = getSlotIndexOrException(subId);
4339 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004340
4341 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4342 if (controller != null) {
4343 ImsManager imsManager = controller.getImsManager(subId);
4344 if (imsManager != null) {
4345 imsManager.addRegistrationCallbackForSubscription(c, subId);
4346 } else {
4347 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4348 }
4349 } else {
4350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4351 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004352 } catch (ImsException e) {
4353 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 } finally {
4355 Binder.restoreCallingIdentity(token);
4356 }
4357 }
4358
shilu366312e2019-12-17 09:28:10 -08004359 /**
4360 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4361 * @param subId The subscription to use to check the configuration.
4362 * @param c The callback that will be used to send the result.
4363 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004365 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004366 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004367 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004368 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4369 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4370 }
Meng Wangafbc5852019-09-19 17:37:13 -07004371 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004372
Meng Wangafbc5852019-09-19 17:37:13 -07004373 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004374 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4375 if (controller != null) {
4376 ImsManager imsManager = controller.getImsManager(subId);
4377 if (imsManager != null) {
4378 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4379 } else {
4380 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4381 + "is inactive, ignoring unregister.");
4382 // If the ImsManager is not valid, just return, since the callback
4383 // will already have been removed internally.
4384 }
4385 }
Meng Wangafbc5852019-09-19 17:37:13 -07004386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 }
4390
Brad Ebingera34a6c22019-10-22 17:36:18 -07004391 /**
4392 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4393 */
4394 @Override
4395 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4396 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4397 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4398 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4399 "IMS not available on device.");
4400 }
4401 final long token = Binder.clearCallingIdentity();
4402 try {
4403 Phone phone = getPhone(subId);
4404 if (phone == null) {
4405 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4406 + subId + "'");
4407 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4408 }
4409 phone.getImsRegistrationState(regState -> {
4410 try {
4411 consumer.accept((regState == null)
4412 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4413 } catch (RemoteException e) {
4414 // Ignore if the remote process is no longer available to call back.
4415 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4416 }
4417 });
4418 } finally {
4419 Binder.restoreCallingIdentity(token);
4420 }
4421 }
4422
4423 /**
4424 * Get the transport type for the IMS service registration state.
4425 */
4426 @Override
4427 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004428 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004429 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004430 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4431 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4432 "IMS not available on device.");
4433 }
4434 final long token = Binder.clearCallingIdentity();
4435 try {
4436 Phone phone = getPhone(subId);
4437 if (phone == null) {
4438 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4439 + subId + "'");
4440 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4441 }
4442 phone.getImsRegistrationTech(regTech -> {
4443 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4444 int regTechConverted = (regTech == null)
4445 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4446 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4447 regTechConverted);
4448 try {
4449 consumer.accept(regTechConverted);
4450 } catch (RemoteException e) {
4451 // Ignore if the remote process is no longer available to call back.
4452 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4453 }
4454 });
4455 } finally {
4456 Binder.restoreCallingIdentity(token);
4457 }
4458 }
4459
shilu366312e2019-12-17 09:28:10 -08004460 /**
4461 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4462 * @param subId The subscription to use to check the configuration.
4463 * @param c The callback that will be used to send the result.
4464 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004466 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4467 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004468 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004469 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004470 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4471 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4472 "IMS not available on device.");
4473 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004474 final long token = Binder.clearCallingIdentity();
4475 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004476 int slotId = getSlotIndexOrException(subId);
4477 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004478
4479 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4480 if (controller != null) {
4481 ImsManager imsManager = controller.getImsManager(subId);
4482 if (imsManager != null) {
4483 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4484 } else {
4485 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4486 }
4487 } else {
4488 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4489 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (ImsException e) {
4491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 } finally {
4493 Binder.restoreCallingIdentity(token);
4494 }
4495 }
4496
shilu366312e2019-12-17 09:28:10 -08004497 /**
4498 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4499 * @param subId The subscription to use to check the configuration.
4500 * @param c The callback that will be used to send the result.
4501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004503 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004504 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004505 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004506 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4507 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4508 }
Meng Wangafbc5852019-09-19 17:37:13 -07004509
4510 final long token = Binder.clearCallingIdentity();
4511 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004512 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4513 if (controller != null) {
4514 ImsManager imsManager = controller.getImsManager(subId);
4515 if (imsManager != null) {
4516 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4517 } else {
4518 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4519 + " is inactive, ignoring unregister.");
4520 // If the ImsManager is not valid, just return, since the callback
4521 // will already have been removed internally.
4522 }
4523 }
Meng Wangafbc5852019-09-19 17:37:13 -07004524 } finally {
4525 Binder.restoreCallingIdentity(token);
4526 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 }
4528
4529 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004530 public boolean isCapable(int subId, int capability, int regTech) {
4531 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 final long token = Binder.clearCallingIdentity();
4533 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004534 int slotId = getSlotIndexOrException(subId);
4535 verifyImsMmTelConfiguredOrThrow(slotId);
4536 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4537 } catch (com.android.ims.ImsException e) {
4538 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4539 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004541 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4542 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 } finally {
4544 Binder.restoreCallingIdentity(token);
4545 }
4546 }
4547
4548 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004549 public boolean isAvailable(int subId, int capability, int regTech) {
4550 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004551 final long token = Binder.clearCallingIdentity();
4552 try {
4553 Phone phone = getPhone(subId);
4554 if (phone == null) return false;
4555 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004556 } catch (com.android.ims.ImsException e) {
4557 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4558 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004559 } finally {
4560 Binder.restoreCallingIdentity(token);
4561 }
4562 }
4563
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004564 /**
4565 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4566 * subscription.
4567 * @param subId The subscription to use to check the configuration.
4568 * @param callback The callback that will be used to send the result.
4569 * @param capability The MmTelFeature capability that will be used to send the result.
4570 * @param transportType The transport type of the MmTelFeature capability.
4571 */
4572 @Override
4573 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4574 int transportType) {
4575 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004576 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4577 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4578 "IMS not available on device.");
4579 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004580 final long token = Binder.clearCallingIdentity();
4581 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004582 int slotId = getSlotIndex(subId);
4583 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4584 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4585 + subId + "'");
4586 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4587 }
4588 verifyImsMmTelConfiguredOrThrow(slotId);
4589 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4590 transportType, aBoolean -> {
4591 try {
4592 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4593 } catch (RemoteException e) {
4594 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4595 + "running. Ignore");
4596 }
4597 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004600 } finally {
4601 Binder.restoreCallingIdentity(token);
4602 }
4603 }
4604
shilu366312e2019-12-17 09:28:10 -08004605 /**
4606 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4607 * @param subId The subscription to use to check the configuration.
4608 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004609 @Override
4610 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004611 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004612 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004613
Brad Ebinger35c841c2018-10-01 10:40:55 -07004614 final long token = Binder.clearCallingIdentity();
4615 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004616 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004617 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004619 } catch (ImsException e) {
4620 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 } finally {
4622 Binder.restoreCallingIdentity(token);
4623 }
4624 }
4625
4626 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004627 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004629 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 final long identity = Binder.clearCallingIdentity();
4631 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004632 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004633 // This setting doesn't require an active ImsService connection, so do not verify. The
4634 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004635 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (ImsException e) {
4637 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
4641 }
4642
shilu366312e2019-12-17 09:28:10 -08004643 /**
4644 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4645 * @param subId The subscription to use to check the configuration.
4646 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004647 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004648 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004649 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004650 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004653 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004654 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004655 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004656 } catch (ImsException e) {
4657 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 } finally {
4659 Binder.restoreCallingIdentity(identity);
4660 }
4661 }
4662
4663 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004664 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004666 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 final long identity = Binder.clearCallingIdentity();
4668 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004669 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004670 // This setting doesn't require an active ImsService connection, so do not verify. The
4671 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004672 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004673 } catch (ImsException e) {
4674 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678 }
4679
shilu366312e2019-12-17 09:28:10 -08004680 /**
4681 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4682 * @param subId The subscription to use to check the configuration.
4683 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004684 @Override
4685 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004686 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004687 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 final long identity = Binder.clearCallingIdentity();
4689 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004691 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (ImsException e) {
4694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004701 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004703 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 final long identity = Binder.clearCallingIdentity();
4705 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004706 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004707 // This setting doesn't require an active ImsService connection, so do not verify. The
4708 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004710 } catch (ImsException e) {
4711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
4715 }
4716
shilu366312e2019-12-17 09:28:10 -08004717 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004718 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4719 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4720 * @param subId The subscription to use to check the configuration.
4721 */
4722 @Override
4723 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004724 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004725 mApp, subId, "isCrossSimCallingEnabledByUser");
4726 final long identity = Binder.clearCallingIdentity();
4727 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004728 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004729 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004730 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004731 } catch (ImsException e) {
4732 throw new ServiceSpecificException(e.getCode());
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
4736 }
4737
4738 /**
4739 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4740 * Requires MODIFY_PHONE_STATE permission.
4741 * @param subId The subscription to use to check the configuration.
4742 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4743 * false otherwise
4744 */
4745 @Override
4746 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4748 "setCrossSimCallingEnabled");
4749 final long identity = Binder.clearCallingIdentity();
4750 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004751 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004752 // This setting doesn't require an active ImsService connection, so do not verify. The
4753 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004754 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004755 } catch (ImsException e) {
4756 throw new ServiceSpecificException(e.getCode());
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
4762 /**
shilu366312e2019-12-17 09:28:10 -08004763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4764 * @param subId The subscription to use to check the configuration.
4765 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004766 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004767
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004769 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004770 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 final long identity = Binder.clearCallingIdentity();
4772 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004773 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004774 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004775 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004776 } catch (ImsException e) {
4777 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 } finally {
4779 Binder.restoreCallingIdentity(identity);
4780 }
4781 }
4782
4783 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004784 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004786 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 final long identity = Binder.clearCallingIdentity();
4788 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004789 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004790 // This setting doesn't require an active ImsService connection, so do not verify. The
4791 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004792 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004793 } catch (ImsException e) {
4794 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
4798 }
4799
4800 @Override
4801 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4803 "setVoWiFiNonPersistent");
4804 final long identity = Binder.clearCallingIdentity();
4805 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004806 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004807 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004808 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004809 } catch (ImsException e) {
4810 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004811 } finally {
4812 Binder.restoreCallingIdentity(identity);
4813 }
4814 }
4815
shilu366312e2019-12-17 09:28:10 -08004816 /**
4817 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4818 * @param subId The subscription to use to check the configuration.
4819 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004820 @Override
4821 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004822 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004823 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004824 final long identity = Binder.clearCallingIdentity();
4825 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004826 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004827 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004828 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004829 } catch (ImsException e) {
4830 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
4834 }
4835
4836 @Override
4837 public void setVoWiFiModeSetting(int subId, int mode) {
4838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4839 "setVoWiFiModeSetting");
4840 final long identity = Binder.clearCallingIdentity();
4841 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004842 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004843 // This setting doesn't require an active ImsService connection, so do not verify. The
4844 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004845 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004846 } catch (ImsException e) {
4847 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
4853 @Override
4854 public int getVoWiFiRoamingModeSetting(int subId) {
4855 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4856 final long identity = Binder.clearCallingIdentity();
4857 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004858 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004859 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004860 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004861 } catch (ImsException e) {
4862 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
4866 }
4867
4868 @Override
4869 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4871 "setVoWiFiRoamingModeSetting");
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004874 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004875 // This setting doesn't require an active ImsService connection, so do not verify. The
4876 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004877 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004878 } catch (ImsException e) {
4879 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
4883 }
4884
4885 @Override
4886 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4888 "setRttCapabilityEnabled");
4889 final long identity = Binder.clearCallingIdentity();
4890 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004891 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004892 // This setting doesn't require an active ImsService connection, so do not verify. The
4893 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004894 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004895 } catch (ImsException e) {
4896 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
4900 }
4901
shilu366312e2019-12-17 09:28:10 -08004902 /**
4903 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4904 * @param subId The subscription to use to check the configuration.
4905 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004906 @Override
4907 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004908 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004909 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004910 final long identity = Binder.clearCallingIdentity();
4911 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004912 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004913 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004914 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004915 } catch (ImsException e) {
4916 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
4920 }
4921
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 @Override
4923 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4924 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004925
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004926 final long identity = Binder.clearCallingIdentity();
4927 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004928 if (!isImsAvailableOnDevice()) {
4929 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4930 "IMS not available on device.");
4931 }
4932 int slotId = getSlotIndexOrException(subId);
4933 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004934
4935 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4936 if (controller != null) {
4937 ImsManager imsManager = controller.getImsManager(subId);
4938 if (imsManager != null) {
4939 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4940 } else {
4941 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4942 }
4943 } else {
4944 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4945 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 } catch (ImsException e) {
4947 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
4953 @Override
4954 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4955 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004956
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004958 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4959 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4960 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004961 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004962 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4963 if (controller != null) {
4964 ImsManager imsManager = controller.getImsManager(subId);
4965 if (imsManager != null) {
4966 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4967 } else {
4968 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4969 + " is inactive, ignoring unregister.");
4970 // If the ImsManager is not valid, just return, since the callback will already
4971 // have been removed internally.
4972 }
4973 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
4977 }
4978
joonhunshincffb7fc2021-11-28 07:32:01 +00004979 @Override
4980 public void registerFeatureProvisioningChangedCallback(int subId,
4981 IFeatureProvisioningCallback callback) {
4982 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4983 mApp, subId, "registerFeatureProvisioningChangedCallback");
4984
4985 final long identity = Binder.clearCallingIdentity();
4986 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4987 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4988 }
4989
joonhunshin91bc1952022-04-29 08:47:15 +00004990 try {
4991 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4992 if (controller == null) {
4993 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4994 "Device does not support IMS");
4995 }
4996 controller.addFeatureProvisioningChangedCallback(subId, callback);
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005000 }
5001
5002 @Override
5003 public void unregisterFeatureProvisioningChangedCallback(int subId,
5004 IFeatureProvisioningCallback callback) {
5005 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5006 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5007
5008 final long identity = Binder.clearCallingIdentity();
5009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5010 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5011 }
5012
joonhunshin91bc1952022-04-29 08:47:15 +00005013 try {
5014 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5015 if (controller == null) {
5016 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5017 return;
5018 }
5019 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005023 }
allenwtsu99c623b2020-01-03 18:24:23 +08005024
5025 private void checkModifyPhoneStatePermission(int subId, String message) {
5026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5027 message);
5028 }
5029
allenwtsu99c623b2020-01-03 18:24:23 +08005030 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005031 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005032 boolean isProvisioned) {
5033 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005037 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5038 if (controller == null) {
5039 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5040 return;
5041 }
5042 controller.setRcsProvisioningStatusForCapability(
5043 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
allenwtsu99c623b2020-01-03 18:24:23 +08005047 }
5048
5049
5050 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005051 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5052 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5053 mApp, subId, "getRcsProvisioningStatusForCapability");
5054
allenwtsu99c623b2020-01-03 18:24:23 +08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005057 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5058 if (controller == null) {
5059 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5060
5061 // device does not support IMS, this method will return true always.
5062 return true;
5063 }
5064 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
5068 }
5069
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005070 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005071 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5072 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005073 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005074
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005075 final long identity = Binder.clearCallingIdentity();
5076 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005077 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5078 if (controller == null) {
5079 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5080 return;
5081 }
5082 controller.setImsProvisioningStatusForCapability(
5083 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
5087 }
5088
5089 @Override
5090 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005091 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5092 mApp, subId, "getProvisioningStatusForCapability");
5093
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005096 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5097 if (controller == null) {
5098 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005099
joonhunshin91bc1952022-04-29 08:47:15 +00005100 // device does not support IMS, this method will return true always.
5101 return true;
5102 }
5103 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
5107 }
5108
5109 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005110 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5111 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5112 mApp, subId, "isProvisioningRequiredForCapability");
5113
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005116 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5117 if (controller == null) {
5118 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5119
5120 // device does not support IMS, this method will return false
5121 return false;
5122 }
5123 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005126 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005127 }
5128
5129 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005130 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5131 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5132 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005133
joonhunshincffb7fc2021-11-28 07:32:01 +00005134 final long identity = Binder.clearCallingIdentity();
5135 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005136 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5137 if (controller == null) {
5138 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5139
5140 // device does not support IMS, this method will return false
5141 return false;
5142 }
5143 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005147 }
5148
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005150 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005151 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5152 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5153 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005154 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5155 mApp, subId, "getImsProvisioningInt");
5156
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005160 int slotId = getSlotIndex(subId);
5161 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5162 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5163 + subId + "' for key:" + key);
5164 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5165 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005166
joonhunshin91bc1952022-04-29 08:47:15 +00005167 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5168 if (controller == null) {
5169 loge("getImsProvisioningInt: Device does not support IMS");
5170
5171 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5172 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5173 }
5174 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005175 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5176 return retVal;
5177 }
5178
calvinpanb5a34062021-02-08 19:59:36 +08005179 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005180 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005181 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5182 + subId + "' for key:" + key);
5183 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
5187 }
5188
5189 @Override
5190 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005191 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5192 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5193 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005194 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5195 mApp, subId, "getImsProvisioningString");
5196
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005197 final long identity = Binder.clearCallingIdentity();
5198 try {
5199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005200 int slotId = getSlotIndex(subId);
5201 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5202 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5203 + subId + "' for key:" + key);
5204 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5205 }
calvinpanb5a34062021-02-08 19:59:36 +08005206 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005207 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005208 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5209 + subId + "' for key:" + key);
5210 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
5214 }
5215
5216 @Override
5217 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005218 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5219 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5220 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5222 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005223
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005227 int slotId = getSlotIndex(subId);
5228 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5229 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5230 + subId + "' for key:" + key);
5231 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5232 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005233
joonhunshin91bc1952022-04-29 08:47:15 +00005234 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5235 if (controller == null) {
5236 loge("setImsProvisioningInt: Device does not support IMS");
5237
5238 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5239 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5240 }
5241 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005242 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5243 return retVal;
5244 }
5245
calvinpanb5a34062021-02-08 19:59:36 +08005246 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5247 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005248 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005249 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005250 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
5254 }
5255
5256 @Override
5257 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005258 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5259 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5260 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5262 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005266 int slotId = getSlotIndex(subId);
5267 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5268 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5269 + subId + "' for key:" + key);
5270 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5271 }
calvinpanb5a34062021-02-08 19:59:36 +08005272 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5273 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005274 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005275 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005276 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
5280 }
5281
Brad Ebinger919631e2021-06-02 17:46:35 -07005282 /**
5283 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5284 * for the given slot ID or no ImsResolver instance has been created.
5285 * @param slotId The slot ID that the IMS service is created for.
5286 * @throws ImsException If there is no ImsService configured for this slot.
5287 */
5288 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5289 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5290 ImsFeature.FEATURE_MMTEL)) {
5291 throw new ImsException("This subscription does not support MMTEL over IMS",
5292 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5293 }
5294 }
5295
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005296 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005297 int slotId = SubscriptionManager.getSlotIndex(subId);
5298 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005299 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5300 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005301 }
5302 return slotId;
5303 }
5304
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005305 private int getSlotIndex(int subId) {
5306 int slotId = SubscriptionManager.getSlotIndex(subId);
5307 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5308 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5309 }
5310 return slotId;
5311 }
5312
Wink Saville36469e72014-06-11 15:17:00 -07005313 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005314 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005315 */
5316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005317 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5318 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005319 try {
5320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5321 } catch (SecurityException se) {
5322 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5323 throw new SecurityException("Package " + callingPackage + " does not belong to "
5324 + Binder.getCallingUid());
5325 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005326 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005327 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005328 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005329 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005330 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005331 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005332 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005333 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5334 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 final Phone phone = getPhone(subId);
5339 if (phone != null) {
5340 return phone.getServiceState().getDataNetworkType();
5341 } else {
5342 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5343 }
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005347 }
5348
5349 /**
5350 * Returns the data network type
5351 */
5352 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005353 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005354 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005355 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005356 }
5357
5358 /**
5359 * Returns the data network type for a subId
5360 */
5361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005362 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5363 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005364 String functionName = "getDataNetworkTypeForSubscriber";
5365 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5366 mApp, functionName)) {
5367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5368 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5369 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5370 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005371 }
5372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
5375 final Phone phone = getPhone(subId);
5376 if (phone != null) {
5377 return phone.getServiceState().getDataNetworkType();
5378 } else {
5379 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5380 }
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005384 }
5385
5386 /**
Wink Saville36469e72014-06-11 15:17:00 -07005387 * Returns the Voice network type for a subId
5388 */
5389 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005390 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5391 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005392 String functionName = "getVoiceNetworkTypeForSubscriber";
5393 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5394 mApp, functionName)) {
5395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5396 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5397 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5398 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005399 }
5400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 final Phone phone = getPhone(subId);
5404 if (phone != null) {
5405 return phone.getServiceState().getVoiceNetworkType();
5406 } else {
5407 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5408 }
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005412 }
5413
5414 /**
5415 * @return true if a ICC card is present
5416 */
5417 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005418 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005419 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005420 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005421 }
5422
5423 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005424 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005425 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005426 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005427 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
5430 final Phone phone = PhoneFactory.getPhone(slotIndex);
5431 if (phone != null) {
5432 return phone.getIccCard().hasIccCard();
5433 } else {
5434 return false;
5435 }
5436 } finally {
5437 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005439 }
5440
5441 /**
5442 * Return if the current radio is LTE on CDMA. This
5443 * is a tri-state return value as for a period of time
5444 * the mode may be unknown.
5445 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005446 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005447 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005448 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005449 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005451 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5452 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5453 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005454 }
5455
Sanket Padawe356d7632015-06-22 14:03:32 -07005456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005457 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5458 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005459 try {
5460 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5461 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005462 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5463 }
5464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 final Phone phone = getPhone(subId);
5468 if (phone == null) {
5469 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5470 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005471 return TelephonyProperties.lte_on_cdma_device()
5472 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 }
5474 } finally {
5475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005476 }
Wink Saville36469e72014-06-11 15:17:00 -07005477 }
5478
Wink Saville36469e72014-06-11 15:17:00 -07005479 /**
5480 * {@hide}
5481 * Returns Default subId, 0 in the case of single standby.
5482 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005483 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005484 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005485 }
5486
Shishir Agrawala9f32182016-04-12 12:00:16 -07005487 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005488 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005489 }
5490
Wink Savilleb564aae2014-10-23 10:18:09 -07005491 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005492 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005493 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005494
Pengquan Menge92a50d2018-09-21 15:54:48 -07005495 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005496 return getSubscriptionManagerService().isActiveSubId(subId,
5497 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005498 }
5499
Ihab Awadf2177b72013-11-25 13:33:23 -08005500 /**
5501 * @see android.telephony.TelephonyManager.WifiCallingChoices
5502 */
5503 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 final long identity = Binder.clearCallingIdentity();
5505 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005506 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5508 getWhenToMakeWifiCallsDefaultPreference());
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005512 }
5513
5514 /**
5515 * @see android.telephony.TelephonyManager.WifiCallingChoices
5516 */
5517 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 final long identity = Binder.clearCallingIdentity();
5519 try {
5520 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005521 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005526 }
5527
Sailesh Nepald1e68152013-12-12 19:08:02 -08005528 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005529 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005530 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005531 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005532
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005533 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5534 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5535 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005536 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005537 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005538 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
5540 return PhoneFactory.getPhone(phoneId);
5541 }
5542
Shishir Agrawal566b7612013-10-28 14:41:00 -07005543 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005544 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005545 @NonNull IccLogicalChannelRequest request) {
5546 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5547 /*message=*/ "iccOpenLogicalChannel");
5548
5549 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5550 // Verify that the callingPackage in the request belongs to the calling UID
5551 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5552
5553 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005555
Rambo Wanga1782702021-11-10 20:15:19 -08005556 private Phone getPhoneFromValidIccLogicalChannelRequest(
5557 @NonNull IccLogicalChannelRequest request, String message) {
5558 Phone phone;
5559 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5561 mApp, request.subId, message);
5562 phone = getPhoneFromSubId(request.subId);
5563 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5564 enforceModifyPermission();
5565 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5566 } else {
5567 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005568 }
Rambo Wanga1782702021-11-10 20:15:19 -08005569 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005570 }
5571
5572 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005573 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005576 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005578 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5579 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005580 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5581 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 loge("The calling package is not allowed to access ISD-R.");
5583 throw new SecurityException(
5584 "The calling package is not allowed to access ISD-R.");
5585 }
Derek Tan740e1672017-06-27 14:56:27 -07005586 }
Derek Tan740e1672017-06-27 14:56:27 -07005587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005589 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5590 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 return response;
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005595 }
5596
5597 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005598 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5599 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5600 /*message=*/"iccCloseLogicalChannel");
5601
5602 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5603
5604 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005606
Rambo Wanga1782702021-11-10 20:15:19 -08005607 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5608 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005609 // before this feature is enabled, this API should only return false if
5610 // the operation fails instead of throwing runtime exception for
5611 // backward-compatibility.
5612 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5613 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 final long identity = Binder.clearCallingIdentity();
5615 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005616 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005617 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 }
Chen Xue9d737e2022-01-01 23:41:31 -08005619 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005620 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005621 Boolean success = false;
5622 if (result instanceof RuntimeException) {
5623 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005624 if (shouldThrowExceptionOnFailure) {
5625 throw (RuntimeException) result;
5626 } else {
5627 return false;
5628 }
Chen Xue9d737e2022-01-01 23:41:31 -08005629 } else if (result instanceof Boolean) {
5630 success = (Boolean) result;
5631 } else {
5632 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5633 }
Rambo Wanga1782702021-11-10 20:15:19 -08005634 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 return success;
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005639 }
5640
5641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005642 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005643 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5645 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005646 if (DBG) {
5647 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5648 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5649 + p3 + " data=" + data);
5650 }
5651 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5652 command, p1, p2, p3, data);
5653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005654
Jordan Liu4c733742019-02-28 12:03:40 -08005655 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005656 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005657 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005658 enforceModifyPermission();
5659 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005660 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005661 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5662 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005663 }
5664 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005665 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5666 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005667 }
5668
5669 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5670 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
5672 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005673 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 return "";
5675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005678 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5679 null /* workSource */);
5680 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 // Append the returned status code to the end of the response payload.
5683 String s = Integer.toHexString(
5684 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5685 if (response.payload != null) {
5686 s = IccUtils.bytesToHexString(response.payload) + s;
5687 }
5688 return s;
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005691 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005692 }
Jake Hambye994d462014-02-03 13:10:13 -08005693
Evan Charltonc66da362014-05-16 14:06:40 -07005694 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005695 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5696 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5698 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005700 if (DBG) {
5701 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5702 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5703 }
5704 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5705 cla, command, p1, p2, p3, data);
5706 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005707
Jordan Liu4c733742019-02-28 12:03:40 -08005708 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005709 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005710 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005711 enforceModifyPermission();
5712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5713 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005714 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005715 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5716 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005717 }
5718
5719 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005720 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5721 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005722 }
5723
5724 // open APDU basic channel assuming the caller has sufficient permissions
5725 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5726 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5730 && TextUtils.equals(ISDR_AID, data)) {
5731 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005732 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5733 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 if (bestComponent == null
5735 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5736 loge("The calling package is not allowed to select ISD-R.");
5737 throw new SecurityException(
5738 "The calling package is not allowed to select ISD-R.");
5739 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005740 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005743 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5744 null /* workSource */);
5745 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 // Append the returned status code to the end of the response payload.
5748 String s = Integer.toHexString(
5749 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5750 if (response.payload != null) {
5751 s = IccUtils.bytesToHexString(response.payload) + s;
5752 }
5753 return s;
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005756 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005757 }
5758
5759 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005760 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005761 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5763 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 if (DBG) {
5768 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5769 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5770 }
5771
5772 IccIoResult response =
5773 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5774 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5775 subId);
5776
5777 if (DBG) {
5778 log("Exchange SIM_IO [R]" + response);
5779 }
5780
5781 byte[] result = null;
5782 int length = 2;
5783 if (response.payload != null) {
5784 length = 2 + response.payload.length;
5785 result = new byte[length];
5786 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5787 } else {
5788 result = new byte[length];
5789 }
5790
5791 result[length - 1] = (byte) response.sw2;
5792 result[length - 2] = (byte) response.sw1;
5793 return result;
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005796 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005797 }
5798
Nathan Haroldb3014052017-01-25 15:57:32 -08005799 /**
5800 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5801 * on a particular subscription
5802 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005803 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5804 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005807 return null;
5808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809
5810 final long identity = Binder.clearCallingIdentity();
5811 try {
5812 if (appType != TelephonyManager.APPTYPE_USIM
5813 && appType != TelephonyManager.APPTYPE_SIM) {
5814 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5815 return null;
5816 }
5817 Object response = sendRequest(
5818 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5819 if (response instanceof String[]) {
5820 return (String[]) response;
5821 }
yincheng zhao2737e882019-09-06 17:06:54 -07005822 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005824 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005827 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005828 }
5829
yincheng zhao2737e882019-09-06 17:06:54 -07005830 /**
5831 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5832 * subscription.
5833 *
5834 * @param subId the id of the subscription.
5835 * @param appType the uicc app type, must be USIM or SIM.
5836 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5837 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005838 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005839 * @return number of fplmns that is successfully written to the SIM.
5840 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005841 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5842 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5844 mApp, subId, "setForbiddenPlmns");
5845
yincheng zhao2737e882019-09-06 17:06:54 -07005846 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5847 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5848 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5849 }
5850 if (fplmns == null) {
5851 throw new IllegalArgumentException("Fplmn List provided is null");
5852 }
5853 for (String fplmn : fplmns) {
5854 if (!CellIdentity.isValidPlmn(fplmn)) {
5855 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5856 }
5857 }
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 Object response = sendRequest(
5861 CMD_SET_FORBIDDEN_PLMNS,
5862 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5863 subId);
5864 return (int) response;
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005870 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005871 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5873 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 final long identity = Binder.clearCallingIdentity();
5876 try {
5877 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5878 if (response.payload == null) {
5879 return "";
5880 }
Evan Charltonc66da362014-05-16 14:06:40 -07005881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 // Append the returned status code to the end of the response payload.
5883 String s = Integer.toHexString(
5884 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5885 s = IccUtils.bytesToHexString(response.payload) + s;
5886 return s;
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
Evan Charltonc66da362014-05-16 14:06:40 -07005890 }
5891
Jake Hambye994d462014-02-03 13:10:13 -08005892 /**
5893 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5894 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5895 *
5896 * @param itemID the ID of the item to read
5897 * @return the NV item as a String, or null on error.
5898 */
5899 @Override
5900 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005901 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5903 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005908 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5910 return value;
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
Jake Hambye994d462014-02-03 13:10:13 -08005914 }
5915
5916 /**
5917 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5918 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5919 *
5920 * @param itemID the ID of the item to read
5921 * @param itemValue the value to write, as a String
5922 * @return true on success; false on any failure
5923 */
5924 @Override
5925 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5928 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5933 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005934 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5936 return success;
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Jake Hambye994d462014-02-03 13:10:13 -08005940 }
5941
5942 /**
5943 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5944 * Used for device configuration by some CDMA operators.
5945 *
5946 * @param preferredRoamingList byte array containing the new PRL
5947 * @return true on success; false on any failure
5948 */
5949 @Override
5950 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5952 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5957 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5958 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5959 return success;
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
Jake Hambye994d462014-02-03 13:10:13 -08005963 }
5964
5965 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005966 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005967 * Used for device configuration by some CDMA operators.
5968 *
chen xu6dac5ab2018-10-26 17:39:23 -07005969 * @param slotIndex - device slot.
5970 *
Jake Hambye994d462014-02-03 13:10:13 -08005971 * @return true on success; false on any failure
5972 */
5973 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005974 public boolean resetModemConfig(int slotIndex) {
5975 Phone phone = PhoneFactory.getPhone(slotIndex);
5976 if (phone != null) {
5977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5978 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979
chen xu6dac5ab2018-10-26 17:39:23 -07005980 final long identity = Binder.clearCallingIdentity();
5981 try {
5982 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5983 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5984 return success;
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 }
chen xu6dac5ab2018-10-26 17:39:23 -07005989 return false;
5990 }
5991
5992 /**
5993 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5994 *
5995 * @param slotIndex - device slot.
5996 *
5997 * @return true on success; false on any failure
5998 */
5999 @Override
6000 public boolean rebootModem(int slotIndex) {
6001 Phone phone = PhoneFactory.getPhone(slotIndex);
6002 if (phone != null) {
6003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, phone.getSubId(), "rebootModem");
6005
6006 final long identity = Binder.clearCallingIdentity();
6007 try {
6008 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6009 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6010 return success;
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
6014 }
6015 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006016 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006017
Brad Ebinger51f743a2017-01-23 13:50:20 -08006018 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006019 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6020 * {@link #disableIms(int)}.
6021 * @param slotIndex device slot.
6022 */
6023 public void resetIms(int slotIndex) {
6024 enforceModifyPermission();
6025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 if (mImsResolver == null) {
6029 // may happen if the does not support IMS.
6030 return;
6031 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006032 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
6036 }
6037
6038 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006039 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6040 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006041 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006042 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006047 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006048 // may happen if the device does not support IMS.
6049 return;
6050 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 } finally {
6053 Binder.restoreCallingIdentity(identity);
6054 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006055 }
6056
6057 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006058 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6059 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006060 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006061 public void disableIms(int slotId) {
6062 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006066 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006067 // may happen if the device does not support IMS.
6068 return;
6069 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006070 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006074 }
6075
6076 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006077 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6078 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006079 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006080 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006081 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006082 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083
6084 final long identity = Binder.clearCallingIdentity();
6085 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006086 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006087 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6088 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006089 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006090 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006094 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006095 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006096 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6097 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006098 @Override
6099 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006100 enforceModifyPermission();
6101
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006105 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
6109 }
6110
6111 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006112 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006113 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006114 */
6115 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117
6118 final long identity = Binder.clearCallingIdentity();
6119 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006120 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006121 // may happen if the device does not support IMS.
6122 return null;
6123 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006124 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006128 }
6129
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006130 /**
6131 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006132 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006133 */
6134 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136
6137 final long identity = Binder.clearCallingIdentity();
6138 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006139 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006140 // may happen if the device does not support IMS.
6141 return null;
6142 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006143 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006147 }
6148
Brad Ebinger884c07b2018-02-15 16:17:40 -08006149 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006150 * Sets the ImsService Package Name that Telephony will bind to.
6151 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006152 * @param slotIndex the slot ID that the ImsService should bind for.
6153 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006154 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006155 * @param featureTypes An integer array of feature types associated with a packageName.
6156 * @param packageName The name of the package that the current configuration will be replaced
6157 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006158 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006159 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006160 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6161 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006164 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 final long identity = Binder.clearCallingIdentity();
6167 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006168 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006169 // may happen if the device does not support IMS.
6170 return false;
6171 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006172 Map<Integer, String> featureConfig = new HashMap<>();
6173 for (int featureType : featureTypes) {
6174 featureConfig.put(featureType, packageName);
6175 }
6176 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6177 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006181 }
6182
6183 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006184 * Clears any carrier ImsService overrides for the slot index specified that were previously
6185 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6186 *
6187 * This should only be used for testing.
6188 *
6189 * @param slotIndex the slot ID that the ImsService should bind for.
6190 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6191 */
6192 @Override
6193 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6195 "clearCarrierImsServiceOverride");
6196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006197 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006198
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 if (mImsResolver == null) {
6202 // may happen if the device does not support IMS.
6203 return false;
6204 }
6205 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
6209 }
6210
6211 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006212 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006213 *
6214 * @param slotId The slot that the ImsService is associated with.
6215 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6216 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006217 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006218 * @return the package name of the ImsService configuration.
6219 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006220 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6221 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006222 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006223 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6224 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006228 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006229 // may happen if the device does not support IMS.
6230 return "";
6231 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006232 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006233 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6234 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 } finally {
6236 Binder.restoreCallingIdentity(identity);
6237 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006238 }
6239
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006240 /**
6241 * Get the MmTelFeature state associated with the requested subscription id.
6242 * @param subId The subscription that the MmTelFeature is associated with.
6243 * @param callback A callback with an integer containing the
6244 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6245 */
6246 @Override
6247 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6248 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006249 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6250 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6251 "IMS not available on device.");
6252 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006253 final long token = Binder.clearCallingIdentity();
6254 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006255 int slotId = getSlotIndex(subId);
6256 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6257 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6258 + subId + "'");
6259 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6260 }
6261 verifyImsMmTelConfiguredOrThrow(slotId);
6262 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6263 try {
6264 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6265 } catch (RemoteException e) {
6266 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6267 + "Ignore");
6268 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006269 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006270 } catch (ImsException e) {
6271 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006272 } finally {
6273 Binder.restoreCallingIdentity(token);
6274 }
6275 }
6276
Daniel Brightbb5840b2021-01-12 15:48:18 -08006277 /**
6278 * Sets the ims registration state on all valid {@link Phone}s.
6279 */
6280 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006281 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282
6283 final long identity = Binder.clearCallingIdentity();
6284 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006285 // NOTE: Before S, this method only set the default phone.
6286 for (final Phone phone : PhoneFactory.getPhones()) {
6287 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6288 phone.setImsRegistrationState(registered);
6289 }
6290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 } finally {
6292 Binder.restoreCallingIdentity(identity);
6293 }
Wink Saville36469e72014-06-11 15:17:00 -07006294 }
6295
6296 /**
Stuart Scott54788802015-03-30 13:18:01 -07006297 * Set the network selection mode to automatic.
6298 *
6299 */
6300 @Override
6301 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6303 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304
6305 final long identity = Binder.clearCallingIdentity();
6306 try {
shilufc958392020-01-20 11:36:01 -08006307 if (!isActiveSubscription(subId)) {
6308 return;
6309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006311 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6312 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 } finally {
6314 Binder.restoreCallingIdentity(identity);
6315 }
Stuart Scott54788802015-03-30 13:18:01 -07006316 }
6317
Jack Yud10cdd42020-09-28 20:28:01 -07006318 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006319 * Ask the radio to connect to the input network and change selection mode to manual.
6320 *
6321 * @param subId the id of the subscription.
6322 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6323 * the operator to attach to.
6324 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6325 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6326 * normal network selection next time.
6327 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006328 */
6329 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006330 public boolean setNetworkSelectionModeManual(
6331 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6333 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006334
Jack Yu285100e2022-12-02 22:48:35 -08006335 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006336 if (!isActiveSubscription(subId)) {
6337 return false;
6338 }
6339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006341 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006343 if (DBG) {
6344 log("setNetworkSelectionModeManual: subId: " + subId
6345 + " operator: " + operatorInfo);
6346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006351 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006352 /**
shilu84f6e8b2019-12-19 13:58:01 -08006353 * Get the manual network selection
6354 *
6355 * @param subId the id of the subscription.
6356 *
6357 * @return the previously saved user selected PLMN
6358 */
6359 @Override
6360 public String getManualNetworkSelectionPlmn(int subId) {
6361 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006362 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6363 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006364
6365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006368 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006369 }
6370
6371 final Phone phone = getPhone(subId);
6372 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006373 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006374 }
6375 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6376 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006377 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006382
6383 /**
6384 * Scans for available networks.
6385 */
6386 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006387 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6388 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6390 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006391 LocationAccessPolicy.LocationPermissionResult locationResult =
6392 LocationAccessPolicy.checkLocationPermission(mApp,
6393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6394 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006395 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006396 .setCallingPid(Binder.getCallingPid())
6397 .setCallingUid(Binder.getCallingUid())
6398 .setMethod("getCellNetworkScanResults")
6399 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006400 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6401 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006402 .build());
6403 switch (locationResult) {
6404 case DENIED_HARD:
6405 throw new SecurityException("Not allowed to access scan results -- location");
6406 case DENIED_SOFT:
6407 return null;
6408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
Pengquan Menga1bb6272018-09-06 09:59:22 -07006410 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 try {
6412 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006413 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 } finally {
6416 Binder.restoreCallingIdentity(identity);
6417 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006418 }
6419
6420 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006421 * Get the call forwarding info, given the call forwarding reason.
6422 */
6423 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006424 public void getCallForwarding(int subId, int callForwardingReason,
6425 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006426 enforceReadPrivilegedPermission("getCallForwarding");
6427 long identity = Binder.clearCallingIdentity();
6428 try {
6429 if (DBG) {
6430 log("getCallForwarding: subId " + subId
6431 + " callForwardingReason" + callForwardingReason);
6432 }
Hall Liu27d24262020-09-18 19:04:59 -07006433
6434 Phone phone = getPhone(subId);
6435 if (phone == null) {
6436 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006437 callback.onError(
6438 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006439 } catch (RemoteException e) {
6440 // ignore
6441 }
6442 return;
6443 }
6444
6445 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6446 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6447 @Override
6448 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6449 try {
6450 callback.onCallForwardingInfoAvailable(info);
6451 } catch (RemoteException e) {
6452 // ignore
6453 }
6454 }
6455
6456 @Override
6457 public void onError(int error) {
6458 try {
6459 callback.onError(error);
6460 } catch (RemoteException e) {
6461 // ignore
6462 }
6463 }
6464 });
6465 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
6471 /**
6472 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6473 * reason, the number to forward, and the timeout before the forwarding is attempted.
6474 */
6475 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006476 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6477 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006478 enforceModifyPermission();
6479 long identity = Binder.clearCallingIdentity();
6480 try {
6481 if (DBG) {
6482 log("setCallForwarding: subId " + subId
6483 + " callForwardingInfo" + callForwardingInfo);
6484 }
Hall Liu27d24262020-09-18 19:04:59 -07006485
6486 Phone phone = getPhone(subId);
6487 if (phone == null) {
6488 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006489 callback.accept(
6490 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006491 } catch (RemoteException e) {
6492 // ignore
6493 }
6494 return;
6495 }
6496
6497 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6498 FunctionalUtils.ignoreRemoteException(callback::accept));
6499
6500 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505
6506 /**
Hall Liu27d24262020-09-18 19:04:59 -07006507 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006508 */
6509 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006510 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006511 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006512 long identity = Binder.clearCallingIdentity();
6513 try {
Hall Liu27d24262020-09-18 19:04:59 -07006514 Phone phone = getPhone(subId);
6515 if (phone == null) {
6516 try {
6517 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6518 } catch (RemoteException e) {
6519 // ignore
6520 }
6521 return;
6522 }
SongFerngWang0e767992021-03-31 22:08:45 +08006523 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6524 PersistableBundle c = configManager.getConfigForSubId(subId);
6525 boolean requireUssd = c.getBoolean(
6526 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006527
Shuo Qian4a594052020-01-23 11:59:30 -08006528 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006529 if (requireUssd) {
6530 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6531 getSubscriptionCarrierId(subId));
6532 String newUssdCommand = "";
6533 try {
6534 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006535 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006536 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6537 } catch (NullPointerException e) {
6538 loge("Failed to generate USSD number" + e);
6539 }
6540 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6541 mMainThreadHandler, callback, carrierXmlParser,
6542 CarrierXmlParser.SsEntry.SSAction.QUERY);
6543 final String ussdCommand = newUssdCommand;
6544 Executors.newSingleThreadExecutor().execute(() -> {
6545 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6546 });
6547 } else {
6548 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6549 callback::accept);
6550 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6551 }
Shuo Qian4a594052020-01-23 11:59:30 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
6555 }
6556
6557 /**
Hall Liu27d24262020-09-18 19:04:59 -07006558 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006559 */
6560 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006561 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006562 enforceModifyPermission();
6563 long identity = Binder.clearCallingIdentity();
6564 try {
Hall Liu27d24262020-09-18 19:04:59 -07006565 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6566
6567 Phone phone = getPhone(subId);
6568 if (phone == null) {
6569 try {
6570 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6571 } catch (RemoteException e) {
6572 // ignore
6573 }
6574 return;
6575 }
6576
SongFerngWang0e767992021-03-31 22:08:45 +08006577 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6578 PersistableBundle c = configManager.getConfigForSubId(subId);
6579 boolean requireUssd = c.getBoolean(
6580 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006581
SongFerngWang0e767992021-03-31 22:08:45 +08006582 if (DBG) log("getCallWaitingStatus: subId " + subId);
6583 if (requireUssd) {
6584 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6585 getSubscriptionCarrierId(subId));
6586 CarrierXmlParser.SsEntry.SSAction ssAction =
6587 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6588 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6589 String newUssdCommand = "";
6590 try {
6591 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006592 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006593 .makeCommand(ssAction, null);
6594 } catch (NullPointerException e) {
6595 loge("Failed to generate USSD number" + e);
6596 }
6597 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6598 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6599 final String ussdCommand = newUssdCommand;
6600 Executors.newSingleThreadExecutor().execute(() -> {
6601 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6602 });
6603 } else {
6604 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6605 FunctionalUtils.ignoreRemoteException(callback::accept));
6606
6607 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6608 }
Shuo Qian4a594052020-01-23 11:59:30 -08006609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611 }
6612 }
6613
6614 /**
yinxub1bed742017-04-17 11:45:04 -07006615 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006616 *
yinxub1bed742017-04-17 11:45:04 -07006617 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006618 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6619 * location related information which will be sent if the caller already possess
6620 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006621 * @param request contains the radio access networks with bands/channels to scan
6622 * @param messenger callback messenger for scan results or errors
6623 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006624 * @return the id of the requested scan which can be used to stop the scan.
6625 */
6626 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006627 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6628 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006629 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6631 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006632 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006633 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6634 if (!renounceFineLocationAccess) {
6635 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006636 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6637 .setCallingPackage(callingPackage)
6638 .setCallingFeatureId(callingFeatureId)
6639 .setCallingPid(Binder.getCallingPid())
6640 .setCallingUid(Binder.getCallingUid())
6641 .setMethod("requestNetworkScan")
6642 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6643 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6644 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6645 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006646 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006647 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006648 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6649 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006650 if (e != null) {
6651 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6652 throw e;
6653 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006654 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006655 return TelephonyScanManager.INVALID_SCAN_ID;
6656 }
6657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 }
Hall Liu912dfd32019-04-25 14:02:26 -07006659 int callingUid = Binder.getCallingUid();
6660 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006661 final long identity = Binder.clearCallingIdentity();
6662 try {
6663 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006664 renounceFineLocationAccess, request, messenger, binder,
6665 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006666 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
6669 }
yinxu504e1392017-04-12 16:03:22 -07006670 }
6671
Hall Liub2ac8ef2019-02-28 15:56:23 -08006672 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006673 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006674 boolean hasCarrierPriv;
6675 final long identity = Binder.clearCallingIdentity();
6676 try {
6677 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6678 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
Hall Liu558027f2019-05-15 19:14:05 -07006682 boolean hasNetworkScanPermission =
6683 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006684 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006685
6686 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6687 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6688 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006689 }
6690
6691 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6692 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006693 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6694 return new SecurityException("Specific channels must not be"
6695 + " scanned without location access.");
6696 }
6697 }
6698 }
6699
Hall Liub2ac8ef2019-02-28 15:56:23 -08006700 return null;
6701 }
6702
yinxu504e1392017-04-12 16:03:22 -07006703 /**
6704 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006705 *
6706 * @param subId id of the subscription
6707 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006708 */
6709 @Override
6710 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6712 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713
Hall Liu912dfd32019-04-25 14:02:26 -07006714 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006717 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 } finally {
6719 Binder.restoreCallingIdentity(identity);
6720 }
yinxu504e1392017-04-12 16:03:22 -07006721 }
6722
6723 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006724 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006725 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006726 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006727 */
6728 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006729 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006730 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006731 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006732 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733
6734 final long identity = Binder.clearCallingIdentity();
6735 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006736 if (DBG) log("getAllowedNetworkTypesBitmask");
6737 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6738 int networkTypesBitmask = (result != null ? result[0] : -1);
6739 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6740 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 } finally {
6742 Binder.restoreCallingIdentity(identity);
6743 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006744 }
6745
6746 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006747 * Get the allowed network types for certain reason.
6748 *
6749 * @param subId the id of the subscription.
6750 * @param reason the reason the allowed network type change is taking place
6751 * @return the allowed network types.
6752 */
6753 @Override
6754 public long getAllowedNetworkTypesForReason(int subId,
6755 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006756 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006757 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006758 final long identity = Binder.clearCallingIdentity();
6759 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006760 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
6764 }
6765
6766 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006767 * Enable/Disable E-UTRA-NR Dual Connectivity
6768 * @param subId subscription id of the sim card
6769 * @param nrDualConnectivityState expected NR dual connectivity state
6770 * This can be passed following states
6771 * <ol>
6772 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6773 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6774 * <li>Disable NR dual connectivity and force secondary cell to be released
6775 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6776 * </ol>
6777 * @return operation result.
6778 */
6779 @Override
6780 public int setNrDualConnectivityState(int subId,
6781 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6783 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006784 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006785 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6786 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6787 }
6788
Sooraj Sasindran37444802020-08-11 10:40:43 -07006789 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6793 nrDualConnectivityState, subId,
6794 workSource);
6795 if (DBG) log("enableNRDualConnectivity result: " + result);
6796 return result;
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
6800 }
6801
6802 /**
6803 * Is E-UTRA-NR Dual Connectivity enabled
6804 * @return true if dual connectivity is enabled else false
6805 */
6806 @Override
6807 public boolean isNrDualConnectivityEnabled(int subId) {
6808 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006809 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006810 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006811 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006812 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6813 return false;
6814 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6819 null, subId, workSource);
6820 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6821 return isEnabled;
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
6825 }
6826
6827 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006828 * Set the allowed network types of the device and
6829 * provide the reason triggering the allowed network change.
6830 *
6831 * @param subId the id of the subscription.
6832 * @param reason the reason the allowed network type change is taking place
6833 * @param allowedNetworkTypes the allowed network types.
6834 * @return true on success; false on any failure.
6835 */
6836 @Override
6837 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006838 @TelephonyManager.AllowedNetworkTypesReason int reason,
6839 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6841 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006842 // If the caller only has carrier privileges, then they should not be able to override
6843 // any network types which were set for security reasons.
6844 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6845 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006846 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006847 throw new SecurityException(
6848 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006849 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006850 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006851 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006852 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006853 return false;
6854 }
6855 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6856 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006857 return false;
6858 }
6859
Jack Yu5b494332023-01-23 18:18:04 +00006860 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6861 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006862
Jack Yue37dd262022-12-16 11:53:37 -08006863 Phone phone = getPhone(subId);
6864 if (phone == null) {
6865 return false;
6866 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006867
Jack Yue37dd262022-12-16 11:53:37 -08006868 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006869 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006870 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006871 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006872
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006873 final long identity = Binder.clearCallingIdentity();
6874 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006875 Boolean success = (Boolean) sendRequest(
6876 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6877 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6878
6879 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6880 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006881 } finally {
6882 Binder.restoreCallingIdentity(identity);
6883 }
6884 }
6885
6886 /**
Miaoa84611c2019-03-15 09:21:10 +08006887 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006888 *
Miaoa84611c2019-03-15 09:21:10 +08006889 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006890 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006891 * @hide
6892 */
6893 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006894 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006897 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 try {
Miaoa84611c2019-03-15 09:21:10 +08006899 if (phone != null) {
6900 return phone.hasMatchedTetherApnSetting();
6901 } else {
6902 return false;
6903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 } finally {
6905 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006906 }
Junda Liu475951f2014-11-07 16:45:03 -08006907 }
6908
6909 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006910 * Get the user enabled state of Mobile Data.
6911 *
6912 * TODO: remove and use isUserDataEnabled.
6913 * This can't be removed now because some vendor codes
6914 * calls through ITelephony directly while they should
6915 * use TelephonyManager.
6916 *
6917 * @return true on enabled
6918 */
6919 @Override
6920 public boolean getDataEnabled(int subId) {
6921 return isUserDataEnabled(subId);
6922 }
6923
6924 /**
6925 * Get whether mobile data is enabled per user setting.
6926 *
6927 * There are other factors deciding whether mobile data is actually enabled, but they are
6928 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006929 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006930 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6931 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006932 *
6933 * @return {@code true} if data is enabled else {@code false}
6934 */
6935 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006936 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006937 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006938 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006939 try {
6940 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6941 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006942 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006943 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6944 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006945 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006947 mApp, subId, functionName);
6948
Robert Greenwalt646120a2014-05-23 11:54:03 -07006949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
Jack Yu285100e2022-12-02 22:48:35 -08006953 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6955 Phone phone = PhoneFactory.getPhone(phoneId);
6956 if (phone != null) {
6957 boolean retVal = phone.isUserDataEnabled();
6958 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6959 return retVal;
6960 } else {
6961 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6962 return false;
6963 }
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006966 }
6967 }
6968
6969 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006970 * Checks if the device is capable of mobile data by considering whether whether the
6971 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6972 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006973 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006974 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006975 */
6976 @Override
6977 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006978 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006979 try {
6980 try {
6981 mApp.enforceCallingOrSelfPermission(
6982 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006983 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006984 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006985 try {
6986 mApp.enforceCallingOrSelfPermission(
6987 android.Manifest.permission.READ_PHONE_STATE,
6988 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006989 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006990 mApp.enforceCallingOrSelfPermission(
6991 permission.READ_BASIC_PHONE_STATE, functionName);
6992 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006993 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006994 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006995 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997
6998 final long identity = Binder.clearCallingIdentity();
6999 try {
Jack Yu285100e2022-12-02 22:48:35 -08007000 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 Phone phone = PhoneFactory.getPhone(phoneId);
7002 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007003 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007004 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 return retVal;
7006 } else {
7007 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7008 return false;
7009 }
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007012 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007013 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007014
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007015 /**
7016 * Check if data is enabled for a specific reason
7017 * @param subId Subscription index
7018 * @param reason the reason the data enable change is taking place
7019 * @return {@code true} if the overall data is enabled; {@code false} if not.
7020 */
7021 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007022 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007023 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007024 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007025 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007026 try {
7027 mApp.enforceCallingOrSelfPermission(
7028 android.Manifest.permission.ACCESS_NETWORK_STATE,
7029 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007030 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007031 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7032 functionName);
7033 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007034 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007035 try {
7036 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007037 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007038 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007040 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007041 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007042 }
7043
7044
7045 final long identity = Binder.clearCallingIdentity();
7046 try {
Jack Yu285100e2022-12-02 22:48:35 -08007047 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007048 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007049 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007050 + " reason=" + reason);
7051 }
7052 Phone phone = PhoneFactory.getPhone(phoneId);
7053 if (phone != null) {
7054 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007055 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007056 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007057 return retVal;
7058 } else {
7059 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007060 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007061 + subId + " retVal=false");
7062 }
7063 return false;
7064 }
7065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
7068 }
7069
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007071 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007072 // No permission needed; this only lets the caller inspect their own status.
7073 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007074 }
Junda Liu29340342014-07-10 15:23:27 -07007075
7076 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007077 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007078 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007079 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7080 }
7081
7082 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7083 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007085 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7087 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007088 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7089 if (cpt == null) {
7090 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007091 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7092 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007093 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007094 }
7095
7096 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007097 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007098 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007099 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007101 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007102 Phone phone = getPhone(subId);
7103 if (phone == null) {
7104 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7105 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7106 }
7107 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7108 if (cpt == null) {
7109 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007110 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7111 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007112 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007113 }
7114
7115 @Override
7116 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007117 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007118 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7119 }
7120
7121 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007122 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007123 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007124 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007125 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007126 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7127 Phone phone = PhoneFactory.getPhone(phoneId);
7128 if (phone == null) {
7129 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007130 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007131 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7132 if (cpt == null) {
7133 continue;
7134 }
7135 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007136 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7137 break;
7138 }
7139 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007140 return result;
Junda Liu29340342014-07-10 15:23:27 -07007141 }
Derek Tan89e89d42014-07-08 17:00:10 -07007142
7143 @Override
Junda Liue64de782015-04-16 17:19:16 -07007144 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007145 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007146 Phone phone = PhoneFactory.getPhone(phoneId);
7147 if (phone == null) {
7148 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007149 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007150 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7151 if (cpt == null) {
7152 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007153 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007154 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007155 }
7156
Amith Yamasani6e118872016-02-19 12:53:51 -08007157 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007158 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007159 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007160 Phone phone = PhoneFactory.getPhone(phoneId);
7161 if (phone == null) {
7162 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007163 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007164 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7165 if (cpt == null) {
7166 return Collections.emptyList();
7167 }
7168 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007169 }
7170
chen xuf7e9fe82019-05-09 19:31:02 -07007171 @Override
7172 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007173 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007174 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007175 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007176 try {
7177 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7178 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7179 }
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007182 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007183 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007184 }
7185
Rambo Wang6812ffb2022-03-15 16:54:17 -07007186 @Override
7187 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7188 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7189
7190 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7191 if (phone == null) {
7192 return null;
7193 }
7194 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7195 if (cpt == null) {
7196 return null;
7197 }
7198 return cpt.getCarrierServicePackageName();
7199 }
7200
Wink Savilleb564aae2014-10-23 10:18:09 -07007201 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007202 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007203 UiccPort port = phone == null ? null : phone.getUiccPort();
7204 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007205 return null;
7206 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007207 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007208 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007209 return null;
7210 }
7211 return iccId;
7212 }
7213
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007214 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007215 public void setCallComposerStatus(int subId, int status) {
7216 enforceModifyPermission();
7217
7218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 Phone phone = getPhone(subId);
7221 if (phone != null) {
7222 Phone defaultPhone = phone.getImsPhone();
7223 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7224 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7225 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007226 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7227 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007228 }
7229 }
Shuo Qian284ae752020-12-22 19:10:14 -08007230 } catch (ImsException e) {
7231 throw new ServiceSpecificException(e.getCode());
7232 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007233 Binder.restoreCallingIdentity(identity);
7234 }
7235 }
7236
7237 @Override
7238 public int getCallComposerStatus(int subId) {
7239 enforceReadPrivilegedPermission("getCallComposerStatus");
7240
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
7243 Phone phone = getPhone(subId);
7244 if (phone != null) {
7245 Phone defaultPhone = phone.getImsPhone();
7246 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7247 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7248 return imsPhone.getCallComposerStatus();
7249 }
7250 }
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
7254 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7255 }
7256
7257 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007258 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7259 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007260 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007261 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 final String iccId = getIccId(subId);
7266 final Phone phone = getPhone(subId);
7267 if (phone == null) {
7268 return false;
7269 }
7270 final String subscriberId = phone.getSubscriberId();
7271
7272 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007273 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 + subscriberId + " to " + number);
7275 }
7276
7277 if (TextUtils.isEmpty(iccId)) {
7278 return false;
7279 }
7280
7281 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7282
7283 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7284 if (alphaTag == null) {
7285 editor.remove(alphaTagPrefKey);
7286 } else {
7287 editor.putString(alphaTagPrefKey, alphaTag);
7288 }
7289
7290 // Record both the line number and IMSI for this ICCID, since we need to
7291 // track all merged IMSIs based on line number
7292 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7293 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7294 if (number == null) {
7295 editor.remove(numberPrefKey);
7296 editor.remove(subscriberPrefKey);
7297 } else {
7298 editor.putString(numberPrefKey, number);
7299 editor.putString(subscriberPrefKey, subscriberId);
7300 }
7301
7302 editor.commit();
7303 return true;
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007306 }
Derek Tan7226c842014-07-02 17:42:23 -07007307 }
7308
7309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007310 public String getLine1NumberForDisplay(int subId, String callingPackage,
7311 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007312 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007314 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007315 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007316 return null;
7317 }
Derek Tan97ebb422014-09-05 16:55:38 -07007318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 String iccId = getIccId(subId);
7322 if (iccId != null) {
7323 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7324 if (DBG_MERGE) {
7325 log("getLine1NumberForDisplay returning "
7326 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7327 }
7328 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7331 return null;
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007334 }
Derek Tan7226c842014-07-02 17:42:23 -07007335 }
7336
7337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7339 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007342 return null;
7343 }
Derek Tan97ebb422014-09-05 16:55:38 -07007344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 String iccId = getIccId(subId);
7348 if (iccId != null) {
7349 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7350 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7351 }
7352 return null;
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007355 }
Derek Tan7226c842014-07-02 17:42:23 -07007356 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007357
7358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007359 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7360 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007361 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7362 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007364 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007365 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007366 return null;
7367 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007368
Jordan Liub49b04b2019-05-06 14:45:15 -07007369 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7370 // the process, where TelephonyManager was instantiated.
7371 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007372 final long identity = Binder.clearCallingIdentity();
7373 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007374 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 final TelephonyManager tele = TelephonyManager.from(context);
7376 final SubscriptionManager sub = SubscriptionManager.from(context);
7377
7378 // Figure out what subscribers are currently active
7379 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380
Jordan Liub49b04b2019-05-06 14:45:15 -07007381 // Only consider subs which match the current subId
7382 // This logic can be simplified. See b/131189269 for progress.
7383 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007384 activeSubscriberIds.add(tele.getSubscriberId(subId));
7385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386
7387 // First pass, find a number override for an active subscriber
7388 String mergeNumber = null;
7389 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7390 for (String key : prefs.keySet()) {
7391 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7392 final String subscriberId = (String) prefs.get(key);
7393 if (activeSubscriberIds.contains(subscriberId)) {
7394 final String iccId = key.substring(
7395 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7396 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7397 mergeNumber = (String) prefs.get(numberKey);
7398 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007399 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 + " for active subscriber " + subscriberId);
7401 }
7402 if (!TextUtils.isEmpty(mergeNumber)) {
7403 break;
7404 }
7405 }
7406 }
7407 }
7408
7409 // Shortcut when no active merged subscribers
7410 if (TextUtils.isEmpty(mergeNumber)) {
7411 return null;
7412 }
7413
7414 // Second pass, find all subscribers under that line override
7415 final ArraySet<String> result = new ArraySet<>();
7416 for (String key : prefs.keySet()) {
7417 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7418 final String number = (String) prefs.get(key);
7419 if (mergeNumber.equals(number)) {
7420 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7421 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7422 final String subscriberId = (String) prefs.get(subscriberKey);
7423 if (!TextUtils.isEmpty(subscriberId)) {
7424 result.add(subscriberId);
7425 }
7426 }
7427 }
7428 }
7429
7430 final String[] resultArray = result.toArray(new String[result.size()]);
7431 Arrays.sort(resultArray);
7432 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007433 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7435 }
7436 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007439 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007440 }
7441
7442 @Override
zoey chen38003472019-12-13 17:16:31 +08007443 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7444 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007445
7446 final long identity = Binder.clearCallingIdentity();
7447 try {
7448 final TelephonyManager telephonyManager = mApp.getSystemService(
7449 TelephonyManager.class);
7450 String subscriberId = telephonyManager.getSubscriberId(subId);
7451 if (subscriberId == null) {
7452 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007453 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007454 + subId);
7455 }
7456 return null;
7457 }
7458
Jack Yu3beaf9d2023-04-14 09:17:27 -07007459 final SubscriptionInfo info = getSubscriptionManagerService()
7460 .getSubscriptionInfo(subId);
7461 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007462 // If it doesn't belong to any group, return just subscriberId of itself.
7463 if (groupUuid == null) {
7464 return new String[]{subscriberId};
7465 }
7466
7467 // Get all subscriberIds from the group.
7468 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007469 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7470 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7471 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007472 for (SubscriptionInfo subInfo : groupInfos) {
7473 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7474 if (subscriberId != null) {
7475 mergedSubscriberIds.add(subscriberId);
7476 }
7477 }
7478
7479 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482
7483 }
7484 }
7485
7486 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007487 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007488 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007489 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 final Phone phone = getPhone(subId);
7494 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007498 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007499
7500 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007501 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007502 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7503 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007504 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7505 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 final Phone phone = getPhone(subId);
7510 if (phone == null) {
7511 return false;
7512 }
7513 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7514 cdmaNonRoamingList);
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007517 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007518 }
7519
7520 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007521 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007522 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007523 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007524 if (phone == null) {
7525 return raf;
7526 }
7527
Shuo Qiandee53402020-05-29 14:08:15 -07007528 try {
7529 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007530 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007531 mApp, phone.getSubId(), "getRadioAccessFamily");
7532 } catch (SecurityException e) {
7533 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7534 throw e;
7535 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 final long identity = Binder.clearCallingIdentity();
7538 try {
chen xub97461a2018-10-26 14:17:57 -07007539 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
chen xub97461a2018-10-26 14:17:57 -07007543 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007544 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007545
7546 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007547 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007548 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007549 try {
7550 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7551 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007552 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007553 }
7554 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007555 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007556 }
7557 RoleManager rm = mApp.getSystemService(RoleManager.class);
7558 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7559 if (!dialerRoleHolders.contains(callingPackage)) {
7560 throw new SecurityException("App must be the dialer role holder to"
7561 + " upload a call composer pic");
7562 }
7563
7564 Executors.newSingleThreadExecutor().execute(() -> {
7565 ByteArrayOutputStream output = new ByteArrayOutputStream(
7566 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7567 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7568 boolean readUntilEnd = false;
7569 int totalBytesRead = 0;
7570 byte[] buffer = new byte[16 * 1024];
7571 while (true) {
7572 int numRead;
7573 try {
7574 numRead = input.read(buffer);
7575 } catch (IOException e) {
7576 try {
7577 fd.checkError();
7578 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7579 null);
7580 } catch (IOException e1) {
7581 // This means that the other side closed explicitly with an error. If this
7582 // happens, log and ignore.
7583 loge("Remote end of call composer picture pipe closed: " + e1);
7584 }
7585 break;
7586 }
7587 if (numRead == -1) {
7588 readUntilEnd = true;
7589 break;
7590 }
7591 totalBytesRead += numRead;
7592 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7593 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7594 try {
7595 input.close();
7596 } catch (IOException e) {
7597 // ignore
7598 }
7599 break;
7600 }
7601 output.write(buffer, 0, numRead);
7602 }
7603 // Generally, the remote end will close the file descriptors. The only case where we
7604 // close is above, where the picture size is too big.
7605
7606 try {
7607 fd.checkError();
7608 } catch (IOException e) {
7609 loge("Remote end for call composer closed with an error: " + e);
7610 return;
7611 }
7612
Hall Liuaa4211e2021-01-20 15:43:39 -08007613 if (!readUntilEnd) {
7614 loge("Did not finish reading entire image; aborting");
7615 return;
7616 }
Hall Liu82694d52020-12-11 18:22:04 -08007617
Hall Liuaa4211e2021-01-20 15:43:39 -08007618 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7619 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7620 new CallComposerPictureTransfer.Factory() {},
7621 imageData,
7622 (result) -> {
7623 if (result.first != null) {
7624 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7625 Bundle outputResult = new Bundle();
7626 outputResult.putParcelable(
7627 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7628 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7629 outputResult);
7630 } else {
7631 callback.send(result.second, null);
7632 }
7633 }
7634 );
Hall Liu82694d52020-12-11 18:22:04 -08007635 });
7636 }
7637
7638 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007639 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007641 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642
7643 final long identity = Binder.clearCallingIdentity();
7644 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007645 ImsManager.getInstance(defaultPhone.getContext(),
7646 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647 } finally {
7648 Binder.restoreCallingIdentity(identity);
7649 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007650 }
7651
7652 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007653 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007654 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007655 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7656 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007657 return false;
7658 }
Svet Ganovb320e182015-04-16 12:30:10 -07007659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 // Check the user preference and the system-level IMS setting. Even if the user has
7663 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7664 // In the long run, we may instead need to check if there exists a connection service
7665 // which can support video calling.
7666 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007667 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668 return imsManager.isVtEnabledByPlatform()
7669 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7670 && imsManager.isVtEnabledByUser();
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007674 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007675
Andrew Leea1239f22015-03-02 17:44:07 -08007676 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007677 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7678 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007680 mApp, subId, callingPackage, callingFeatureId,
7681 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 return false;
7683 }
7684
7685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 CarrierConfigManager configManager =
7688 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007689 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
Andrew Leea1239f22015-03-02 17:44:07 -08007694 }
7695
7696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007699 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 return false;
7701 }
7702
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
7705 CarrierConfigManager configManager =
7706 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007707 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
7711 }
Andrew Leea1239f22015-03-02 17:44:07 -08007712 }
7713
Andrew Lee9431b832015-03-09 18:46:45 -07007714 @Override
7715 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007716 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007717 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007718 }
7719
7720 @Override
7721 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 final long identity = Binder.clearCallingIdentity();
7723 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007724 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 } finally {
7726 Binder.restoreCallingIdentity(identity);
7727 }
Andrew Lee9431b832015-03-09 18:46:45 -07007728 }
7729
Hall Liuf6668912018-10-31 17:05:23 -07007730 /**
7731 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7732 * support for the feature and device firmware support.
7733 *
7734 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7735 */
7736 @Override
7737 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 final Phone phone = getPhone(subscriptionId);
7740 if (phone == null) {
7741 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7742 return false;
7743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007745 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7747 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007748 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 return isCarrierSupported && isDeviceSupported;
7750 } finally {
7751 Binder.restoreCallingIdentity(identity);
7752 }
Hall Liu98187582018-01-22 19:15:32 -08007753 }
7754
Hall Liuf6668912018-10-31 17:05:23 -07007755 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007756 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7757 * RTT setting, will return true if the device and carrier both support RTT.
7758 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007759 */
7760 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 final long identity = Binder.clearCallingIdentity();
7762 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007763 boolean isRttSupported = isRttSupported(subscriptionId);
7764 boolean isUserRttSettingOn = Settings.Secure.getInt(
7765 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7766 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7767 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7768 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 } finally {
7770 Binder.restoreCallingIdentity(identity);
7771 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007772 }
7773
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007774 @Deprecated
7775 @Override
7776 public String getDeviceId(String callingPackage) {
7777 return getDeviceIdWithFeature(callingPackage, null);
7778 }
7779
Sanket Padawe7310cc72015-01-14 09:53:20 -08007780 /**
7781 * Returns the unique device ID of phone, for example, the IMEI for
7782 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7783 *
7784 * <p>Requires Permission:
7785 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7786 */
7787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007788 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007789 try {
7790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7791 } catch (SecurityException se) {
7792 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7793 throw new SecurityException("Package " + callingPackage + " does not belong to "
7794 + Binder.getCallingUid());
7795 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007796 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007797 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007798 return null;
7799 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007800 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007801 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007802 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007803 return null;
7804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805
7806 final long identity = Binder.clearCallingIdentity();
7807 try {
7808 return phone.getDeviceId();
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007812 }
7813
Ping Sunc67b7c22016-03-02 19:16:45 +08007814 /**
7815 * {@hide}
7816 * Returns the IMS Registration Status on a particular subid
7817 *
7818 * @param subId
7819 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007820 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007821 Phone phone = getPhone(subId);
7822 if (phone != null) {
7823 return phone.isImsRegistered();
7824 } else {
7825 return false;
7826 }
7827 }
7828
Santos Cordon7a1885b2015-02-03 11:15:19 -08007829 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007830 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007831 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007833 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007834 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7835 }
7836 final long identity = Binder.clearCallingIdentity();
7837 try {
7838 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7839 } finally {
7840 Binder.restoreCallingIdentity(identity);
7841 }
7842 }
7843
7844 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007845 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007846 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007847 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007848 mApp,
7849 subscriptionId,
7850 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7851 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007852 final long identity = Binder.clearCallingIdentity();
7853 try {
7854 Phone phone = getPhone(subscriptionId);
7855 if (phone == null) {
7856 return null;
7857 }
7858 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7859 } finally {
7860 Binder.restoreCallingIdentity(identity);
7861 }
7862 }
7863
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007864 /**
7865 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007866 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007867 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 Phone phone = getPhone(subId);
7871 if (phone != null) {
7872 return phone.isWifiCallingEnabled();
7873 } else {
7874 return false;
7875 }
7876 } finally {
7877 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007878 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007879 }
7880
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007881 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007882 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007883 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007884 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 final long identity = Binder.clearCallingIdentity();
7886 try {
7887 Phone phone = getPhone(subId);
7888 if (phone != null) {
7889 return phone.isVideoEnabled();
7890 } else {
7891 return false;
7892 }
7893 } finally {
7894 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007895 }
7896 }
7897
7898 /**
7899 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7900 * defined in {@link ImsRegistrationImplBase}.
7901 */
7902 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 final long identity = Binder.clearCallingIdentity();
7904 try {
7905 Phone phone = getPhone(subId);
7906 if (phone != null) {
7907 return phone.getImsRegistrationTech();
7908 } else {
7909 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7910 }
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007913 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007914 }
7915
Stuart Scott8eef64f2015-04-08 15:13:54 -07007916 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007917 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007918 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007919 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7920 return;
7921 }
Kai Shif70f46f2021-03-03 13:59:46 -08007922 Phone defaultPhone = getDefaultPhone();
7923 if (defaultPhone != null) {
7924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7925 mApp, getDefaultPhone().getSubId(), "factoryReset");
7926 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007927 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007928
Svet Ganovcc087f82015-05-12 20:35:54 -07007929 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007930 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7931 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007932 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007933 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007934 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007935 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007936 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007937 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007938 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007939 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007940 // There has been issues when Sms raw table somehow stores orphan
7941 // fragments. They lead to garbled message when new fragments come
7942 // in and combined with those stale ones. In case this happens again,
7943 // user can reset all network settings which will clean up this table.
7944 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007945 // Clean up IMS settings as well here.
7946 int slotId = getSlotIndex(subId);
7947 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7948 ImsManager.getInstance(mApp, slotId).factoryReset();
7949 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007950
Kai Shif70f46f2021-03-03 13:59:46 -08007951 if (defaultPhone == null) {
7952 return;
7953 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007954 // Erase modem config if erase modem on network setting is enabled.
7955 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7956 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7957 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007958 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007959 }
Kai Shif70f46f2021-03-03 13:59:46 -08007960
7961 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007962 } finally {
7963 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007964 }
7965 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007966
SongFerngWangfd89b102021-05-27 22:44:54 +08007967 @VisibleForTesting
7968 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7969 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7970 return;
7971 }
7972 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7973 RILConstants.PREFERRED_NETWORK_MODE);
7974 SubscriptionManager.setSubscriptionProperty(subId,
7975 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7976 "user=" + defaultNetworkType);
7977 phone.loadAllowedNetworksFromSubscriptionDatabase();
7978 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7979 defaultNetworkType, null);
7980 }
7981
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007982 private void cleanUpSmsRawTable(Context context) {
7983 ContentResolver resolver = context.getContentResolver();
7984 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7985 resolver.delete(uri, null, null);
7986 }
7987
Narayan Kamath1c496c22015-04-16 14:40:19 +01007988 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007989 public String getSimLocaleForSubscriber(int subId) {
7990 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7991 final Phone phone = getPhone(subId);
7992 if (phone == null) {
7993 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007994 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 final long identity = Binder.clearCallingIdentity();
7997 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007998 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7999 phone.getContext().getOpPackageName(),
8000 phone.getContext().getAttributionTag());
8001 if (info == null) {
8002 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8003 return null;
chen xu6291c472019-02-04 12:55:53 -08008004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 // Try and fetch the locale from the carrier properties or from the SIM language
8006 // preferences (EF-PL and EF-LI)...
8007 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008009 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8010 if (localeFromDefaultSim != null) {
8011 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8012 if (DBG) log("Using locale from subId: " + subId + " locale: "
8013 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008014 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008015 } else {
8016 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 }
8018 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 // The SIM language preferences only store a language (e.g. fr = French), not an
8021 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8022 // the SIM and carrier preferences does not include a country we add the country
8023 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008024 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008026 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008027 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028 }
8029
8030 if (DBG) log("No locale found - returning null");
8031 return null;
8032 } finally {
8033 Binder.restoreCallingIdentity(identity);
8034 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008035 }
8036
tom hsu0b59d292022-09-29 23:49:21 +08008037 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008038 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008039 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008040 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008041 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008042 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8043 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008044 Locale.forLanguageTag(localeTag).getCountry())) {
8045 return localeTag;
8046 }
8047 }
8048 return inputLocale.toLanguageTag();
8049 }
8050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 /**
8052 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8053 */
8054 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008055 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008056 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008057 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008058
Gary Jian3aa9a762022-01-24 16:41:19 +08008059 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8060 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008061
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008062 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008063 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8064 * representing the state of the modem.
8065 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008066 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8067 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008068 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008069 */
8070 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008071 public void requestModemActivityInfo(ResultReceiver result) {
8072 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074
8075 final long identity = Binder.clearCallingIdentity();
8076 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008077 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 } finally {
8079 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008080 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008081 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008082
Gary Jian76280a42022-12-07 16:18:33 +08008083 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008084 // less than total activity duration.
8085 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8086 if (info == null) {
8087 return false;
8088 }
8089 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008090 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008091 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8092
Hall Liu49656c02020-10-09 19:00:11 -07008093 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8094
Siddharth Rayb8114062018-06-17 15:02:38 -07008095 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008096 && (info.getSleepTimeMillis() <= activityDurationMs)
8097 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008098 }
8099
Gary Jian3aa9a762022-01-24 16:41:19 +08008100 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8101 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8102 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8103 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8104
8105 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8106 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8107 }
8108
8109 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8110 mLastModemActivityInfo.setReceiveTimeMillis(
8111 rat,
8112 freq,
8113 info.getReceiveTimeMillis(rat, freq)
8114 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8115 }
8116
8117 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8118 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8119 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8120 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8121
8122 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8123 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8124 }
8125 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8126 mLastModemActivityInfo.setReceiveTimeMillis(
8127 rat,
8128 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8129 }
8130
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008131 /**
8132 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8133 * @param info recent ModemActivityInfo
8134 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008135 private void mergeModemActivityInfo(ModemActivityInfo info) {
8136 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008137 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008138 boolean matched;
8139 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8140 matched = false;
8141 int rat = info.getSpecificInfoRat(i);
8142 int freq = info.getSpecificInfoFrequencyRange(i);
8143 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8144 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8145 //if it already exists
8146 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8147 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8148 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8149 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8150 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8151 updateLastModemActivityInfo(info, rat, freq);
8152 matched = true;
8153 }
8154 } else {
8155 updateLastModemActivityInfo(info, rat);
8156 matched = true;
8157 }
8158 }
8159 }
8160
8161 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008162 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008163 new ActivityStatsTechSpecificInfo(
8164 rat,
8165 freq,
8166 info.getTransmitTimeMillis(rat, freq),
8167 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008168 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008169 }
8170 }
8171 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8172 mLastModemActivitySpecificInfo =
8173 new ActivityStatsTechSpecificInfo[merged.size()];
8174 merged.toArray(mLastModemActivitySpecificInfo);
8175
8176 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8177 mLastModemActivityInfo.setSleepTimeMillis(
8178 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008179 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008180 mLastModemActivityInfo.setIdleTimeMillis(
8181 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008182 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008183
8184 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008185 new ModemActivityInfo(
8186 mLastModemActivityInfo.getTimestampMillis(),
8187 mLastModemActivityInfo.getSleepTimeMillis(),
8188 mLastModemActivityInfo.getIdleTimeMillis(),
8189 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008190 }
8191
8192 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8193 ActivityStatsTechSpecificInfo[] info) {
8194 int infoSize = info.length;
8195 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8196 for (int i = 0; i < infoSize; i++) {
8197 ret[i] = new ActivityStatsTechSpecificInfo(
8198 info[i].getRat(), info[i].getFrequencyRange(),
8199 info[i].getTransmitTimeMillis(),
8200 (int) info[i].getReceiveTimeMillis());
8201 }
8202 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008203 }
8204
Jack Yu85bd38a2015-11-09 11:34:32 -08008205 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008206 * Returns the service state information on specified subscription.
8207 */
8208 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008209 public ServiceState getServiceStateForSubscriber(int subId,
8210 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8211 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008213 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008214 return null;
8215 }
8216
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008217 boolean hasFinePermission = false;
8218 boolean hasCoarsePermission = false;
8219 if (!renounceFineLocationAccess) {
8220 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8221 LocationAccessPolicy.checkLocationPermission(mApp,
8222 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8223 .setCallingPackage(callingPackage)
8224 .setCallingFeatureId(callingFeatureId)
8225 .setCallingPid(Binder.getCallingPid())
8226 .setCallingUid(Binder.getCallingUid())
8227 .setMethod("getServiceStateForSubscriber")
8228 .setLogAsInfo(true)
8229 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8230 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8231 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8232 .build());
8233 hasFinePermission =
8234 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8235 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008236
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008237 if (!renounceCoarseLocationAccess) {
8238 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8239 LocationAccessPolicy.checkLocationPermission(mApp,
8240 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8241 .setCallingPackage(callingPackage)
8242 .setCallingFeatureId(callingFeatureId)
8243 .setCallingPid(Binder.getCallingPid())
8244 .setCallingUid(Binder.getCallingUid())
8245 .setMethod("getServiceStateForSubscriber")
8246 .setLogAsInfo(true)
8247 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8248 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8249 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8250 .build());
8251 hasCoarsePermission =
8252 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8253 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008254
Jack Yu479f40e2020-10-27 21:29:25 -07008255 final Phone phone = getPhone(subId);
8256 if (phone == null) {
8257 return null;
8258 }
8259
Jordan Liu0f2bc442020-11-18 16:47:37 -08008260 final long identity = Binder.clearCallingIdentity();
8261
Jack Yu479f40e2020-10-27 21:29:25 -07008262 boolean isCallingPackageDataService = phone.getDataServicePackages()
8263 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008265 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008266 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8267 .getSubscriptionInfoInternal(subId);
8268 if (subInfo == null || !subInfo.isActive()) {
8269 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8270 + "subId=" + subId);
8271 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008272 }
8273
Hall Liuf19c44f2018-11-27 14:38:17 -08008274 ServiceState ss = phone.getServiceState();
8275
8276 // Scrub out the location info in ServiceState depending on what level of access
8277 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008278 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008279 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8280 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008284 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008285
8286 /**
8287 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8288 *
8289 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8290 * voicemail ringtone.
8291 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8292 * PhoneAccount.
8293 */
8294 @Override
8295 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 final long identity = Binder.clearCallingIdentity();
8297 try {
8298 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8299 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008300 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008307 }
8308
8309 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008310 * Sets the per-account voicemail ringtone.
8311 *
8312 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8313 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8314 *
8315 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8316 * voicemail ringtone.
8317 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8318 * PhoneAccount.
8319 */
8320 @Override
8321 public void setVoicemailRingtoneUri(String callingPackage,
8322 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008323 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008325 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8326 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8328 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8329 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331
8332 final long identity = Binder.clearCallingIdentity();
8333 try {
8334 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8335 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008336 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 }
8338 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008341 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008342 }
8343
8344 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008345 * Returns whether vibration is set for voicemail notification in Phone settings.
8346 *
8347 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8348 * voicemail vibration setting.
8349 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8350 */
8351 @Override
8352 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353 final long identity = Binder.clearCallingIdentity();
8354 try {
8355 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8356 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008357 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008364 }
8365
Youhan Wange64578a2016-05-02 15:32:42 -07008366 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008367 * Sets the per-account voicemail vibration.
8368 *
8369 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8370 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8371 *
8372 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8373 * voicemail vibration setting.
8374 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8375 * specific PhoneAccount.
8376 */
8377 @Override
8378 public void setVoicemailVibrationEnabled(String callingPackage,
8379 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008380 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008382 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8383 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8385 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8386 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008387 }
8388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8392 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008393 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 }
8395 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008398 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008399 }
8400
8401 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008402 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8403 *
8404 * @throws SecurityException if the caller does not have the required permission
8405 */
arunvoddud7401012022-12-15 16:08:12 +00008406 @VisibleForTesting
8407 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008408 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008409 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008410 }
8411
8412 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008413 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8414 * permission.
8415 *
8416 * @throws SecurityException if the caller does not have the required permission
8417 */
8418 private void enforceSendSmsPermission() {
8419 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8420 }
8421
8422 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008423 * Make sure either called from same process as self (phone) or IPC caller has interact across
8424 * users permission.
8425 *
8426 * @throws SecurityException if the caller does not have the required permission
8427 */
8428 private void enforceInteractAcrossUsersPermission(String message) {
8429 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8430 }
8431
8432 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008433 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008434 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008435 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008436 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008437 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442 if (componentName == null) {
8443 throw new SecurityException(
8444 "Caller not current active visual voicemail package[null]");
8445 }
8446 String vvmPackage = componentName.getPackageName();
8447 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008448 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449 }
8450 } finally {
8451 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008452 }
8453 }
8454
8455 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008456 * Return the application ID for the app type.
8457 *
8458 * @param subId the subscription ID that this request applies to.
8459 * @param appType the uicc app type.
8460 * @return Application ID for specificied app type, or null if no uicc.
8461 */
8462 @Override
8463 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008464 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008465 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466
8467 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008468 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 if (phone == null) {
8470 return null;
8471 }
8472 String aid = null;
8473 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008474 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008475 .getApplicationByType(appType).getAid();
8476 } catch (Exception e) {
8477 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8478 }
8479 return aid;
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008482 }
Youhan Wange64578a2016-05-02 15:32:42 -07008483 }
8484
Youhan Wang4001d252016-05-11 10:29:41 -07008485 /**
8486 * Return the Electronic Serial Number.
8487 *
8488 * @param subId the subscription ID that this request applies to.
8489 * @return ESN or null if error.
8490 */
8491 @Override
8492 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008493 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008494 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495
8496 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008497 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008498 if (phone == null) {
8499 return null;
8500 }
8501 String esn = null;
8502 try {
8503 esn = phone.getEsn();
8504 } catch (Exception e) {
8505 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8506 }
8507 return esn;
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008510 }
Youhan Wang4001d252016-05-11 10:29:41 -07008511 }
8512
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008513 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008514 * Return the Preferred Roaming List Version.
8515 *
8516 * @param subId the subscription ID that this request applies to.
8517 * @return PRLVersion or null if error.
8518 */
8519 @Override
8520 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008521 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008522 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523
8524 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008525 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 if (phone == null) {
8527 return null;
8528 }
8529 String cdmaPrlVersion = null;
8530 try {
8531 cdmaPrlVersion = phone.getCdmaPrlVersion();
8532 } catch (Exception e) {
8533 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8534 }
8535 return cdmaPrlVersion;
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008538 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008539 }
8540
8541 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008542 * Get snapshot of Telephony histograms
8543 * @return List of Telephony histograms
8544 * @hide
8545 */
8546 @Override
8547 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8549 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 return RIL.getTelephonyRILTimingHistograms();
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008557 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008558
8559 /**
8560 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008561 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8562 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008563 * Require system privileges. In the future we may add this to carrier APIs.
8564 *
Michele Berionne482f8202018-11-27 18:57:59 -08008565 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008566 */
8567 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008568 @TelephonyManager.SetCarrierRestrictionResult
8569 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008570 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008571 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008572
Michele Berionne482f8202018-11-27 18:57:59 -08008573 if (carrierRestrictionRules == null) {
8574 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008575 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577 final long identity = Binder.clearCallingIdentity();
8578 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008579 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008580 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008584 }
8585
8586 /**
8587 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008588 * Get the allowed carrier list and the excluded carrier list, including the priority between
8589 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008590 * Require system privileges. In the future we may add this to carrier APIs.
8591 *
Michele Berionne482f8202018-11-27 18:57:59 -08008592 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008593 */
8594 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008595 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008596 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008597 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598
8599 final long identity = Binder.clearCallingIdentity();
8600 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008601 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8602 if (response instanceof CarrierRestrictionRules) {
8603 return (CarrierRestrictionRules) response;
8604 }
8605 // Response is an Exception of some kind,
8606 // which is signalled to the user as a NULL retval
8607 return null;
8608 } catch (Exception e) {
8609 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8610 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008614 }
8615
fionaxu59545b42016-05-25 15:53:37 -07008616 /**
arunvoddud7401012022-12-15 16:08:12 +00008617 * Fetches the carrier restriction status of the device and sends the status to the caller
8618 * through the callback.
8619 *
8620 * @param callback The callback that will be used to send the result.
8621 * @throws SecurityException if the caller does not have the required permission/privileges or
8622 * the caller is not allowlisted.
8623 */
8624 @Override
8625 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8626 enforceReadPermission("getCarrierRestrictionStatus");
8627 int carrierId = validateCallerAndGetCarrierId(packageName);
8628 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8629 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8630 throw new SecurityException("Not an authorized caller");
8631 }
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8635 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8636 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
8640 }
8641
arunvoddu567f2b42023-04-25 17:22:00 +00008642 @Override
8643 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8644 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8645 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8646 return allowListInfo.getShaIdList(pkgName, carrierId);
8647 }
8648
arunvoddud7401012022-12-15 16:08:12 +00008649 @VisibleForTesting
8650 public int validateCallerAndGetCarrierId(String packageName) {
8651 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8652 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8653 }
8654
8655 /**
fionaxu59545b42016-05-25 15:53:37 -07008656 * Action set from carrier signalling broadcast receivers to enable/disable radio
8657 * @param subId the subscription ID that this action applies to.
8658 * @param enabled control enable or disable radio.
8659 * {@hide}
8660 */
8661 @Override
8662 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8663 enforceModifyPermission();
8664 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008665
8666 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008667 if (phone == null) {
8668 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8669 return;
8670 }
8671 try {
8672 phone.carrierActionSetRadioEnabled(enabled);
8673 } catch (Exception e) {
8674 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675 } finally {
8676 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008677 }
8678 }
8679
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008680 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008681 * Enable or disable Voice over NR (VoNR)
8682 * @param subId the subscription ID that this action applies to.
8683 * @param enabled enable or disable VoNR.
8684 * @return operation result.
8685 */
8686 @Override
8687 public int setVoNrEnabled(int subId, boolean enabled) {
8688 enforceModifyPermission();
8689 final Phone phone = getPhone(subId);
8690
8691 final long identity = Binder.clearCallingIdentity();
8692 if (phone == null) {
8693 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8694 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8695 }
8696
8697 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8698 try {
8699 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8700 workSource);
8701 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008702
8703 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8704 if (DBG) {
8705 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8706 }
8707 SubscriptionManager.setSubscriptionProperty(
8708 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8709 (enabled ? "1" : "0"));
8710 }
8711
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008712 return result;
8713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 }
8717
8718 /**
8719 * Is voice over NR enabled
8720 * @return true if VoNR is enabled else false
8721 */
8722 @Override
8723 public boolean isVoNrEnabled(int subId) {
8724 enforceReadPrivilegedPermission("isVoNrEnabled");
8725 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
8728 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8729 null, subId, workSource);
8730 if (DBG) log("isVoNrEnabled: " + isEnabled);
8731 return isEnabled;
8732 } finally {
8733 Binder.restoreCallingIdentity(identity);
8734 }
8735 }
8736
8737 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008738 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8739 * network status based on which carrier apps could apply actions accordingly,
8740 * enable/disable default url handler for example.
8741 *
8742 * @param subId the subscription ID that this action applies to.
8743 * @param report control start/stop reporting the default network status.
8744 * {@hide}
8745 */
8746 @Override
8747 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8748 enforceModifyPermission();
8749 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750
8751 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008752 if (phone == null) {
8753 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8754 return;
8755 }
8756 try {
8757 phone.carrierActionReportDefaultNetworkStatus(report);
8758 } catch (Exception e) {
8759 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008760 } finally {
8761 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008762 }
8763 }
8764
8765 /**
fionaxud9622282017-07-17 17:51:30 -07008766 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8767 * @param subId the subscription ID that this action applies to.
8768 * {@hide}
8769 */
8770 @Override
8771 public void carrierActionResetAll(int subId) {
8772 enforceModifyPermission();
8773 final Phone phone = getPhone(subId);
8774 if (phone == null) {
8775 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8776 return;
8777 }
8778 try {
8779 phone.carrierActionResetAll();
8780 } catch (Exception e) {
8781 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8782 }
8783 }
8784
8785 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008786 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8787 * bug report is being generated.
8788 */
8789 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008790 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008791 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8792 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008793 writer.println("Permission Denial: can't dump Phone from pid="
8794 + Binder.getCallingPid()
8795 + ", uid=" + Binder.getCallingUid()
8796 + "without permission "
8797 + android.Manifest.permission.DUMP);
8798 return;
8799 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008800 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008801 }
Jack Yueb89b242016-06-22 13:27:47 -07008802
Brad Ebingerdac2f002018-04-03 15:17:52 -07008803 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008804 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8805 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8806 @NonNull String[] args) {
8807 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8808 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008809 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008810 }
8811
Jack Yueb89b242016-06-22 13:27:47 -07008812 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008813 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008814 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008815 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008816 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008817 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008818 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008819 */
8820 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008821 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008822 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008823 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8824 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8825 try {
8826 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008827 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008828 } catch (SecurityException se) {
8829 enforceModifyPermission();
8830 }
8831 } else {
8832 enforceModifyPermission();
8833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008834
Nate Myrenae97d192023-06-09 15:22:31 -07008835 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
8836 && null != callingPackage && opEnableMobileDataByUser()) {
8837 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
8838 callingPackage, null, null);
8839 }
8840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008841 final long identity = Binder.clearCallingIdentity();
8842 try {
8843 Phone phone = getPhone(subId);
8844 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008845 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8846 phone.carrierActionSetMeteredApnsEnabled(enabled);
8847 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008848 phone.getDataSettingsManager().setDataEnabled(
8849 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008851 }
8852 } finally {
8853 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008854 }
8855 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008856
8857 /**
8858 * Get Client request stats
8859 * @return List of Client Request Stats
8860 * @hide
8861 */
8862 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008863 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8864 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008866 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008867 return null;
8868 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008869 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008871 final long identity = Binder.clearCallingIdentity();
8872 try {
8873 if (phone != null) {
8874 return phone.getClientRequestStats();
8875 }
8876
8877 return null;
8878 } finally {
8879 Binder.restoreCallingIdentity(identity);
8880 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008881 }
8882
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008883 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008884 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008885 if (uid == Process.ROOT_UID && packageName == null) {
8886 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8887 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8888 // exception. ROOT_UID seems not to have a valid package name returned by
8889 // PackageManager, so just fake it here to avoid issues when running telephony shell
8890 // commands that plumb through the RIL as root, like so:
8891 // $ adb root
8892 // $ adb shell cmd phone ...
8893 packageName = "root";
8894 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008895 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008896 }
Jack Yueb4124c2017-02-16 15:32:43 -08008897
8898 /**
Grace Chen70990072017-03-24 17:21:30 -07008899 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008900 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008901 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008902 * @param state State of SIM (power down, power up, pass through)
8903 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8904 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8905 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008906 *
8907 **/
8908 @Override
Grace Chen70990072017-03-24 17:21:30 -07008909 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008910 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008911 Phone phone = PhoneFactory.getPhone(slotIndex);
8912
vagdeviaf9a5b92018-08-15 16:01:53 -07008913 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 final long identity = Binder.clearCallingIdentity();
8916 try {
8917 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008918 phone.setSimPowerState(state, null, workSource);
8919 }
8920 } finally {
8921 Binder.restoreCallingIdentity(identity);
8922 }
8923 }
8924
8925 /**
8926 * Set SIM card power state.
8927 *
8928 * @param slotIndex SIM slot id.
8929 * @param state State of SIM (power down, power up, pass through)
8930 * @param callback callback to trigger after success or failure
8931 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8932 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8933 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8934 *
8935 **/
8936 @Override
8937 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8938 IIntegerConsumer callback) {
8939 enforceModifyPermission();
8940 Phone phone = PhoneFactory.getPhone(slotIndex);
8941
8942 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8943
8944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 if (phone != null) {
8947 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8948 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949 }
8950 } finally {
8951 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008952 }
8953 }
Shuo Qiandd210312017-04-12 22:11:33 +00008954
Tyler Gunn65d45c22017-06-05 11:22:26 -07008955 private boolean isUssdApiAllowed(int subId) {
8956 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008957 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008958 if (configManager == null) {
8959 return false;
8960 }
8961 PersistableBundle pb = configManager.getConfigForSubId(subId);
8962 if (pb == null) {
8963 return false;
8964 }
8965 return pb.getBoolean(
8966 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8967 }
8968
Shuo Qiandd210312017-04-12 22:11:33 +00008969 /**
Ling Mac28f0212023-03-24 16:07:15 -07008970 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008971 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008972 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008973 */
goneil9c5f4872017-12-05 14:07:56 -08008974 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008975 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008976 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 final long identity = Binder.clearCallingIdentity();
8978 try {
Ling Mac28f0212023-03-24 16:07:15 -07008979 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 } finally {
8981 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008982 }
8983 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008984
8985 /**
8986 * Get the current signal strength information for the given subscription.
8987 * Because this information is not updated when the device is in a low power state
8988 * it should not be relied-upon to be current.
8989 * @param subId Subscription index
8990 * @return the most recent cached signal strength info from the modem
8991 */
8992 @Override
8993 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 final long identity = Binder.clearCallingIdentity();
8995 try {
8996 Phone p = getPhone(subId);
8997 if (p == null) {
8998 return null;
8999 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009001 return p.getSignalStrength();
9002 } finally {
9003 Binder.restoreCallingIdentity(identity);
9004 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009006
Pengquan Meng77b7f132018-08-22 14:49:57 -07009007 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009008 * Get the current modem radio state for the given slot.
9009 * @param slotIndex slot index.
9010 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009011 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009012 * @return the current radio power state from the modem
9013 */
9014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009015 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009016 Phone phone = PhoneFactory.getPhone(slotIndex);
9017 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9019 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009020 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9021 }
9022
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 return phone.getRadioPowerState();
9026 } finally {
9027 Binder.restoreCallingIdentity(identity);
9028 }
9029 }
9030 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9031 }
9032
9033 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009034 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9035 *
9036 * <p>Requires one of the following permissions:
9037 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009038 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009039 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9040 * privileges.
9041 *
9042 * @param subId subscription id
9043 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9044 * {@code false}.
9045 */
9046 @Override
9047 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009048 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009049 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009050 try {
9051 mApp.enforceCallingOrSelfPermission(
9052 android.Manifest.permission.ACCESS_NETWORK_STATE,
9053 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009054 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009055 mApp.enforceCallingOrSelfPermission(
9056 permission.READ_BASIC_PHONE_STATE, functionName);
9057 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009058 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009059 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009060 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009061 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009062
Pengquan Menga1bb6272018-09-06 09:59:22 -07009063 boolean isEnabled = false;
9064 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009065 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009066 Phone phone = getPhone(subId);
9067 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009068 } finally {
9069 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009070 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009071 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009072 }
9073
9074
9075 /**
9076 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9077 *
9078 * <p> Requires permission:
9079 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9080 * privileges.
9081 *
9082 * @param subId subscription id
9083 * @param isEnabled {@code true} means enable, {@code false} means disable.
9084 */
9085 @Override
9086 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9088 mApp, subId, "setDataRoamingEnabled");
9089
Pengquan Menga1bb6272018-09-06 09:59:22 -07009090 final long identity = Binder.clearCallingIdentity();
9091 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009092 Phone phone = getPhone(subId);
9093 if (phone != null) {
9094 phone.setDataRoamingEnabled(isEnabled);
9095 }
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009098 }
9099 }
9100
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009101 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009102 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009103 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009104 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009105 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009106
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009107 boolean isAllowed = true;
9108 final long identity = Binder.clearCallingIdentity();
9109 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009110 Phone phone = getPhone(subId);
9111 if (phone != null) {
9112 isAllowed = phone.isCspPlmnEnabled();
9113 }
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 return isAllowed;
9118 }
9119
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009120 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9121 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009122 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009123 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009124 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009125 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9126 if (phone == null) {
9127 return false;
9128 }
9129 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9130 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9131 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009132 }
9133
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009134 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009135 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009136 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009137 mApp.getSystemService(AppOpsManager.class)
9138 .checkPackage(Binder.getCallingUid(), callingPackage);
9139
Jordan Liu1e142fc2019-04-22 15:10:43 -07009140 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009141 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009142 try {
9143 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009144 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009145 } catch (SecurityException e) {
9146 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9147 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009148 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009149 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009150 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009151 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009152 }
sandeepjsb6c87872021-09-27 15:34:44 +00009153 // checking compatibility, if calling app's target SDK is T and beyond.
9154 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9155 Binder.getCallingUid())) {
9156 isIccIdAccessRestricted = true;
9157 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009158 final long identity = Binder.clearCallingIdentity();
9159 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009160 UiccController uiccController = UiccController.getInstance();
9161 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009162 if (hasReadPermission) {
9163 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009164 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009165
9166 // Remove private info if the caller doesn't have access
9167 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9168 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009169 //setting the value after compatibility check
9170 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009171 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9172 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009173 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009174 if (card == null) {
9175 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009176 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009177 continue;
9178 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009179 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9180 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009181 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009182 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009183 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009184 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9185 for (UiccPortInfo portInfo : portInfos) {
9186 UiccPort port = uiccController.getUiccPortForSlot(
9187 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9188 if (port == null) {
9189 // assume no access if port is null
9190 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9191 continue;
9192 }
9193 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9194 uiccPortInfos.add(portInfo);
9195 } else {
9196 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9197 }
9198 }
9199 filteredInfos.add(new UiccCardInfo(
9200 cardInfo.isEuicc(),
9201 cardInfo.getCardId(),
9202 null,
9203 cardInfo.getPhysicalSlotIndex(),
9204 cardInfo.isRemovable(),
9205 cardInfo.isMultipleEnabledProfilesSupported(),
9206 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009207 }
9208 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009209 } finally {
9210 Binder.restoreCallingIdentity(identity);
9211 }
9212 }
9213
sandeepjsb6c87872021-09-27 15:34:44 +00009214 /**
9215 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9216 * generally private and require carrier privileges to view.
9217 *
9218 * @hide
9219 */
9220 @NonNull
9221 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9222 List<UiccPortInfo> portinfo = new ArrayList<>();
9223 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9224 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9225 }
9226 return new UiccCardInfo(
9227 cardInfo.isEuicc(),
9228 cardInfo.getCardId(),
9229 null,
9230 cardInfo.getPhysicalSlotIndex(),
9231 cardInfo.isRemovable(),
9232 cardInfo.isMultipleEnabledProfilesSupported(),
9233 portinfo
9234 );
9235 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009236
sandeepjsb6c87872021-09-27 15:34:44 +00009237 /**
9238 * @hide
9239 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9240 * These values are generally private and require carrier privileges to view.
9241 */
9242 @NonNull
9243 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9244 return new UiccPortInfo(
9245 UiccPortInfo.ICCID_REDACTED,
9246 portInfo.getPortIndex(),
9247 portInfo.getLogicalSlotIndex(),
9248 portInfo.isActive()
9249 );
9250 }
9251 @Override
9252 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009253 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009254 mApp.getSystemService(AppOpsManager.class)
9255 .checkPackage(Binder.getCallingUid(), callingPackage);
9256
sandeepjsb6c87872021-09-27 15:34:44 +00009257 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009258
Aman Guptaf3c90b32022-03-17 04:54:16 +00009259 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9260 // we are reading iccId which is PII data.
9261 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009262
9263 // checking compatibility, if calling app's target SDK is T and beyond.
9264 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9265 Binder.getCallingUid())) {
9266 isLogicalSlotAccessRestricted = true;
9267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009268 final long identity = Binder.clearCallingIdentity();
9269 try {
9270 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009271 if (slots == null || slots.length == 0) {
9272 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009273 return null;
9274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009275 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9276 for (int i = 0; i < slots.length; i++) {
9277 UiccSlot slot = slots[i];
9278 if (slot == null) {
9279 continue;
9280 }
9281
Jordan Liu7be7e652019-05-06 18:55:02 +00009282 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009283 UiccCard card = slot.getUiccCard();
9284 if (card != null) {
9285 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009286 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009287 cardId = slot.getEid();
9288 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009289 // If cardId is null, use iccId of default port as cardId.
9290 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009292 }
9293
Jordan Liu857451f2019-05-09 16:35:35 -07009294 if (cardId != null) {
9295 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9296 // if cardId is an EID, it's all digits so this is fine
9297 cardId = IccUtils.stripTrailingFs(cardId);
9298 }
9299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009300 int cardState = 0;
9301 switch (slot.getCardState()) {
9302 case CARDSTATE_ABSENT:
9303 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9304 break;
9305 case CARDSTATE_PRESENT:
9306 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9307 break;
9308 case CARDSTATE_ERROR:
9309 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9310 break;
9311 case CARDSTATE_RESTRICTED:
9312 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9313 break;
9314 default:
9315 break;
9316
9317 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009318 List<UiccPortInfo> portInfos = new ArrayList<>();
9319 int[] portIndexes = slot.getPortList();
9320 for (int portIdx : portIndexes) {
9321 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009322 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009323 portInfos.add(new UiccPortInfo(iccId, portIdx,
9324 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009326 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009327 slot.isEuicc(),
9328 cardId,
9329 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009330 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009331 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009332 //setting the value after compatibility check
9333 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009334 }
9335 return infos;
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009338 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009339 }
9340
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009341 /* Returns null if doesn't have read permission or carrier privilege access. */
9342 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9343 boolean hasReadPermission) {
9344 String iccId = slot.getIccId(portIndex);
9345 if (hasReadPermission) { // if has read permission
9346 return iccId;
9347 } else {
9348 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9349 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9350 // if no read permission, checking carrier privilege access
9351 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9352 return iccId;
9353 }
9354 }
9355 }
9356 // No read permission or carrier privilege access.
9357 return UiccPortInfo.ICCID_REDACTED;
9358 }
9359
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009360 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009361 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009362 public boolean switchSlots(int[] physicalSlots) {
9363 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009364
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009367 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9368 for (int i = 0; i < physicalSlots.length; i++) {
9369 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9370 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9371 physicalSlots[i], i));
9372 }
9373 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009377 }
Jack Yu4c988042018-02-27 15:30:01 -08009378
9379 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009380 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9381 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9382 enforceModifyPermission();
9383
9384 final long identity = Binder.clearCallingIdentity();
9385 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009386 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009387 } finally {
9388 Binder.restoreCallingIdentity(identity);
9389 }
9390 }
9391
9392 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009393 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009394 final long identity = Binder.clearCallingIdentity();
9395 try {
9396 return UiccController.getInstance().getCardIdForDefaultEuicc();
9397 } finally {
9398 Binder.restoreCallingIdentity(identity);
9399 }
9400 }
9401
Pengquan Meng85728fb2018-03-12 16:31:21 -07009402 /**
goneil47ffb6e2018-04-06 15:40:58 -07009403 * A test API to reload the UICC profile.
9404 *
9405 * <p>Requires that the calling app has permission
9406 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9407 * @hide
9408 */
9409 @Override
9410 public void refreshUiccProfile(int subId) {
9411 enforceModifyPermission();
9412
9413 final long identity = Binder.clearCallingIdentity();
9414 try {
9415 Phone phone = getPhone(subId);
9416 if (phone == null) {
9417 return;
9418 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009419 UiccPort uiccPort = phone.getUiccPort();
9420 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009421 return;
9422 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009423 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009424 if (uiccProfile == null) {
9425 return;
9426 }
9427 uiccProfile.refresh();
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
9432
9433 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009434 * Returns false if the mobile data is disabled by default, otherwise return true.
9435 */
9436 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009437 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009438 }
9439
9440 /**
9441 * Returns true if the data roaming is enabled by default, i.e the system property
9442 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9443 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9444 */
9445 private boolean getDefaultDataRoamingEnabled(int subId) {
9446 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009447 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009448 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009449 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9450 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9451 return isDataRoamingEnabled;
9452 }
9453
9454 /**
9455 * Returns the default network type for the given {@code subId}, if the default network type is
9456 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9457 */
9458 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009459 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009460 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009461 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9462 return list.get(phoneId);
9463 }
9464 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009465 }
fionaxua13278b2018-03-21 00:08:13 -07009466
9467 @Override
9468 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009469 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009471
9472 final long identity = Binder.clearCallingIdentity();
9473 try {
9474 final Phone phone = getPhone(subId);
9475 if (phone == null) {
9476 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9477 return;
9478 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009479 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9480 if (cpt != null) {
9481 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9482 }
9483 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009484 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9485 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009486 if (carrierPrivilegeRules == null) {
9487 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9488 } else {
9489 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009491 } finally {
9492 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009493 }
fionaxua13278b2018-03-21 00:08:13 -07009494 }
9495
9496 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009497 public void setCarrierServicePackageOverride(
9498 int subId, String carrierServicePackage, String callingPackage) {
9499 TelephonyPermissions.enforceShellOnly(
9500 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9501
Benedict Wong66477622023-02-03 23:30:57 +00009502 final long identity = Binder.clearCallingIdentity();
9503 try {
9504 final Phone phone = getPhone(subId);
9505 if (phone == null || phone.getSubId() != subId) {
9506 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9507 throw new IllegalArgumentException("No phone for subid");
9508 }
9509 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9510 if (cpt == null) {
9511 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9512 throw new IllegalStateException("No CPT for phone");
9513 }
9514 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9515 } finally {
9516 Binder.restoreCallingIdentity(identity);
9517 }
9518 }
9519
9520 @Override
fionaxua13278b2018-03-21 00:08:13 -07009521 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009522 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009523
9524 final long identity = Binder.clearCallingIdentity();
9525 try {
9526 final Phone phone = getPhone(subId);
9527 if (phone == null) {
9528 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9529 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9530 }
9531 return phone.getCarrierIdListVersion();
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009534 }
fionaxua13278b2018-03-21 00:08:13 -07009535 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009536
9537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009538 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9539 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009541 mApp, subId, callingPackage, callingFeatureId,
9542 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009543 return -1;
9544 }
9545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9549 } finally {
9550 Binder.restoreCallingIdentity(identity);
9551 }
9552 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009553
9554 @Override
9555 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009556 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009557 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009558 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009559
9560 final long identity = Binder.clearCallingIdentity();
9561 try {
9562 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
9567
9568 @Override
9569 public boolean setCdmaRoamingMode(int subId, int mode) {
9570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9571 mApp, subId, "setCdmaRoamingMode");
9572
9573 final long identity = Binder.clearCallingIdentity();
9574 try {
9575 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9576 } finally {
9577 Binder.restoreCallingIdentity(identity);
9578 }
9579 }
9580
9581 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009582 public int getCdmaSubscriptionMode(int subId) {
9583 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009584 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009585 mApp, subId, "getCdmaSubscriptionMode");
9586
9587 final long identity = Binder.clearCallingIdentity();
9588 try {
9589 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9590 } finally {
9591 Binder.restoreCallingIdentity(identity);
9592 }
9593 }
9594
9595 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009596 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9598 mApp, subId, "setCdmaSubscriptionMode");
9599
9600 final long identity = Binder.clearCallingIdentity();
9601 try {
9602 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9603 } finally {
9604 Binder.restoreCallingIdentity(identity);
9605 }
9606 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009607
sqianc5eccab2018-10-19 18:46:41 -07009608 @Override
sqian8c685422019-02-22 15:55:18 -08009609 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009610 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009612 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9613 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009614 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9615 }
9616 final long identity = Binder.clearCallingIdentity();
9617 try {
sqian854d44b2018-12-12 16:48:18 -08009618 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9619 for (Phone phone: PhoneFactory.getPhones()) {
9620 if (phone.getEmergencyNumberTracker() != null
9621 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9622 emergencyNumberListInternal.put(
9623 phone.getSubId(),
9624 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9625 }
sqian11b7a0e2018-12-05 18:48:28 -08009626 }
sqian854d44b2018-12-12 16:48:18 -08009627 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009628 } finally {
9629 Binder.restoreCallingIdentity(identity);
9630 }
sqianc5eccab2018-10-19 18:46:41 -07009631 }
9632
9633 @Override
sqian8c685422019-02-22 15:55:18 -08009634 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009635 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009636 if (!exactMatch) {
9637 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009638 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009639 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009640 }
9641 final long identity = Binder.clearCallingIdentity();
9642 try {
sqian854d44b2018-12-12 16:48:18 -08009643 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009644 //Note: we ignore passed in param exactMatch. We can remove it once
9645 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009646 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009647 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009648 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009649 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009650 }
sqian11b7a0e2018-12-05 18:48:28 -08009651 }
9652 return false;
9653 } finally {
9654 Binder.restoreCallingIdentity(identity);
9655 }
9656 }
9657
sqianf4ca7ed2019-01-15 18:32:07 -08009658 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009659 * Start emergency callback mode for GsmCdmaPhone for testing.
9660 */
9661 @Override
9662 public void startEmergencyCallbackMode() {
9663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9664 "startEmergencyCallbackMode");
9665 enforceModifyPermission();
9666 final long identity = Binder.clearCallingIdentity();
9667 try {
9668 for (Phone phone : PhoneFactory.getPhones()) {
9669 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9670 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9671 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9672 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9673 gsmCdmaPhone.obtainMessage(
9674 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9675 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9676 }
9677 }
9678 } finally {
9679 Binder.restoreCallingIdentity(identity);
9680 }
9681 }
9682
9683 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009684 * Update emergency number list for test mode.
9685 */
9686 @Override
9687 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9688 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9689 "updateEmergencyNumberListTestMode");
9690
9691 final long identity = Binder.clearCallingIdentity();
9692 try {
9693 for (Phone phone: PhoneFactory.getPhones()) {
9694 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9695 if (tracker != null) {
9696 tracker.executeEmergencyNumberTestModeCommand(action, num);
9697 }
9698 }
9699 } finally {
9700 Binder.restoreCallingIdentity(identity);
9701 }
9702 }
9703
9704 /**
9705 * Get the full emergency number list for test mode.
9706 */
9707 @Override
9708 public List<String> getEmergencyNumberListTestMode() {
9709 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9710 "getEmergencyNumberListTestMode");
9711
9712 final long identity = Binder.clearCallingIdentity();
9713 try {
9714 Set<String> emergencyNumbers = new HashSet<>();
9715 for (Phone phone: PhoneFactory.getPhones()) {
9716 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9717 if (tracker != null) {
9718 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9719 emergencyNumbers.add(num.getNumber());
9720 }
9721 }
9722 }
9723 return new ArrayList<>(emergencyNumbers);
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
9728
chen xud6b45bd2018-10-30 22:27:10 -07009729 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009730 public int getEmergencyNumberDbVersion(int subId) {
9731 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9732
9733 final long identity = Binder.clearCallingIdentity();
9734 try {
9735 final Phone phone = getPhone(subId);
9736 if (phone == null) {
9737 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9738 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9739 }
9740 return phone.getEmergencyNumberDbVersion();
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
9745
9746 @Override
9747 public void notifyOtaEmergencyNumberDbInstalled() {
9748 enforceModifyPermission();
9749
9750 final long identity = Binder.clearCallingIdentity();
9751 try {
9752 for (Phone phone: PhoneFactory.getPhones()) {
9753 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9754 if (tracker != null) {
9755 tracker.updateOtaEmergencyNumberDatabase();
9756 }
9757 }
9758 } finally {
9759 Binder.restoreCallingIdentity(identity);
9760 }
9761 }
9762
9763 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009764 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009765 enforceActiveEmergencySessionPermission();
9766
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
9769 for (Phone phone: PhoneFactory.getPhones()) {
9770 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9771 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009772 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9773 }
9774 }
9775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
9779
9780 @Override
9781 public void resetOtaEmergencyNumberDbFilePath() {
9782 enforceActiveEmergencySessionPermission();
9783
9784 final long identity = Binder.clearCallingIdentity();
9785 try {
9786 for (Phone phone: PhoneFactory.getPhones()) {
9787 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9788 if (tracker != null) {
9789 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009790 }
9791 }
9792 } finally {
9793 Binder.restoreCallingIdentity(identity);
9794 }
9795 }
9796
9797 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009798 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9799 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9800 Phone phone = getPhone(subId);
9801 if (phone == null) {
9802 return null;
9803 }
9804 final long identity = Binder.clearCallingIdentity();
9805 try {
9806 UiccProfile profile = UiccController.getInstance()
9807 .getUiccProfileForPhone(phone.getPhoneId());
9808 if (profile != null) {
9809 return profile.getCertsFromCarrierPrivilegeAccessRules();
9810 }
9811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 return null;
9815 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009816
9817 /**
9818 * Enable or disable a modem stack.
9819 */
9820 @Override
9821 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9822 enforceModifyPermission();
9823
9824 final long identity = Binder.clearCallingIdentity();
9825 try {
9826 Phone phone = PhoneFactory.getPhone(slotIndex);
9827 if (phone == null) {
9828 return false;
9829 } else {
9830 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9831 }
9832 } finally {
9833 Binder.restoreCallingIdentity(identity);
9834 }
9835 }
Michelecea4cf22018-12-21 15:00:11 -08009836
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009837 /**
9838 * Whether a modem stack is enabled or not.
9839 */
9840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009841 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9842 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009843 Phone phone = PhoneFactory.getPhone(slotIndex);
9844 if (phone == null) return false;
9845
9846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009847 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9848 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009849 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9850 }
9851
9852 final long identity = Binder.clearCallingIdentity();
9853 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009854 try {
9855 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9856 } catch (NoSuchElementException ex) {
9857 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9858 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009859 } finally {
9860 Binder.restoreCallingIdentity(identity);
9861 }
9862 }
9863
Michelecea4cf22018-12-21 15:00:11 -08009864 @Override
Michele0ea7d782019-03-19 14:58:42 -07009865 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009866 enforceModifyPermission();
9867
9868 final long identity = Binder.clearCallingIdentity();
9869 try {
9870 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009871 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009872 .commit();
9873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
9877
9878 @Override
Michele0ea7d782019-03-19 14:58:42 -07009879 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009880 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009882 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9883 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009884 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009885 }
Michelecea4cf22018-12-21 15:00:11 -08009886
9887 final long identity = Binder.clearCallingIdentity();
9888 try {
Michele0ea7d782019-03-19 14:58:42 -07009889 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
9893 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009894
Michele0ea7d782019-03-19 14:58:42 -07009895 @TelephonyManager.IsMultiSimSupportedResult
9896 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009897 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9898 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9899 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009900 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9901 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009902 }
9903 // Check if the hardware supports multisim functionality. If usage of multisim is not
9904 // supported by the modem, indicate that it is restricted.
9905 PhoneCapability staticCapability =
9906 mPhoneConfigurationManager.getStaticPhoneCapability();
9907 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009908 loge("isMultiSimSupportedInternal: no static configuration available");
9909 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009910 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009911 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009912 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9913 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009914 }
9915 // Check if support of multiple SIMs is restricted by carrier
9916 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009917 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009918 }
9919
Michele0ea7d782019-03-19 14:58:42 -07009920 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009921 }
9922
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009923 /**
9924 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009925 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9926 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9927 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009928 * @param numOfSims number of active sims we want to switch to
9929 */
9930 @Override
9931 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009932 if (numOfSims == 1) {
9933 enforceModifyPermission();
9934 } else {
9935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9936 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9937 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009938 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009939
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009940 try {
Michele30b57b22019-03-01 12:01:14 -08009941 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009942 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009943 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9944 return;
9945 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009946 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9947 } finally {
9948 Binder.restoreCallingIdentity(identity);
9949 }
9950 }
9951
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009952 @Override
9953 public boolean isApplicationOnUicc(int subId, int appType) {
9954 enforceReadPrivilegedPermission("isApplicationOnUicc");
9955 Phone phone = getPhone(subId);
9956 if (phone == null) {
9957 return false;
9958 }
9959 final long identity = Binder.clearCallingIdentity();
9960 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009961 UiccPort uiccPort = phone.getUiccPort();
9962 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009963 return false;
9964 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009965 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009966 if (uiccProfile == null) {
9967 return false;
9968 }
9969 if (TelephonyManager.APPTYPE_SIM <= appType
9970 && appType <= TelephonyManager.APPTYPE_ISIM) {
9971 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9972 }
9973 return false;
9974 } finally {
9975 Binder.restoreCallingIdentity(identity);
9976 }
9977 }
9978
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009979 /**
chen xub4baa772019-04-03 10:23:41 -07009980 * Get whether making changes to modem configurations will trigger reboot.
9981 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009982 */
9983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009984 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9985 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009987 mApp, subId, callingPackage, callingFeatureId,
9988 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009989 return false;
9990 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9994 } finally {
9995 Binder.restoreCallingIdentity(identity);
9996 }
9997 }
9998
Nathan Harold29f5f052019-02-15 13:41:57 -08009999 private void updateModemStateMetrics() {
10000 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10001 // TODO: check the state for each modem if the api is ready.
10002 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10003 }
10004
Pengquan Meng3889a572019-01-23 11:16:29 -080010005 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010006 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010007 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010008 // Verify that the callingPackage belongs to the calling UID
10009 mApp.getSystemService(AppOpsManager.class)
10010 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010011 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010012 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010013 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010014 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10015 if (slotInfos != null) {
10016 for (int i = 0; i < slotInfos.length; i++) {
10017 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10018 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10019 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10020 portInfo.getLogicalSlotIndex()));
10021 }
10022 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010023 }
10024 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010025 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010026 } finally {
10027 Binder.restoreCallingIdentity(identity);
10028 }
10029 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010030
10031 /**
10032 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010033 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010034 */
jimsunf9ec1622022-09-13 21:18:43 +080010035 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010036 @Override
10037 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010038 return getHalVersion(HAL_SERVICE_RADIO);
10039 }
10040
10041 /**
10042 * Get the HAL Version of a specific service
10043 */
10044 @Override
10045 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010046 Phone phone = getDefaultPhone();
10047 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010048 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010049 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10050 return hv.major * 100 + hv.minor;
10051 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010052
10053 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010054 * Get the current calling package name.
10055 * @return the current calling package name
10056 */
10057 @Override
10058 public String getCurrentPackageName() {
10059 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10060 }
10061
10062 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010063 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10064 * corresponding network requests on a subId.
10065 *
10066 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010067 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010068 * 2) APN is un-metered for this subscription, or
10069 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010070 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010071 *
10072 * @return whether data is allowed for a apn type.
10073 *
10074 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010075 */
10076 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010077 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010078 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10079 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010080
10081 // Now that all security checks passes, perform the operation as ourselves.
10082 final long identity = Binder.clearCallingIdentity();
10083 try {
10084 Phone phone = getPhone(subId);
10085 if (phone == null) return false;
10086
Jack Yu27422a52022-03-21 10:38:05 -070010087 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010088 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010089 isMetered = phone.getDataNetworkController().getDataConfigManager()
10090 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10091 phone.getServiceState().getDataRoaming());
10092 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010093 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010094 } finally {
10095 Binder.restoreCallingIdentity(identity);
10096 }
10097 }
10098
10099 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010100 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010101 enforceReadPrivilegedPermission("isApnMetered");
10102
10103 // Now that all security checks passes, perform the operation as ourselves.
10104 final long identity = Binder.clearCallingIdentity();
10105 try {
10106 Phone phone = getPhone(subId);
10107 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010108 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10109 DataUtils.apnTypeToNetworkCapability(apnType),
10110 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010115
10116 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010117 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10118 int subscriptionId, IBooleanConsumer resultCallback) {
10119 enforceModifyPermission();
10120 long token = Binder.clearCallingIdentity();
10121 try {
10122 Phone phone = getPhone(subscriptionId);
10123 if (phone == null) {
10124 try {
10125 if (resultCallback != null) {
10126 resultCallback.accept(false);
10127 }
10128 } catch (RemoteException e) {
10129 // ignore
10130 }
10131 return;
10132 }
10133 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10134 Pair.create(specifiers, (x) -> {
10135 try {
10136 if (resultCallback != null) {
10137 resultCallback.accept(x);
10138 }
10139 } catch (RemoteException e) {
10140 // ignore
10141 }
10142 });
10143 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10144 } finally {
10145 Binder.restoreCallingIdentity(token);
10146 }
10147 }
10148
10149 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010150 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10151 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010152 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010153 mApp, subId, "getSystemSelectionChannels");
10154 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10155 final long identity = Binder.clearCallingIdentity();
10156 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010157 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10158 if (result instanceof IllegalStateException) {
10159 throw (IllegalStateException) result;
10160 }
10161 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010162 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10163 return specifiers;
10164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
10168
10169 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010170 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010171 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010172 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010173 }
10174
10175 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010176 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10177 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010178 if (callingPackage == null) {
10179 callingPackage = getCurrentPackageName();
10180 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010181 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10182 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010183 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10184 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010185 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10186 }
10187 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10188 Intent intent = new Intent();
10189 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10190 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10191 // Bring up choose default SMS subscription dialog right now
10192 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10193 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10194 mApp.startActivity(intent);
10195 }
chen xud5ca2d52019-05-28 15:20:57 -070010196
10197 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010198 public void showSwitchToManagedProfileDialog() {
10199 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010200 try {
10201 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10202 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10203 // for work telephony.
10204 Intent intent = new Intent(Intent.ACTION_SENDTO);
10205 intent.setData(Uri.parse("smsto:"));
10206 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10207 mApp.startActivity(intent);
10208 } catch (ActivityNotFoundException e) {
10209 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10210 Intent intent = new Intent();
10211 intent.setClass(mApp, ErrorDialogActivity.class);
10212 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10213 mApp.startActivity(intent);
10214 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010215 }
10216
10217 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010218 public String getMmsUAProfUrl(int subId) {
10219 //TODO investigate if this API should require proper permission check in R b/133791609
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010222 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10223 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10224 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10225 return carrierUAProfUrl;
10226 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010227 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10228 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010229 } finally {
10230 Binder.restoreCallingIdentity(identity);
10231 }
10232 }
10233
10234 @Override
10235 public String getMmsUserAgent(int subId) {
10236 //TODO investigate if this API should require proper permission check in R b/133791609
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010239 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10240 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10241 if (!TextUtils.isEmpty(carrierUserAgent)) {
10242 return carrierUserAgent;
10243 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010244 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10245 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010246 } finally {
10247 Binder.restoreCallingIdentity(identity);
10248 }
10249 }
Jack Yub07d4972019-05-28 16:12:25 -070010250
10251 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010252 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10253 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010254
Jack Yub07d4972019-05-28 16:12:25 -070010255 final long identity = Binder.clearCallingIdentity();
10256 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010257 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010258 if (phone == null) return false;
10259
Ling Maf188d502022-09-16 15:22:36 -070010260 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010261 } finally {
10262 Binder.restoreCallingIdentity(identity);
10263 }
10264 }
10265
10266 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010267 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010268 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010269 enforceModifyPermission();
10270
changbettyd5c246e2019-12-24 15:40:37 +080010271 final long identity = Binder.clearCallingIdentity();
10272 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010273 Phone phone = getPhone(subscriptionId);
10274 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010275
Ling Maf188d502022-09-16 15:22:36 -070010276 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280 }
10281
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010282 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010283 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010284 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10285 * otherwise.
10286 */
10287 @Override
10288 public void setCepEnabled(boolean isCepEnabled) {
10289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10290
10291 final long identity = Binder.clearCallingIdentity();
10292 try {
10293 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10294 for (Phone phone : PhoneFactory.getPhones()) {
10295 Phone defaultPhone = phone.getImsPhone();
10296 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10297 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10298 ImsPhoneCallTracker imsPhoneCallTracker =
10299 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10300 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10301 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10302 + imsPhone.getMsisdn());
10303 }
10304 }
10305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
10308 }
allenwtsu46dcc572020-01-08 18:24:03 +080010309
10310 /**
10311 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10312 *
10313 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10314 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10315 * before being read.
10316 */
10317 @Override
10318 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10319 isCompressed) {
10320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10321 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010322 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10323 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10324 }
10325 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010326 // ProvisioningManager can not handle ServiceSpecificException.
10327 // Throw the IllegalStateException and annotate ProvisioningManager.
10328 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010329 }
10330
10331 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010332 try {
Hui Wang761a6682020-10-31 05:12:53 +000010333 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010336 }
10337 }
zoey chene02881a2019-12-30 16:11:23 +080010338
10339 @Override
10340 public boolean isIccLockEnabled(int subId) {
10341 enforceReadPrivilegedPermission("isIccLockEnabled");
10342
10343 // Now that all security checks passes, perform the operation as ourselves.
10344 final long identity = Binder.clearCallingIdentity();
10345 try {
10346 Phone phone = getPhone(subId);
10347 if (phone != null && phone.getIccCard() != null) {
10348 return phone.getIccCard().getIccLockEnabled();
10349 } else {
10350 return false;
10351 }
10352 } finally {
10353 Binder.restoreCallingIdentity(identity);
10354 }
10355 }
10356
10357 /**
10358 * Set the ICC pin lock enabled or disabled.
10359 *
10360 * @return an integer representing the status of IccLock enabled or disabled in the following
10361 * three cases:
10362 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10363 * successfully.
10364 * - Positive number and zero for remaining password attempts.
10365 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10366 *
10367 */
10368 @Override
10369 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10370 enforceModifyPermission();
10371
10372 Phone phone = getPhone(subId);
10373 if (phone == null) {
10374 return 0;
10375 }
10376 // Now that all security checks passes, perform the operation as ourselves.
10377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10380 new Pair<Boolean, String>(enabled, password), phone, null);
10381 return attemptsRemaining;
10382
10383 } catch (Exception e) {
10384 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10385 } finally {
10386 Binder.restoreCallingIdentity(identity);
10387 }
10388 return 0;
10389 }
10390
10391 /**
10392 * Change the ICC password used in ICC pin lock.
10393 *
10394 * @return an integer representing the status of IccLock changed in the following three cases:
10395 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10396 * - Positive number and zero for remaining password attempts.
10397 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10398 *
10399 */
10400 @Override
10401 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10402 enforceModifyPermission();
10403
10404 Phone phone = getPhone(subId);
10405 if (phone == null) {
10406 return 0;
10407 }
10408 // Now that all security checks passes, perform the operation as ourselves.
10409 final long identity = Binder.clearCallingIdentity();
10410 try {
10411 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10412 new Pair<String, String>(oldPassword, newPassword), phone, null);
10413 return attemptsRemaining;
10414
10415 } catch (Exception e) {
10416 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
10420 return 0;
10421 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010422
10423 /**
10424 * Request for receiving user activity notification
10425 */
10426 @Override
10427 public void requestUserActivityNotification() {
10428 if (!mNotifyUserActivity.get()
10429 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10430 mNotifyUserActivity.set(true);
10431 }
10432 }
10433
10434 /**
10435 * Called when userActivity is signalled in the power manager.
10436 * This is safe to call from any thread, with any window manager locks held or not.
10437 */
10438 @Override
10439 public void userActivity() {
10440 // ***************************************
10441 // * Inherited from PhoneWindowManager *
10442 // ***************************************
10443 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10444 // WITH ITS LOCKS HELD.
10445 //
10446 // This code must be VERY careful about the locks
10447 // it acquires.
10448 // In fact, the current code acquires way too many,
10449 // and probably has lurking deadlocks.
10450
10451 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10452 throw new SecurityException("Only the OS may call notifyUserActivity()");
10453 }
10454
10455 if (mNotifyUserActivity.getAndSet(false)) {
10456 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10457 USER_ACTIVITY_NOTIFICATION_DELAY);
10458 }
10459 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010460
10461 @Override
10462 public boolean canConnectTo5GInDsdsMode() {
10463 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10464 }
Jack Yud10cdd42020-09-28 20:28:01 -070010465
10466 @Override
10467 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10468 String callingFeatureId) {
10469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10470 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10471 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10472 }
10473
10474 Phone phone = getPhone(subId);
10475 if (phone == null) {
10476 throw new RuntimeException("phone is not available");
10477 }
10478 // Now that all security checks passes, perform the operation as ourselves.
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 return phone.getEquivalentHomePlmns();
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
Daniel Bright59e67312020-11-13 11:49:37 -080010486
10487 @Override
10488 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010489 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10490 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010491 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010492 if (radioInterfaceCapabilities == null) {
10493 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010494 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010495 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010496 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010497
Hui Wang641e81c2020-10-12 12:14:23 -070010498 @Override
10499 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10500 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010501 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10502 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10503 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10504 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10505 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010506 if (DBG) {
10507 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10508 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10509 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10510 }
10511
10512 if (!SubscriptionManager.isValidSubscriptionId(subId)
10513 || appType < TelephonyManager.APPTYPE_UNKNOWN
10514 || appType > TelephonyManager.APPTYPE_ISIM
10515 || nafUrl == null || securityProtocol == null || callback == null) {
10516 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10517 if (callback != null) {
10518 try {
10519 callback.onAuthenticationFailure(
10520 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10521 } catch (RemoteException exception) {
10522 log("Fail to notify onAuthenticationFailure due to " + exception);
10523 }
10524 return;
10525 }
10526 }
10527
10528 final long token = Binder.clearCallingIdentity();
10529 try {
10530 getGbaManager(subId).bootstrapAuthenticationRequest(
10531 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010532 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010533 } finally {
10534 Binder.restoreCallingIdentity(token);
10535 }
10536 }
10537
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010538 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010539 * Attempts to set the radio power state for all phones for thermal reason.
10540 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010541 * requested radio power state will actually be set. See {@link
10542 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10543 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010544 * @param enable {@code true} if trying to turn radio on.
10545 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10546 * false}.
10547 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010548 private boolean setRadioPowerForThermal(boolean enable) {
10549 boolean isPhoneAvailable = false;
10550 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10551 Phone phone = PhoneFactory.getPhone(i);
10552 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010553 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010554 isPhoneAvailable = true;
10555 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010556 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010557
10558 // return true if successfully informed the phone object about the thermal radio power
10559 // request.
10560 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010561 }
10562
10563 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010564 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010565 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10566 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10567 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10568 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10569 throw new IllegalArgumentException("modem does not support data throttling");
10570 }
10571
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010572 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10573 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010574 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010575 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10576 }
10577
Sarah Chinecc78c42022-03-31 21:16:48 -070010578 setDataEnabledForReason(
10579 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010580
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010581 if (isDataThrottlingSupported) {
10582 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010583 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010584 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10585 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10586 } else if (thermalMitigationResult
10587 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010588 log("Modem likely does not support data throttling on secondary carrier. Data " +
10589 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10590 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010591 }
10592 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010593 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010594
10595 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010596 }
10597
Jack Nudelman644b91a2021-03-12 14:09:48 -080010598 private static List<String> getThermalMitigationAllowlist(Context context) {
10599 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10600 for (String pckg : context.getResources()
10601 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10602 sThermalMitigationAllowlistedPackages.add(pckg);
10603 }
10604 }
10605
10606 return sThermalMitigationAllowlistedPackages;
10607 }
10608
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010609 private boolean isAnyPhoneInEmergencyState() {
10610 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10611 if (tm.isInEmergencyCall()) {
10612 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10613 return true;
10614 }
10615 for (Phone phone : PhoneFactory.getPhones()) {
10616 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10617 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010618 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10619 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010620 return true;
10621 }
10622 }
10623
10624 return false;
10625 }
10626
Jack Nudelman644b91a2021-03-12 14:09:48 -080010627 /**
10628 * Used by shell commands to add an authorized package name for thermal mitigation.
10629 * @param packageName name of package to be allowlisted
10630 * @param context
10631 */
10632 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10633 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10634 sThermalMitigationAllowlistedPackages.add(packageName);
10635 }
10636
10637 /**
10638 * Used by shell commands to remove an authorized package name for thermal mitigation.
10639 * @param packageName name of package to remove from allowlist
10640 * @param context
10641 */
10642 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10643 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10644 sThermalMitigationAllowlistedPackages.remove(packageName);
10645 }
10646
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010647 /**
10648 * Thermal mitigation request to control functionalities at modem.
10649 *
10650 * @param subId the id of the subscription.
10651 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010652 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010653 *
10654 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10655 */
10656 @Override
10657 @ThermalMitigationResult
10658 public int sendThermalMitigationRequest(
10659 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010660 ThermalMitigationRequest thermalMitigationRequest,
10661 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010662 enforceModifyPermission();
10663
Jack Nudelman644b91a2021-03-12 14:09:48 -080010664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10665 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10666 .contains(callingPackage)) {
10667 throw new SecurityException("Calling package must be configured in the device config. "
10668 + "calling package: " + callingPackage);
10669 }
10670
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010671 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10672 final long identity = Binder.clearCallingIdentity();
10673
10674 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10675 try {
10676 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10677 switch (thermalMitigationAction) {
10678 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10679 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010680 handleDataThrottlingRequest(subId,
10681 thermalMitigationRequest.getDataThrottlingRequest(),
10682 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010683 break;
10684 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10685 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10686 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10687 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10688 }
10689
10690 // Ensure that radio is on. If not able to power on due to phone being
10691 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010692 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010693 thermalMitigationResult =
10694 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10695 break;
10696 }
10697
10698 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010699 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010700 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10701 break;
10702 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10703 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10704 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10705 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10706 }
10707
10708 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10709 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010710 Phone phone = getPhone(subId);
10711 if (phone == null) {
10712 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010713 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010714 break;
10715 }
10716
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010717 TelephonyConnectionService service =
10718 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010719 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010720 Log.e(LOG_TAG, "An emergency call is pending");
10721 thermalMitigationResult =
10722 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10723 break;
10724 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010725 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010726 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010727 break;
10728 }
10729 } else {
10730 thermalMitigationResult =
10731 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10732 break;
10733 }
10734
10735 // Turn radio off. If not able to power off due to phone being unavailable,
10736 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010737 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010738 thermalMitigationResult =
10739 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10740 break;
10741 }
10742 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010743 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010744 break;
10745 default:
10746 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10747 + "not exist. Requested action: " + thermalMitigationAction);
10748 }
10749 } catch (IllegalArgumentException e) {
10750 throw e;
10751 } catch (Exception e) {
10752 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10753 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757
10758 if (DBG) {
10759 log("thermalMitigationRequest returning with thermalMitigationResult: "
10760 + thermalMitigationResult);
10761 }
10762
10763 return thermalMitigationResult;
10764 }
Hui Wang641e81c2020-10-12 12:14:23 -070010765
10766 /**
10767 * Set the GbaService Package Name that Telephony will bind to.
10768 *
10769 * @param subId The sim that the GbaService is associated with.
10770 * @param packageName The name of the package to be replaced with.
10771 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10772 */
10773 @Override
10774 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10775 enforceModifyPermission();
10776
10777 final long identity = Binder.clearCallingIdentity();
10778 try {
10779 return getGbaManager(subId).overrideServicePackage(packageName);
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
10785 /**
10786 * Return the package name of the currently bound GbaService.
10787 *
10788 * @param subId The sim that the GbaService is associated with.
10789 * @return the package name of the GbaService configuration, null if GBA is not supported.
10790 */
10791 @Override
10792 public String getBoundGbaService(int subId) {
10793 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10794
10795 final long identity = Binder.clearCallingIdentity();
10796 try {
10797 return getGbaManager(subId).getServicePackage();
10798 } finally {
10799 Binder.restoreCallingIdentity(identity);
10800 }
10801 }
10802
10803 /**
10804 * Set the release time for telephony to unbind GbaService.
10805 *
10806 * @param subId The sim that the GbaService is associated with.
10807 * @param interval The release time to unbind GbaService by millisecond.
10808 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10809 */
10810 @Override
10811 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10812 enforceModifyPermission();
10813
10814 final long identity = Binder.clearCallingIdentity();
10815 try {
10816 return getGbaManager(subId).overrideReleaseTime(interval);
10817 } finally {
10818 Binder.restoreCallingIdentity(identity);
10819 }
10820 }
10821
10822 /**
10823 * Return the release time for telephony to unbind GbaService.
10824 *
10825 * @param subId The sim that the GbaService is associated with.
10826 * @return The release time to unbind GbaService by millisecond.
10827 */
10828 @Override
10829 public int getGbaReleaseTime(int subId) {
10830 enforceReadPrivilegedPermission("getGbaReleaseTime");
10831
10832 final long identity = Binder.clearCallingIdentity();
10833 try {
10834 return getGbaManager(subId).getReleaseTime();
10835 } finally {
10836 Binder.restoreCallingIdentity(identity);
10837 }
10838 }
10839
10840 private GbaManager getGbaManager(int subId) {
10841 GbaManager instance = GbaManager.getInstance(subId);
10842 if (instance == null) {
10843 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10844 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10845 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10846 }
10847 return instance;
10848 }
Hui Wang761a6682020-10-31 05:12:53 +000010849
10850 /**
10851 * indicate whether the device and the carrier can support
10852 * RCS VoLTE single registration.
10853 */
10854 @Override
10855 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010856 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10857 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10858 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10859 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010860
10861 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10862 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10863 }
10864
10865 final long identity = Binder.clearCallingIdentity();
10866 try {
10867 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10868 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010869 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10870 if (isCapable != null) {
10871 return isCapable;
10872 }
Hui Wang761a6682020-10-31 05:12:53 +000010873 }
Hui Wang67af90e2021-06-04 16:57:15 -070010874 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10875 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010876 } finally {
10877 Binder.restoreCallingIdentity(identity);
10878 }
10879 }
10880
10881 /**
10882 * Register RCS provisioning callback.
10883 */
10884 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010885 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010886 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010887 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010888 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010889 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10890 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010891
10892 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10893 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10894 }
10895 if (!isImsAvailableOnDevice()) {
10896 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10897 "IMS not available on device.");
10898 }
10899
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010902 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010903 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010904 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10905 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010906 }
Hui Wang761a6682020-10-31 05:12:53 +000010907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
10912 /**
10913 * Unregister RCS provisioning callback.
10914 */
10915 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010916 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010917 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010918 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010919 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010920 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10921 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010922
10923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10924 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10925 }
10926 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010927 // operation failed silently
10928 Rlog.w(LOG_TAG, "IMS not available on device.");
10929 return;
Hui Wang761a6682020-10-31 05:12:53 +000010930 }
10931
10932 final long identity = Binder.clearCallingIdentity();
10933 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010934 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010935 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010936 } finally {
10937 Binder.restoreCallingIdentity(identity);
10938 }
10939 }
10940
10941 /**
10942 * trigger RCS reconfiguration.
10943 */
10944 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010945 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10946 "triggerRcsReconfiguration",
10947 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010948
10949 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10950 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10951 }
10952 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010953 // ProvisioningManager can not handle ServiceSpecificException.
10954 // Throw the IllegalStateException and annotate ProvisioningManager.
10955 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010956 }
10957
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
10960 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10961 } finally {
10962 Binder.restoreCallingIdentity(identity);
10963 }
10964 }
10965
10966 /**
10967 * Provide the client configuration parameters of the RCS application.
10968 */
10969 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010970 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10971 "setRcsClientConfiguration",
10972 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010973
10974 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10975 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10976 }
10977 if (!isImsAvailableOnDevice()) {
10978 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10979 "IMS not available on device.");
10980 }
10981
10982 final long identity = Binder.clearCallingIdentity();
10983
10984 try {
10985 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10986 if (configBinder == null) {
10987 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010988 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10989 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010990 } else {
10991 configBinder.setRcsClientConfiguration(rcc);
10992 }
joonhunshin3e154242021-09-17 06:33:39 +000010993
10994 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10995 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010996 } catch (RemoteException e) {
10997 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010998 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10999 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011000 } finally {
11001 Binder.restoreCallingIdentity(identity);
11002 }
11003 }
11004
11005 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011006 * Enables or disables the test mode for RCS VoLTE single registration.
11007 */
11008 @Override
11009 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11010 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11011 "setRcsSingleRegistrationTestModeEnabled");
11012
11013 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11014 }
11015
11016 /**
11017 * Gets the test mode for RCS VoLTE single registration.
11018 */
11019 @Override
11020 public boolean getRcsSingleRegistrationTestModeEnabled() {
11021 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11022 "getRcsSingleRegistrationTestModeEnabled");
11023
11024 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11025 }
11026
11027 /**
Hui Wang761a6682020-10-31 05:12:53 +000011028 * Overrides the config of RCS VoLTE single registration enabled for the device.
11029 */
11030 @Override
11031 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11033 "setDeviceSingleRegistrationEnabledOverride");
11034 enforceModifyPermission();
11035
11036 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11037 : Boolean.parseBoolean(enabledStr);
11038 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011039 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011040 }
11041
11042 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011043 * Sends a device to device communication message. Only usable via shell.
11044 * @param message message to send.
11045 * @param value message value.
11046 */
11047 @Override
11048 public void sendDeviceToDeviceMessage(int message, int value) {
11049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011050 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011051 enforceModifyPermission();
11052
11053 final long identity = Binder.clearCallingIdentity();
11054 try {
11055 TelephonyConnectionService service =
11056 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11057 if (service == null) {
11058 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11059 return;
11060 }
11061 service.sendTestDeviceToDeviceMessage(message, value);
11062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
11066
Tyler Gunnbabbda02021-02-10 11:05:02 -080011067 /**
11068 * Sets the specified device to device transport active.
11069 * @param transport The transport to set active.
11070 */
11071 @Override
11072 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11074 "setActiveDeviceToDeviceTransport");
11075 enforceModifyPermission();
11076
11077 final long identity = Binder.clearCallingIdentity();
11078 try {
11079 TelephonyConnectionService service =
11080 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11081 if (service == null) {
11082 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11083 return;
11084 }
11085 service.setActiveDeviceToDeviceTransport(transport);
11086 } finally {
11087 Binder.restoreCallingIdentity(identity);
11088 }
11089 }
Tyler Gunn92479152021-01-20 16:30:10 -080011090
Tyler Gunnd4339262021-05-03 14:46:49 -070011091 @Override
11092 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11094 "setDeviceToDeviceForceEnabled");
11095
11096 final long identity = Binder.clearCallingIdentity();
11097 try {
11098 Arrays.stream(PhoneFactory.getPhones()).forEach(
11099 p -> {
11100 Phone thePhone = p.getImsPhone();
11101 if (thePhone != null && thePhone instanceof ImsPhone) {
11102 ImsPhone imsPhone = (ImsPhone) thePhone;
11103 CallTracker tracker = imsPhone.getCallTracker();
11104 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11105 ImsPhoneCallTracker imsPhoneCallTracker =
11106 (ImsPhoneCallTracker) tracker;
11107 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11108 }
11109 }
11110 }
11111 );
11112 } finally {
11113 Binder.restoreCallingIdentity(identity);
11114 }
11115 }
11116
Tyler Gunn92479152021-01-20 16:30:10 -080011117 /**
Hui Wang761a6682020-10-31 05:12:53 +000011118 * Gets the config of RCS VoLTE single registration enabled for the device.
11119 */
11120 @Override
11121 public boolean getDeviceSingleRegistrationEnabled() {
11122 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11123 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11124 }
11125
11126 /**
11127 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11128 */
11129 @Override
11130 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11132 "setCarrierSingleRegistrationEnabledOverride");
11133 enforceModifyPermission();
11134
11135 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11136 : Boolean.parseBoolean(enabledStr);
11137 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11138 subId, enabled);
11139 }
11140
11141 /**
11142 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11143 */
11144 @Override
11145 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11146 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11147 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11148 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011149
11150 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011151 * Overrides the ims feature validation result
11152 */
11153 @Override
11154 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11156 "setImsFeatureValidationOverride");
11157
11158 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11159 : Boolean.parseBoolean(enabledStr);
11160 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11161 subId, enabled);
11162 }
11163
11164 /**
11165 * Gets the ims feature validation override value
11166 */
11167 @Override
11168 public boolean getImsFeatureValidationOverride(int subId) {
11169 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11170 "getImsFeatureValidationOverride");
11171 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11172 }
11173
11174 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011175 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11176 * their mobile plan.
11177 */
11178 @Override
11179 public String getMobileProvisioningUrl() {
11180 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11181 final long identity = Binder.clearCallingIdentity();
11182 try {
11183 return getDefaultPhone().getMobileProvisioningUrl();
11184 } finally {
11185 Binder.restoreCallingIdentity(identity);
11186 }
11187 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011188
James.cf Linbcdf8b32021-01-14 16:44:13 +080011189 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011190 * Get the EAB contact from the EAB database.
11191 */
11192 @Override
11193 public String getContactFromEab(String contact) {
11194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11195 enforceModifyPermission();
11196 final long identity = Binder.clearCallingIdentity();
11197 try {
11198 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11199 } finally {
11200 Binder.restoreCallingIdentity(identity);
11201 }
11202 }
11203
11204 /**
Calvin Pana1434322021-07-01 19:27:01 +080011205 * Get the EAB capability from the EAB database.
11206 */
11207 @Override
11208 public String getCapabilityFromEab(String contact) {
11209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11210 enforceModifyPermission();
11211 final long identity = Binder.clearCallingIdentity();
11212 try {
11213 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11214 } finally {
11215 Binder.restoreCallingIdentity(identity);
11216 }
11217 }
11218
11219 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011220 * Remove the EAB contacts from the EAB database.
11221 */
11222 @Override
11223 public int removeContactFromEab(int subId, String contacts) {
11224 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11225 enforceModifyPermission();
11226 final long identity = Binder.clearCallingIdentity();
11227 try {
11228 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11229 } finally {
11230 Binder.restoreCallingIdentity(identity);
11231 }
11232 }
11233
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011234 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011235 public boolean getDeviceUceEnabled() {
11236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11237 final long identity = Binder.clearCallingIdentity();
11238 try {
11239 return mApp.getDeviceUceEnabled();
11240 } finally {
11241 Binder.restoreCallingIdentity(identity);
11242 }
11243 }
11244
11245 @Override
11246 public void setDeviceUceEnabled(boolean isEnabled) {
11247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11248 final long identity = Binder.clearCallingIdentity();
11249 try {
11250 mApp.setDeviceUceEnabled(isEnabled);
11251 } finally {
11252 Binder.restoreCallingIdentity(identity);
11253 }
11254 }
11255
Brad Ebinger14d467f2021-02-12 06:18:28 +000011256 /**
11257 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11258 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11259 */
11260 // Used for SHELL command only right now.
11261 @Override
11262 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11263 List<String> featureTags) {
11264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11265 "addUceRegistrationOverrideShell");
11266 final long identity = Binder.clearCallingIdentity();
11267 try {
11268 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11269 new ArraySet<>(featureTags));
11270 } catch (ImsException e) {
11271 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11272 } finally {
11273 Binder.restoreCallingIdentity(identity);
11274 }
11275 }
11276
11277 /**
11278 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11279 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11280 */
11281 // Used for SHELL command only right now.
11282 @Override
11283 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11284 List<String> featureTags) {
11285 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11286 "removeUceRegistrationOverrideShell");
11287 final long identity = Binder.clearCallingIdentity();
11288 try {
11289 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11290 new ArraySet<>(featureTags));
11291 } catch (ImsException e) {
11292 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11293 } finally {
11294 Binder.restoreCallingIdentity(identity);
11295 }
11296 }
11297
11298 /**
11299 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11300 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11301 */
11302 // Used for SHELL command only right now.
11303 @Override
11304 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11305 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11306 "clearUceRegistrationOverrideShell");
11307 final long identity = Binder.clearCallingIdentity();
11308 try {
11309 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11310 } catch (ImsException e) {
11311 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11312 } finally {
11313 Binder.restoreCallingIdentity(identity);
11314 }
11315 }
11316
11317 /**
11318 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11319 */
11320 // Used for SHELL command only right now.
11321 @Override
11322 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11323 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11324 "getLatestRcsContactUceCapabilityShell");
11325 final long identity = Binder.clearCallingIdentity();
11326 try {
11327 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11328 } catch (ImsException e) {
11329 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11330 } finally {
11331 Binder.restoreCallingIdentity(identity);
11332 }
11333 }
11334
11335 /**
11336 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11337 * device does not have an active PUBLISH.
11338 */
11339 // Used for SHELL command only right now.
11340 @Override
11341 public String getLastUcePidfXmlShell(int subId) {
11342 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11343 final long identity = Binder.clearCallingIdentity();
11344 try {
11345 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11346 } catch (ImsException e) {
11347 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11348 } finally {
11349 Binder.restoreCallingIdentity(identity);
11350 }
11351 }
11352
James.cf Line8713a42021-04-29 16:04:26 +080011353 /**
11354 * Remove UCE requests cannot be sent to the network status.
11355 */
11356 // Used for SHELL command only right now.
11357 @Override
11358 public boolean removeUceRequestDisallowedStatus(int subId) {
11359 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11360 final long identity = Binder.clearCallingIdentity();
11361 try {
11362 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11363 } catch (ImsException e) {
11364 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11365 } finally {
11366 Binder.restoreCallingIdentity(identity);
11367 }
11368 }
11369
James.cf Lin18bb9002021-05-25 01:37:38 +080011370 /**
11371 * Remove UCE requests cannot be sent to the network status.
11372 */
11373 // Used for SHELL command only.
11374 @Override
11375 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11376 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11377 final long identity = Binder.clearCallingIdentity();
11378 try {
11379 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11380 } catch (ImsException e) {
11381 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11382 } finally {
11383 Binder.restoreCallingIdentity(identity);
11384 }
11385 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011386
James.cf Lin4b784aa2021-01-31 03:25:15 +080011387 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011388 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11389 String callingPackage) {
11390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11391 mApp, subId, "setSignalStrengthUpdateRequest");
11392
11393 final int callingUid = Binder.getCallingUid();
11394 // Verify that tha callingPackage belongs to the calling UID
11395 mApp.getSystemService(AppOpsManager.class)
11396 .checkPackage(callingUid, callingPackage);
11397
Rambo Wang3607f502021-02-01 21:51:40 -080011398 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011399
11400 final long identity = Binder.clearCallingIdentity();
11401 try {
11402 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11403 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11404
11405 if (result instanceof IllegalStateException) {
11406 throw (IllegalStateException) result;
11407 }
11408 } finally {
11409 Binder.restoreCallingIdentity(identity);
11410 }
11411 }
11412
11413 @Override
11414 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11415 String callingPackage) {
11416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11417 mApp, subId, "clearSignalStrengthUpdateRequest");
11418
11419 final int callingUid = Binder.getCallingUid();
11420 // Verify that tha callingPackage belongs to the calling UID
11421 mApp.getSystemService(AppOpsManager.class)
11422 .checkPackage(callingUid, callingPackage);
11423
11424 final long identity = Binder.clearCallingIdentity();
11425 try {
11426 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11427 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11428
11429 if (result instanceof IllegalStateException) {
11430 throw (IllegalStateException) result;
11431 }
11432 } finally {
11433 Binder.restoreCallingIdentity(identity);
11434 }
11435 }
11436
Rambo Wang3607f502021-02-01 21:51:40 -080011437 private static void validateSignalStrengthUpdateRequest(Context context,
11438 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011439 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11440 // phone/system process do not have further restriction on request
11441 return;
11442 }
11443
11444 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011445 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011446 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011447 context.enforceCallingOrSelfPermission(
11448 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11449 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011450 }
11451
11452 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011453 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011454 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011455 || info.isEnabled()) {
11456 throw new IllegalArgumentException(
11457 "Only system can set hide fields in SignalThresholdInfo");
11458 }
11459
11460 // Thresholds length for each RAN need in range. This has been validated in
11461 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11462 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11463 final int[] thresholds = info.getThresholds();
11464 Objects.requireNonNull(thresholds);
11465 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11466 || thresholds.length
11467 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11468 throw new IllegalArgumentException(
11469 "thresholds length is out of range: " + thresholds.length);
11470 }
11471 }
11472 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011473
11474 /**
11475 * Gets the current phone capability.
11476 *
11477 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11478 * @return the PhoneCapability which describes the data connection capability of modem.
11479 * It's used to evaluate possible phone config change, for example from single
11480 * SIM device to multi-SIM device.
11481 */
11482 @Override
11483 public PhoneCapability getPhoneCapability() {
11484 enforceReadPrivilegedPermission("getPhoneCapability");
11485 final long identity = Binder.clearCallingIdentity();
11486 try {
11487 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11488 } finally {
11489 Binder.restoreCallingIdentity(identity);
11490 }
11491 }
Michele Berionne5e411512020-11-13 02:36:59 +000011492
11493 /**
11494 * Prepare TelephonyManager for an unattended reboot. The reboot is
11495 * required to be done shortly after the API is invoked.
11496 */
11497 @Override
11498 @TelephonyManager.PrepareUnattendedRebootResult
11499 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011500 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011501 enforceRebootPermission();
11502
11503 final long identity = Binder.clearCallingIdentity();
11504 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011505 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011506 } finally {
11507 Binder.restoreCallingIdentity(identity);
11508 }
11509 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011510
11511 /**
11512 * Request to get the current slicing configuration including URSP rules and
11513 * NSSAIs (configured, allowed and rejected).
11514 *
11515 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11516 */
11517 @Override
11518 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011519 TelephonyPermissions
11520 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11521 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011522
11523 final long identity = Binder.clearCallingIdentity();
11524 try {
11525 Phone phone = getDefaultPhone();
11526 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11527 } finally {
11528 Binder.restoreCallingIdentity(identity);
11529 }
11530 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011531
11532 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011533 * Check whether the given premium capability is available for purchase from the carrier.
11534 *
11535 * @param capability The premium capability to check.
11536 * @param subId The subId to check the premium capability for.
11537 *
11538 * @return Whether the given premium capability is available to purchase.
11539 */
11540 @Override
11541 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11542 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11543 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11544 log("Premium capability "
11545 + TelephonyManager.convertPremiumCapabilityToString(capability)
11546 + " is not available for purchase due to missing permissions.");
11547 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11548 + "permission READ_BASIC_PHONE_STATE.");
11549 }
11550
11551 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011552 if (phone == null) {
11553 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11554 return false;
11555 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011556 final long identity = Binder.clearCallingIdentity();
11557 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011558 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011559 .isPremiumCapabilityAvailableForPurchase(capability);
11560 } finally {
11561 Binder.restoreCallingIdentity(identity);
11562 }
11563 }
11564
11565 /**
11566 * Purchase the given premium capability from the carrier.
11567 *
11568 * @param capability The premium capability to purchase.
11569 * @param callback The result of the purchase request.
11570 * @param subId The subId to purchase the premium capability for.
11571 */
11572 @Override
11573 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11574 log("purchasePremiumCapability: capability="
11575 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11576 + getCurrentPackageName());
11577
11578 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11579 mApp, "purchasePremiumCapability")) {
11580 log("purchasePremiumCapability "
11581 + TelephonyManager.convertPremiumCapabilityToString(capability)
11582 + " failed due to missing permissions.");
11583 throw new SecurityException("purchasePremiumCapability requires permission "
11584 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011585 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11586 mApp, "purchasePremiumCapability")) {
11587 log("purchasePremiumCapability "
11588 + TelephonyManager.convertPremiumCapabilityToString(capability)
11589 + " failed due to missing permissions.");
11590 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011591 }
11592
11593 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011594 if (phone == null) {
11595 try {
11596 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11597 callback.accept(result);
11598 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11599 } catch (RemoteException e) {
11600 String logStr = "Purchase premium capability "
11601 + TelephonyManager.convertPremiumCapabilityToString(capability)
11602 + " failed due to RemoteException handling null phone: " + e;
11603 if (DBG) log(logStr);
11604 AnomalyReporter.reportAnomaly(
11605 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11606 }
11607 return;
11608 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011609
11610 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011611 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011612 callingProcess = mApp.getPackageManager().getApplicationInfo(
11613 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011614 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011615 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011616 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011617
11618 boolean isVisible = false;
11619 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11620 if (am != null) {
11621 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11622 if (processes != null) {
11623 for (ActivityManager.RunningAppProcessInfo process : processes) {
11624 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011625 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011626 if (process.processName.equals(callingProcess) && process.importance
11627 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11628 isVisible = true;
11629 break;
11630 }
11631 }
11632 }
11633 }
11634
11635 if (!isVisible) {
11636 try {
11637 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11638 callback.accept(result);
11639 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11640 } catch (RemoteException e) {
11641 String logStr = "Purchase premium capability "
11642 + TelephonyManager.convertPremiumCapabilityToString(capability)
11643 + " failed due to RemoteException handling background application: " + e;
11644 if (DBG) log(logStr);
11645 AnomalyReporter.reportAnomaly(
11646 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11647 }
11648 return;
11649 }
11650
Sarah Chin71b3a852022-09-28 15:54:19 -070011651 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011652 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011653 }
11654
11655 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011656 * Register an IMS connection state callback
11657 */
11658 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011659 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11660 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011661 if (feature == ImsFeature.FEATURE_MMTEL) {
11662 // ImsMmTelManager
11663 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11664 TelephonyPermissions
11665 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11666 mApp, subId, "registerImsStateCallback");
11667 } else if (feature == ImsFeature.FEATURE_RCS) {
11668 // ImsRcsManager or SipDelegateManager
11669 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11670 Binder.getCallingUid(), "registerImsStateCallback",
11671 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11672 Manifest.permission.READ_PRECISE_PHONE_STATE,
11673 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11674 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11675 }
11676
11677 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11678 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11679 "IMS not available on device.");
11680 }
11681
11682 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11683 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11684 }
11685
11686 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11687 if (controller == null) {
11688 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11689 "IMS not available on device.");
11690 }
11691
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011692 if (callingPackage == null) {
11693 callingPackage = getCurrentPackageName();
11694 }
11695
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011696 final long token = Binder.clearCallingIdentity();
11697 try {
11698 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011699 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011700 } catch (ImsException e) {
11701 throw new ServiceSpecificException(e.getCode());
11702 } finally {
11703 Binder.restoreCallingIdentity(token);
11704 }
11705 }
11706
11707 /**
11708 * Unregister an IMS connection state callback
11709 */
11710 @Override
11711 public void unregisterImsStateCallback(IImsStateCallback cb) {
11712 final long token = Binder.clearCallingIdentity();
11713 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11714 if (controller == null) {
11715 return;
11716 }
11717 try {
11718 controller.unregisterImsStateCallback(cb);
11719 } finally {
11720 Binder.restoreCallingIdentity(token);
11721 }
11722 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011723
11724 /**
11725 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11726 *
11727 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11728 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11729 * SecurityException.
11730 * If there is current registered network this value will be same as the registered cell
11731 * identity. If the device goes out of service the previous cell identity is cached and
11732 * will be returned. If the cache age of the Cell identity is more than 24 hours
11733 * it will be cleared and null will be returned.
11734 *
11735 */
11736 @Override
11737 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11738 String callingFeatureId) {
11739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11740 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11741 LocationAccessPolicy.checkLocationPermission(mApp,
11742 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11743 .setCallingPackage(callingPackage)
11744 .setCallingFeatureId(callingFeatureId)
11745 .setCallingPid(Binder.getCallingPid())
11746 .setCallingUid(Binder.getCallingUid())
11747 .setMethod("getLastKnownCellIdentity")
11748 .setLogAsInfo(true)
11749 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11750 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11751 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11752 .build());
11753
11754 boolean hasFinePermission =
11755 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11756 if (!hasFinePermission
11757 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11758 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011759 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011760 }
11761
11762 final long identity = Binder.clearCallingIdentity();
11763 try {
Ling Mac28f0212023-03-24 16:07:15 -070011764 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011765 if (sst == null) return null;
11766 return sst.getLastKnownCellIdentity();
11767 } finally {
11768 Binder.restoreCallingIdentity(identity);
11769 }
11770 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011771
jimsun3b9ccac2021-10-26 15:01:23 +080011772 /**
11773 * Sets the modem service class Name that Telephony will bind to.
11774 *
11775 * @param serviceName The class name of the modem service.
11776 * @return true if the operation is succeed, otherwise false.
11777 */
11778 public boolean setModemService(String serviceName) {
11779 Log.d(LOG_TAG, "setModemService - " + serviceName);
11780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011782 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11783 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011784 return mPhoneConfigurationManager.setModemService(serviceName);
11785 }
11786
11787 /**
11788 * Return the class name of the currently bounded modem service.
11789 *
11790 * @return the class name of the modem service.
11791 */
11792 public String getModemService() {
11793 String result;
11794 Log.d(LOG_TAG, "getModemService");
11795 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11796 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011797 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011798 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11799 "getModemService");
11800 result = mPhoneConfigurationManager.getModemService();
11801 Log.d(LOG_TAG, "result = " + result);
11802 return result;
11803 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011804
11805 @Override
11806 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11807 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11808 mApp.enforceCallingOrSelfPermission(
11809 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11810 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11811
11812 final long identity = Binder.clearCallingIdentity();
11813 try {
11814 Phone phone = getPhone(subId);
11815 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011816 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11817 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011818 phone.setVoiceServiceStateOverride(hasService);
11819 } finally {
11820 Binder.restoreCallingIdentity(identity);
11821 }
11822 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011823
11824 /**
11825 * set removable eSIM as default eUICC.
11826 *
11827 * @hide
11828 */
11829 @Override
11830 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11831 enforceModifyPermission();
11832 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11833
11834 final long identity = Binder.clearCallingIdentity();
11835 try {
11836 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11837 } finally {
11838 Binder.restoreCallingIdentity(identity);
11839 }
11840 }
11841
11842 /**
11843 * Returns whether the removable eSIM is default eUICC or not.
11844 *
11845 * @hide
11846 */
11847 @Override
11848 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11849 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11850 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11851
11852 final long identity = Binder.clearCallingIdentity();
11853 try {
11854 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11855 } finally {
11856 Binder.restoreCallingIdentity(identity);
11857 }
11858 }
11859
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011860 /**
11861 * Get the component name of the default app to direct respond-via-message intent for the
11862 * user associated with this subscription, update the cache if there is no respond-via-message
11863 * application currently configured for this user.
11864 * @return component name of the app and class to direct Respond Via Message intent to, or
11865 * {@code null} if the functionality is not supported.
11866 * @hide
11867 */
11868 @Override
11869 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11870 boolean updateIfNeeded) {
11871 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011872
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011873 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11874
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011875 UserHandle userHandle = null;
11876 final long identity = Binder.clearCallingIdentity();
11877 try {
11878 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11879 } finally {
11880 Binder.restoreCallingIdentity(identity);
11881 }
11882 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11883 updateIfNeeded, userHandle);
11884 }
Jack Yuf5badd92022-12-08 00:50:53 -080011885
11886 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011887 * Set whether the device is able to connect with null ciphering or integrity
11888 * algorithms. This is a global setting and will apply to all active subscriptions
11889 * and all new subscriptions after this.
11890 *
11891 * @param enabled when true, null cipher and integrity algorithms are allowed.
11892 * @hide
11893 */
11894 @Override
11895 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11896 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11897 enforceModifyPermission();
11898 checkForNullCipherAndIntegritySupport();
11899
11900 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11901 // for listening to these preference changes and applying them immediately.
11902 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11903 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11904 editor.apply();
11905
11906 for (Phone phone: PhoneFactory.getPhones()) {
11907 phone.handleNullCipherEnabledChange();
11908 }
11909 }
11910
11911
11912 /**
11913 * Get whether the device is able to connect with null ciphering or integrity
11914 * algorithms. Note that this retrieves the phone-global preference and not
11915 * the state of the radio.
11916 *
11917 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11918 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11919 * version for this feature.
11920 * @hide
11921 */
11922 @Override
11923 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11924 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11925 enforceReadPermission();
11926 checkForNullCipherAndIntegritySupport();
11927 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11928 }
11929
11930 private void checkForNullCipherAndIntegritySupport() {
11931 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11932 throw new UnsupportedOperationException(
11933 "Null cipher and integrity operations require HAL 2.1 or above");
11934 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011935 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11936 throw new UnsupportedOperationException(
11937 "Null cipher and integrity operations unsupported by modem");
11938 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011939 }
11940
11941 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011942 * Get the SIM state for the slot index.
11943 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11944 *
11945 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11946 */
11947 @Override
11948 @SimState
11949 public int getSimStateForSlotIndex(int slotIndex) {
11950 IccCardConstants.State simState;
11951 if (slotIndex < 0) {
11952 simState = IccCardConstants.State.UNKNOWN;
11953 } else {
11954 Phone phone = null;
11955 try {
11956 phone = PhoneFactory.getPhone(slotIndex);
11957 } catch (IllegalStateException e) {
11958 // ignore
11959 }
11960 if (phone == null) {
11961 simState = IccCardConstants.State.UNKNOWN;
11962 } else {
11963 IccCard icc = phone.getIccCard();
11964 if (icc == null) {
11965 simState = IccCardConstants.State.UNKNOWN;
11966 } else {
11967 simState = icc.getState();
11968 }
11969 }
11970 }
11971 return simState.ordinal();
11972 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011973
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011974 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11975 boolean enableLogcat,
11976 long logcatStartTimestampMillis, boolean enableTelecomDump,
11977 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011978 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11979 TelephonyManager.EmergencyCallDiagnosticParams edp =
11980 new TelephonyManager.EmergencyCallDiagnosticParams();
11981 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11982 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11983 edp.setTelecomDumpSysCollection(enableTelecomDump);
11984 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11985 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11986 Executors.newCachedThreadPool(), db,
11987 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11988 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011989 }
11990
11991 /**
11992 * Request telephony to persist state for debugging emergency call failures.
11993 *
11994 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11995 * @param enableLogcat whether to collect logcat output
11996 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11997 * @param enableTelecomDump whether to collect telecom dumpsys
11998 * @param enableTelephonyDump whether to collect telephony dumpsys
11999 */
12000 @Override
12001 @RequiresPermission(android.Manifest.permission.DUMP)
12002 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12003 long logcatStartTimestampMillis, boolean enableTelecomDump,
12004 boolean enableTelephonyDump) {
12005 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12006 "persistEmergencyCallDiagnosticData");
12007 final long identity = Binder.clearCallingIdentity();
12008 try {
12009 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12010 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12011
12012 } finally {
12013 Binder.restoreCallingIdentity(identity);
12014 }
12015 }
12016
Hui Wang9b5793a2022-12-05 14:38:06 -060012017 /**
12018 * Get current cell broadcast ranges.
12019 */
12020 @Override
12021 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12022 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12023 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12024 "getCellBroadcastIdRanges");
12025 final long identity = Binder.clearCallingIdentity();
12026 try {
12027 return getPhone(subId).getCellBroadcastIdRanges();
12028 } finally {
12029 Binder.restoreCallingIdentity(identity);
12030 }
12031 }
12032
12033 /**
12034 * Set reception of cell broadcast messages with the list of the given ranges
12035 *
12036 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12037 */
12038 @Override
12039 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12040 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12041 @Nullable IIntegerConsumer callback) {
12042 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12043 "setCellBroadcastIdRanges");
12044 final long identity = Binder.clearCallingIdentity();
12045 try {
12046 Phone phone = getPhoneFromSubId(subId);
12047 if (DBG) {
12048 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12049 }
12050 phone.setCellBroadcastIdRanges(ranges, result -> {
12051 if (callback != null) {
12052 try {
12053 callback.accept(result);
12054 } catch (RemoteException e) {
12055 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12056 }
12057 }
12058 });
12059 } finally {
12060 Binder.restoreCallingIdentity(identity);
12061 }
12062 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012063
12064 /**
12065 * Returns whether the device supports the domain selection service.
12066 *
12067 * @return {@code true} if the device supports the domain selection service.
12068 */
12069 @Override
12070 public boolean isDomainSelectionSupported() {
12071 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12072 "isDomainSelectionSupported");
12073
12074 final long identity = Binder.clearCallingIdentity();
12075 try {
12076 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12077 } finally {
12078 Binder.restoreCallingIdentity(identity);
12079 }
12080 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012081
12082 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012083 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12084 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12085 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012086 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012087 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012088 * @param enableSatellite {@code true} to enable the satellite modem and
12089 * {@code false} to disable.
12090 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12091 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012092 *
12093 * @throws SecurityException if the caller doesn't have the required permission.
12094 */
12095 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012096 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12097 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012098 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012099 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12100 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012101 }
12102
12103 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012104 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012105 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012106 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012107 * @param result The result receiver that returns whether the satellite modem is enabled
12108 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012109 *
12110 * @throws SecurityException if the caller doesn't have the required permission.
12111 */
12112 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012113 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12114 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012115 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012116 }
12117
12118 /**
Sarah Chin43457982023-02-15 17:50:38 -080012119 * Request to get whether the satellite service demo mode is enabled.
12120 *
12121 * @param subId The subId of the subscription to check whether the satellite demo mode
12122 * is enabled for.
12123 * @param result The result receiver that returns whether the satellite demo mode is enabled
12124 * if the request is successful or an error code if the request failed.
12125 *
12126 * @throws SecurityException if the caller doesn't have the required permission.
12127 */
12128 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012129 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12130 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12131 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012132 }
12133
12134 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012135 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012136 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012137 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012138 * @param result The result receiver that returns whether the satellite service is supported on
12139 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012140 */
12141 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012142 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012143 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012144 }
12145
12146 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012147 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012148 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012149 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012150 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12151 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012152 *
12153 * @throws SecurityException if the caller doesn't have required permission.
12154 */
12155 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012156 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12157 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012158 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012159 }
12160
12161 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012162 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012163 * This can be called by the pointing UI when the user starts pointing to the satellite.
12164 * Modem should continue to report the pointing input as the device or satellite moves.
12165 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012166 * @param subId The subId of the subscription to start satellite transmission updates for.
12167 * @param resultCallback The callback to get the result of the request.
12168 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012169 *
12170 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012171 */
12172 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012173 public void startSatelliteTransmissionUpdates(int subId,
12174 @NonNull IIntegerConsumer resultCallback,
12175 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12176 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12177 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012178 }
12179
12180 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012181 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012182 * This can be called by the pointing UI when the user stops pointing to the satellite.
12183 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012184 * @param subId The subId of the subscription to stop satellite transmission updates for.
12185 * @param resultCallback The callback to get the result of the request.
12186 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12187 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012188 *
12189 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012190 */
12191 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012192 public void stopSatelliteTransmissionUpdates(int subId,
12193 @NonNull IIntegerConsumer resultCallback,
12194 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12195 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12196 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012197 }
12198
12199 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012200 * Register the subscription with a satellite provider.
12201 * This is needed to register the subscription if the provider allows dynamic registration.
12202 *
12203 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012204 * @param token The token to be used as a unique identifier for provisioning with satellite
12205 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012206 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012207 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012208 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012209 * @return The signal transport used by the caller to cancel the provision request,
12210 * or {@code null} if the request failed.
12211 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012212 * @throws SecurityException if the caller doesn't have the required permission.
12213 */
12214 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012215 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012216 @NonNull String token, @NonNull byte[] provisionData,
12217 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012218 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012219 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12220 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012221 }
12222
12223 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012224 * Unregister the device/subscription with the satellite provider.
12225 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012226 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012227 * should report as deprovisioned.
12228 *
12229 * @param subId The subId of the subscription to be deprovisioned.
12230 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012231 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012232 *
12233 * @throws SecurityException if the caller doesn't have the required permission.
12234 */
12235 @Override
12236 public void deprovisionSatelliteService(int subId,
12237 @NonNull String token, @NonNull IIntegerConsumer callback) {
12238 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012239 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012240 }
12241
12242 /**
Sarah Chin43457982023-02-15 17:50:38 -080012243 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012244 *
Sarah Chin43457982023-02-15 17:50:38 -080012245 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012246 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012247 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012248 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012249 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012250 * @throws SecurityException if the caller doesn't have the required permission.
12251 */
12252 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012253 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12254 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012255 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012256 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012257 }
12258
12259 /**
Sarah Chin43457982023-02-15 17:50:38 -080012260 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012261 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012262 *
Sarah Chin43457982023-02-15 17:50:38 -080012263 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012264 * @param callback The callback that was passed to
12265 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012266 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012267 * @throws SecurityException if the caller doesn't have the required permission.
12268 */
12269 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012270 public void unregisterForSatelliteProvisionStateChanged(
12271 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012272 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012273 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012274 }
12275
12276 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012277 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012278 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012279 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012280 * @param result The result receiver that returns whether the device is provisioned with a
12281 * satellite provider if the request is successful or an error code if the
12282 * request failed.
12283 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012284 * @throws SecurityException if the caller doesn't have the required permission.
12285 */
12286 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012287 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12288 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012289 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012290 }
12291
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012292 /**
Sarah Chin43457982023-02-15 17:50:38 -080012293 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012294 *
Sarah Chin43457982023-02-15 17:50:38 -080012295 * @param subId The subId of the subscription to register for satellite modem state changed.
12296 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012297 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012298 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012299 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012300 * @throws SecurityException if the caller doesn't have the required permission.
12301 */
12302 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012303 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012304 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012305 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012306 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012307 }
12308
12309 /**
Sarah Chin43457982023-02-15 17:50:38 -080012310 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012311 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012312 *
Sarah Chin43457982023-02-15 17:50:38 -080012313 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012314 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012315 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012316 *
12317 * @throws SecurityException if the caller doesn't have the required permission.
12318 */
12319 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012320 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012321 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012322 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012323 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012324 }
12325
12326 /**
12327 * Register to receive incoming datagrams over satellite.
12328 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012329 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012330 * @param callback The callback to handle incoming datagrams over satellite.
12331 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012332 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012333 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012334 * @throws SecurityException if the caller doesn't have the required permission.
12335 */
12336 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012337 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012338 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012339 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012340 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012341 }
12342
12343 /**
12344 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012345 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012346 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012347 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12348 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012349 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012350 *
12351 * @throws SecurityException if the caller doesn't have the required permission.
12352 */
12353 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012354 public void unregisterForSatelliteDatagram(int subId,
12355 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012356 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012357 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012358 }
12359
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012360 /**
12361 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012362 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012363 * This method requests modem to check if there are any pending datagrams to be received over
12364 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012365 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012366 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012367 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012368 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012369 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012370 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012371 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012372 @Override
12373 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012374 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012375 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012376 }
12377
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012378 /**
12379 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012380 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012381 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12382 * input to this method. Datagram received here will be passed down to modem without any
12383 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012384 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012385 * @param subId The subId of the subscription to send satellite datagrams for.
12386 * @param datagramType datagram type indicating whether the datagram is of type
12387 * SOS_SMS or LOCATION_SHARING.
12388 * @param datagram encoded gateway datagram which is encrypted by the caller.
12389 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012390 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12391 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012392 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012393 *
12394 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012395 */
12396 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012397 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12398 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12399 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012400 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012401 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12402 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012403 }
12404
Sarah Chindf715ec2023-02-13 13:46:24 -080012405 /**
12406 * Request to get whether satellite communication is allowed for the current location.
12407 *
12408 * @param subId The subId of the subscription to check whether satellite communication is
12409 * allowed for the current location for.
12410 * @param result The result receiver that returns whether satellite communication is allowed
12411 * for the current location if the request is successful or an error code
12412 * if the request failed.
12413 *
12414 * @throws SecurityException if the caller doesn't have the required permission.
12415 */
12416 @Override
12417 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12418 @NonNull ResultReceiver result) {
12419 enforceSatelliteCommunicationPermission(
12420 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012421 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12422 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012423 }
12424
12425 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012426 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012427 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012428 * @param subId The subId to get the time after which the satellite will be visible for.
12429 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012430 * be visible if the request is successful or an error code if the request failed.
12431 *
12432 * @throws SecurityException if the caller doesn't have the required permission.
12433 */
12434 @Override
12435 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12436 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012437 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012438 }
12439
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012440 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012441 * Inform that Device is aligned to satellite for demo mode.
12442 *
12443 * @param subId The subId to get the time after which the satellite will be visible for.
12444 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12445 * {@code false} Device fails to align with the satellite for demo mode.
12446 *
12447 * @throws SecurityException if the caller doesn't have required permission.
12448 */
12449 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12450
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012451 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012452 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012453 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012454 }
12455
12456 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012457 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12458 * by modem.
12459 *
12460 * @param subId The subId of the subscription to request for.
12461 * @param reason Reason for disallowing satellite communication for carrier.
12462 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12463 * operation.
12464 *
12465 * @throws SecurityException if the caller doesn't have required permission.
12466 */
12467 public void addSatelliteAttachRestrictionForCarrier(int subId,
12468 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12469 @NonNull IIntegerConsumer callback) {
12470 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12471 final long identity = Binder.clearCallingIdentity();
12472 try {
12473 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12474 } finally {
12475 Binder.restoreCallingIdentity(identity);
12476 }
12477 }
12478
12479 /**
12480 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12481 * by modem.
12482 *
12483 * @param subId The subId of the subscription to request for.
12484 * @param reason Reason for disallowing satellite communication.
12485 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12486 * operation.
12487 *
12488 * @throws SecurityException if the caller doesn't have required permission.
12489 */
12490 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12491 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12492 @NonNull IIntegerConsumer callback) {
12493 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12494 final long identity = Binder.clearCallingIdentity();
12495 try {
12496 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12497 callback);
12498 } finally {
12499 Binder.restoreCallingIdentity(identity);
12500 }
12501 }
12502
12503 /**
12504 * Get reasons for disallowing satellite communication, as requested by
12505 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12506 *
12507 * @param subId The subId of the subscription to request for.
12508 *
12509 * @return Integer array of reasons for disallowing satellite communication.
12510 *
12511 * @throws SecurityException if the caller doesn't have the required permission.
12512 */
12513 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12514 int subId) {
12515 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12516 final long identity = Binder.clearCallingIdentity();
12517 try {
12518 Set<Integer> reasonSet =
12519 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12520 return reasonSet.stream().mapToInt(i->i).toArray();
12521 } finally {
12522 Binder.restoreCallingIdentity(identity);
12523 }
12524 }
12525
12526 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012527 * Request to get the signal strength of the satellite connection.
12528 *
12529 * @param subId The subId of the subscription to request for.
12530 * @param result Result receiver to get the error code of the request and the current signal
12531 * strength of the satellite connection.
12532 *
12533 * @throws SecurityException if the caller doesn't have required permission.
12534 */
12535 @Override
12536 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12537 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12538 final long identity = Binder.clearCallingIdentity();
12539 try {
12540 mSatelliteController.requestNtnSignalStrength(subId, result);
12541 } finally {
12542 Binder.restoreCallingIdentity(identity);
12543 }
12544 }
12545
12546 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012547 * Registers for NTN signal strength changed from satellite modem. If the registration operation
12548 * is not successful, a {@link ServiceSpecificException} that contains
12549 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012550 *
12551 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012552 * @param callback The callback to handle the NTN signal strength changed event. If the
12553 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
12554 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
12555 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
12556 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012557 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012558 * @throws SecurityException If the caller doesn't have the required permission.
12559 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012560 */
12561 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012562 public void registerForNtnSignalStrengthChanged(int subId,
12563 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000012564 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12565 final long identity = Binder.clearCallingIdentity();
12566 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012567 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000012568 } finally {
12569 Binder.restoreCallingIdentity(identity);
12570 }
12571 }
12572
12573 /**
12574 * Unregisters for NTN signal strength changed from satellite modem.
12575 * If callback was not registered before, the request will be ignored.
12576 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000012577 * @param subId The subId of the subscription to unregister for listening NTN signal strength
12578 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012579 * @param callback The callback that was passed to
12580 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12581 *
12582 * @throws SecurityException if the caller doesn't have the required permission.
12583 */
12584 @Override
12585 public void unregisterForNtnSignalStrengthChanged(
12586 int subId, @NonNull INtnSignalStrengthCallback callback) {
12587 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12588 final long identity = Binder.clearCallingIdentity();
12589 try {
12590 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12591 } finally {
12592 Binder.restoreCallingIdentity(identity);
12593 }
12594 }
12595
12596 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000012597 * Registers for satellite capabilities change event from the satellite service.
12598 *
12599 * @param subId The subId of the subscription to request for.
12600 * @param callback The callback to handle the satellite capabilities changed event.
12601 *
12602 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12603 *
12604 * @throws SecurityException if the caller doesn't have required permission.
12605 */
12606 @Override
12607 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
12608 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12609 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
12610 final long identity = Binder.clearCallingIdentity();
12611 try {
12612 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
12613 } finally {
12614 Binder.restoreCallingIdentity(identity);
12615 }
12616 }
12617
12618 /**
12619 * Unregisters for satellite capabilities change event from the satellite service.
12620 * If callback was not registered before, the request will be ignored.
12621 *
12622 * @param subId The subId of the subscription to unregister for satellite capabilities change.
12623 * @param callback The callback that was passed to.
12624 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
12625 *
12626 * @throws SecurityException if the caller doesn't have required permission.
12627 */
12628 @Override
12629 public void unregisterForSatelliteCapabilitiesChanged(
12630 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12631 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
12632 final long identity = Binder.clearCallingIdentity();
12633 try {
12634 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
12635 } finally {
12636 Binder.restoreCallingIdentity(identity);
12637 }
12638 }
12639
12640 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012641 * This API can be used by only CTS to update satellite vendor service package name.
12642 *
12643 * @param servicePackageName The package name of the satellite vendor service.
12644 * @return {@code true} if the satellite vendor service is set successfully,
12645 * {@code false} otherwise.
12646 */
12647 public boolean setSatelliteServicePackageName(String servicePackageName) {
12648 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12649 TelephonyPermissions.enforceShellOnly(
12650 Binder.getCallingUid(), "setSatelliteServicePackageName");
12651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12652 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12653 "setSatelliteServicePackageName");
12654 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12655 }
12656
12657 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012658 * This API can be used by only CTS to update satellite gateway service package name.
12659 *
12660 * @param servicePackageName The package name of the satellite gateway service.
12661 * @return {@code true} if the satellite gateway service is set successfully,
12662 * {@code false} otherwise.
12663 */
12664 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12665 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12666 TelephonyPermissions.enforceShellOnly(
12667 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12669 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12670 "setSatelliteGatewayServicePackageName");
12671 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12672 }
12673
12674 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012675 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12676 *
12677 * @param packageName The package name of the satellite pointing UI app.
12678 * @param className The class name of the satellite pointing UI app.
12679 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12680 * {@code false} otherwise.
12681 */
12682 public boolean setSatellitePointingUiClassName(
12683 @Nullable String packageName, @Nullable String className) {
12684 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12685 + ", className=" + className);
12686 TelephonyPermissions.enforceShellOnly(
12687 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12689 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12690 "setSatelliteGatewayServicePackageName");
12691 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12692 }
12693
12694 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012695 * This API can be used by only CTS to update the timeout duration in milliseconds that
12696 * satellite should stay at listening mode to wait for the next incoming page before disabling
12697 * listening mode.
12698 *
12699 * @param timeoutMillis The timeout duration in millisecond.
12700 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12701 */
12702 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12703 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12704 TelephonyPermissions.enforceShellOnly(
12705 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12707 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12708 "setSatelliteListeningTimeoutDuration");
12709 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12710 }
12711
12712 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012713 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12714 * the device is aligned with the satellite for demo mode
12715 *
12716 * @param timeoutMillis The timeout duration in millisecond.
12717 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12718 */
12719 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12720 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12721 TelephonyPermissions.enforceShellOnly(
12722 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12724 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12725 "setDeviceAlignedTimeoutDuration");
12726 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12727 }
12728
12729 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070012730 * This API can be used in only testing to override connectivity status in monitoring emergency
12731 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
12732 *
12733 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
12734 * of the following values to enable the override:
12735 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
12736 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
12737 * To disable the override, use -1 for handoverType.
12738 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
12739 * delaySeconds after the emergency call starts.
12740 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
12741 */
12742 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
12743 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
12744 TelephonyPermissions.enforceShellOnly(
12745 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
12746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12747 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12748 "setEmergencyCallToSatelliteHandoverType");
12749 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
12750 handoverType, delaySeconds);
12751 }
12752
12753 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000012754 * This API can be used by only CTS to override the cached value for the device overlay config
12755 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
12756 * outgoing satellite datagrams should be sent to modem in demo mode.
12757 *
12758 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
12759 * satellite modem or not.
12760 *
12761 * @return {@code true} if the operation is successful, {@code false} otherwise.
12762 */
12763 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
12764 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
12765 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
12766 + "disabled");
12767 return false;
12768 }
12769 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
12770 TelephonyPermissions.enforceShellOnly(
12771 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
12772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12773 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12774 "setShouldSendDatagramToModemInDemoMode");
12775 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
12776 shouldSendToModemInDemoMode);
12777 }
12778
12779 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012780 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12781 *
12782 * <p>This method behaves in one of the following ways:
12783 * <ul>
12784 * <li>return true : if the calling package has the appop permission {@link
12785 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12786 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12787 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12788 * Owner device identifier access check, or the calling package has carrier privileges</>
12789 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12790 * </ul>
12791 */
12792 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12793 String callingPackage, @Nullable String callingFeatureId, String message) {
12794 for (Phone phone : PhoneFactory.getPhones()) {
12795 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12796 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12797 return true;
12798 }
12799 }
12800 return false;
12801 }
arunvoddud7401012022-12-15 16:08:12 +000012802
12803 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012804 * @return The subscription manager service instance.
12805 */
12806 public SubscriptionManagerService getSubscriptionManagerService() {
12807 return SubscriptionManagerService.getInstance();
12808 }
12809
12810 /**
arunvoddud7401012022-12-15 16:08:12 +000012811 * Class binds the consumer[callback] and carrierId.
12812 */
12813 private static class CallerCallbackInfo {
12814 private final Consumer<Integer> mConsumer;
12815 private final int mCarrierId;
12816
12817 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12818 mConsumer = consumer;
12819 mCarrierId = carrierId;
12820 }
12821
12822 public Consumer<Integer> getConsumer() {
12823 return mConsumer;
12824 }
12825
12826 public int getCarrierId() {
12827 return mCarrierId;
12828 }
12829 }
Jack Yufa8ed012023-02-11 15:42:28 -080012830}