blob: a968b8222f96fa377fe8638f87b9379754f6da6a [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;
Gil Cukierman06403e12023-11-29 16:33:03 +0000404 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
405 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000406
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 /** The singleton instance. */
408 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800409 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410
Sarah Chin4beb2b72023-02-14 14:47:54 -0800411 private final PhoneGlobals mApp;
Sarah Chincc5446f2023-10-23 17:57:19 -0700412 private final FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800413 private final CallManager mCM;
414 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000415
416 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800417 private final UserManager mUserManager;
418 private final AppOpsManager mAppOps;
419 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800420 private final SharedPreferences mTelephonySharedPreferences;
421 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800422 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Peter Wangdafb9ac2020-01-15 14:13:38 -0800424 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800425 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800426 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
427
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800429
Derek Tan97ebb422014-09-05 16:55:38 -0700430 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
431 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800432 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800433 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700434
Michelecea4cf22018-12-21 15:00:11 -0800435 // String to store multi SIM allowed
436 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
437
Derek Tan740e1672017-06-27 14:56:27 -0700438 // The AID of ISD-R.
439 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
440
yinxub1bed742017-04-17 11:45:04 -0700441 private NetworkScanRequestTracker mNetworkScanRequestTracker;
442
David Kelly5e06a7f2018-03-12 14:10:59 +0000443 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
444 private static final int MANUFACTURER_CODE_LENGTH = 8;
445
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800446 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800447 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800448
Sarah Chin2ec39f62022-08-31 17:03:26 -0700449 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
450 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
451
Derek Tan89e89d42014-07-08 17:00:10 -0700452 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700453 * Experiment flag to enable erase modem config on reset network, default value is false
454 */
455 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
456 "reset_network_erase_modem_config_enabled";
457
Rambo Wang0f050d82021-02-12 11:43:36 -0800458 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800459
Gary Jian76280a42022-12-07 16:18:33 +0800460 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
461
sandeepjsb6c87872021-09-27 15:34:44 +0000462 /**
463 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
464 * one ICCID active at the same time.
465 * Apps should use below API signatures if targeting SDK is T and beyond.
466 *
467 * @hide
468 */
469 @ChangeId
470 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
471 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800472
Naina Nallurid63128d2019-09-17 14:10:30 -0700473 /**
Chen Xu540470b2021-12-14 17:15:47 -0800474 * Apps targeting on Android T and beyond will get exception whenever icc close channel
475 * operation fails.
476 */
477 @ChangeId
478 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
479 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
480
481 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 * A request object to use for transmitting data to an ICC.
483 */
484 private static final class IccAPDUArgument {
485 public int channel, cla, command, p1, p2, p3;
486 public String data;
487
488 public IccAPDUArgument(int channel, int cla, int command,
489 int p1, int p2, int p3, String data) {
490 this.channel = channel;
491 this.cla = cla;
492 this.command = command;
493 this.p1 = p1;
494 this.p2 = p2;
495 this.p3 = p3;
496 this.data = data;
497 }
498 }
499
500 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700501 * A request object to use for transmitting data to an ICC.
502 */
503 private static final class ManualNetworkSelectionArgument {
504 public OperatorInfo operatorInfo;
505 public boolean persistSelection;
506
507 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
508 this.operatorInfo = operatorInfo;
509 this.persistSelection = persistSelection;
510 }
511 }
512
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 private static final class PurchasePremiumCapabilityArgument {
514 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700515 public @NonNull IIntegerConsumer callback;
516
517 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800518 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700519 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700520 this.callback = callback;
521 }
522 }
523
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700524 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
526 * request after sending. The main thread will notify the request when it is complete.
527 */
528 private static final class MainThreadRequest {
529 /** The argument to use for the request */
530 public Object argument;
531 /** The result of the request that is run on the main thread */
532 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800533 // The subscriber id that this request applies to. Defaults to
534 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
535 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536
Nathan Harold92bed182018-10-12 18:16:49 -0700537 // In cases where subId is unavailable, the caller needs to specify the phone.
538 public Phone phone;
539
vagdeviaf9a5b92018-08-15 16:01:53 -0700540 public WorkSource workSource;
541
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 public MainThreadRequest(Object argument) {
543 this.argument = argument;
544 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800545
Nathan Harold92bed182018-10-12 18:16:49 -0700546 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
547 this.argument = argument;
548 if (phone != null) {
549 this.phone = phone;
550 }
551 this.workSource = workSource;
552 }
553
vagdeviaf9a5b92018-08-15 16:01:53 -0700554 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800555 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800556 if (subId != null) {
557 this.subId = subId;
558 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700559 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700561 }
562
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800563 private static final class IncomingThirdPartyCallArgs {
564 public final ComponentName component;
565 public final String callId;
566 public final String callerDisplayName;
567
568 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
569 String callerDisplayName) {
570 this.component = component;
571 this.callId = callId;
572 this.callerDisplayName = callerDisplayName;
573 }
574 }
575
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 /**
577 * A handler that processes messages on the main thread in the phone process. Since many
578 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
579 * inbound binder threads to the main thread in the phone process. The Binder thread
580 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
581 * on, which will be notified when the operation completes and will contain the result of the
582 * request.
583 *
584 * <p>If a MainThreadRequest object is provided in the msg.obj field,
585 * note that request.result must be set to something non-null for the calling thread to
586 * unblock.
587 */
588 private final class MainThreadHandler extends Handler {
589 @Override
590 public void handleMessage(Message msg) {
591 MainThreadRequest request;
592 Message onCompleted;
593 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000594 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800596 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597
598 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 case CMD_HANDLE_USSD_REQUEST: {
600 request = (MainThreadRequest) msg.obj;
601 final Phone phone = getPhoneFromRequest(request);
602 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800603 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700605
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 if (!isUssdApiAllowed(request.subId)) {
607 // Carrier does not support use of this API, return failure.
608 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
609 UssdResponse response = new UssdResponse(ussdRequest, null);
610 Bundle returnData = new Bundle();
611 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
612 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700613
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 request.result = true;
615 notifyRequester(request);
616 return;
617 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700618
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 try {
620 request.result = phone != null
621 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
622 } catch (CallStateException cse) {
623 request.result = false;
624 }
625 // Wake up the requesting thread
626 notifyRequester(request);
627 break;
pkanwar32d516d2016-10-14 19:37:38 -0700628 }
629
Yorke Lee716f67e2015-06-17 15:39:16 -0700630 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700632 final Phone phone = getPhoneFromRequest(request);
633 request.result = phone != null ?
634 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
635 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700638 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700640
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000644 uiccPort = getUiccPortFromRequest(request);
645 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800651 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000652 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800653 iccArgument.channel, iccArgument.cla, iccArgument.command,
654 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
655 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 break;
658
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result;
664 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 if (ar.result == null) {
667 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800668 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800670 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
672 loge("iccTransmitApduLogicalChannel: Unknown exception");
673 }
674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
679 request = (MainThreadRequest) msg.obj;
680 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000681 uiccPort = getUiccPortFromRequest(request);
682 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800684 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800688 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800690 iccArgument.cla, iccArgument.command, iccArgument.p1,
691 iccArgument.p2,
692 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 }
694 break;
695
696 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
697 ar = (AsyncResult) msg.obj;
698 request = (MainThreadRequest) ar.userObj;
699 if (ar.exception == null && ar.result != null) {
700 request.result = ar.result;
701 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800702 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 if (ar.result == null) {
704 loge("iccTransmitApduBasicChannel: Empty response");
705 } else if (ar.exception instanceof CommandException) {
706 loge("iccTransmitApduBasicChannel: CommandException: " +
707 ar.exception);
708 } else {
709 loge("iccTransmitApduBasicChannel: Unknown exception");
710 }
711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 break;
714
715 case CMD_EXCHANGE_SIM_IO:
716 request = (MainThreadRequest) msg.obj;
717 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000718 uiccPort = getUiccPortFromRequest(request);
719 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800721 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 } else {
724 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
725 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000726 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
728 iccArgument.data, onCompleted);
729 }
730 break;
731
732 case EVENT_EXCHANGE_SIM_IO_DONE:
733 ar = (AsyncResult) msg.obj;
734 request = (MainThreadRequest) ar.userObj;
735 if (ar.exception == null && ar.result != null) {
736 request.result = ar.result;
737 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800738 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 break;
742
Derek Tan4d5e5c12014-02-04 11:54:58 -0800743 case CMD_SEND_ENVELOPE:
744 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000745 uiccPort = getUiccPortFromRequest(request);
746 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800748 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800752 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700753 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800754 break;
755
756 case EVENT_SEND_ENVELOPE_DONE:
757 ar = (AsyncResult) msg.obj;
758 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700759 if (ar.exception == null && ar.result != null) {
760 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800761 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800762 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700763 if (ar.result == null) {
764 loge("sendEnvelopeWithStatus: Empty response");
765 } else if (ar.exception instanceof CommandException) {
766 loge("sendEnvelopeWithStatus: CommandException: " +
767 ar.exception);
768 } else {
769 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
770 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800771 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800773 break;
774
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 case CMD_OPEN_CHANNEL:
776 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000777 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800778 IccLogicalChannelRequest openChannelRequest =
779 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000780 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800782 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800783 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700785 } else {
786 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800787 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
788 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700789 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 break;
791
792 case EVENT_OPEN_CHANNEL_DONE:
793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700795 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700797 int[] result = (int[]) ar.result;
798 int channelId = result[0];
799 byte[] selectResponse = null;
800 if (result.length > 1) {
801 selectResponse = new byte[result.length - 1];
802 for (int i = 1; i < result.length; ++i) {
803 selectResponse[i - 1] = (byte) result[i];
804 }
805 }
806 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800807 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800808
809 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700810 if (uiccPort == null) {
811 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
812 } else {
813 IccLogicalChannelRequest channelRequest =
814 (IccLogicalChannelRequest) request.argument;
815 channelRequest.channel = channelId;
816 uiccPort.onLogicalChannelOpened(channelRequest);
817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700818 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 if (ar.result == null) {
820 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700822 if (ar.exception != null) {
823 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
824 }
825
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700826 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700827 if (ar.exception instanceof CommandException) {
828 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800829 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700830 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700831 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700832 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700833 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700834 }
835 }
836 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800837 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700839 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700840 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 break;
842
843 case CMD_CLOSE_CHANNEL:
844 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000845 uiccPort = getUiccPortFromRequest(request);
846 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700847 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800848 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800849 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800850 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700851 } else {
852 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000853 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700854 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 break;
856
857 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800858 ar = (AsyncResult) msg.obj;
859 request = (MainThreadRequest) ar.userObj;
860 if (ar.exception == null) {
861 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800862 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700863 if (uiccPort == null) {
864 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
865 } else {
866 final int channelId = (Integer) request.argument;
867 uiccPort.onLogicalChannelClosed(channelId);
868 }
Chen Xu540470b2021-12-14 17:15:47 -0800869 } else {
870 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800871 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800872 if (ar.exception instanceof CommandException) {
873 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
874 CommandException.Error error =
875 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800876 if (error == CommandException.Error.INVALID_ARGUMENTS) {
877 // should only throw exceptions from the binder threads.
878 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800879 "iccCloseLogicalChannel: invalid argument ");
880 }
881 } else {
882 loge("iccCloseLogicalChannel: Unknown exception");
883 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800884 request.result = (exception != null) ? exception :
885 new IllegalStateException(
886 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800887 }
888 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800889 break;
890
891 case CMD_NV_READ_ITEM:
892 request = (MainThreadRequest) msg.obj;
893 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800894 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
895 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800896 break;
897
898 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700903 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800904 request.result = "";
905 if (ar.result == null) {
906 loge("nvReadItem: Empty response");
907 } else if (ar.exception instanceof CommandException) {
908 loge("nvReadItem: CommandException: " +
909 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700910 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800911 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700915 break;
916
Jake Hambye994d462014-02-03 13:10:13 -0800917 case CMD_NV_WRITE_ITEM:
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
920 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700922 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800923 break;
924
925 case EVENT_NV_WRITE_ITEM_DONE:
926 handleNullReturnEvent(msg, "nvWriteItem");
927 break;
928
929 case CMD_NV_WRITE_CDMA_PRL:
930 request = (MainThreadRequest) msg.obj;
931 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800932 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800933 break;
934
935 case EVENT_NV_WRITE_CDMA_PRL_DONE:
936 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
937 break;
938
chen xu6dac5ab2018-10-26 17:39:23 -0700939 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800940 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700941 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800942 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800943 break;
944
chen xu6dac5ab2018-10-26 17:39:23 -0700945 case EVENT_RESET_MODEM_CONFIG_DONE:
946 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800947 break;
948
Sooraj Sasindran37444802020-08-11 10:40:43 -0700949 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
952 request);
953 Phone phone = getPhoneFromRequest(request);
954 if (phone != null) {
955 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
956 } else {
957 loge("isNRDualConnectivityEnabled: No phone object");
958 request.result = false;
959 notifyRequester(request);
960 }
961 break;
962 }
963
964 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception == null && ar.result != null) {
968 request.result = ar.result;
969 } else {
970 // request.result must be set to something non-null
971 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700972 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700973 request.result = ar.result;
974 } else {
975 request.result = false;
976 }
977 if (ar.result == null) {
978 loge("isNRDualConnectivityEnabled: Empty response");
979 } else if (ar.exception instanceof CommandException) {
980 loge("isNRDualConnectivityEnabled: CommandException: "
981 + ar.exception);
982 } else {
983 loge("isNRDualConnectivityEnabled: Unknown exception");
984 }
985 }
986 notifyRequester(request);
987 break;
988
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700989 case CMD_IS_VONR_ENABLED: {
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
992 request);
993 Phone phone = getPhoneFromRequest(request);
994 if (phone != null) {
995 phone.isVoNrEnabled(onCompleted, request.workSource);
996 } else {
997 loge("isVoNrEnabled: No phone object");
998 request.result = false;
999 notifyRequester(request);
1000 }
1001 break;
1002 }
1003
1004 case EVENT_IS_VONR_ENABLED_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception == null && ar.result != null) {
1008 request.result = ar.result;
1009 } else {
1010 // request.result must be set to something non-null
1011 // for the calling thread to unblock
1012 if (ar.result != null) {
1013 request.result = ar.result;
1014 } else {
1015 request.result = false;
1016 }
1017 if (ar.result == null) {
1018 loge("isVoNrEnabled: Empty response");
1019 } else if (ar.exception instanceof CommandException) {
1020 loge("isVoNrEnabled: CommandException: "
1021 + ar.exception);
1022 } else {
1023 loge("isVoNrEnabled: Unknown exception");
1024 }
1025 }
1026 notifyRequester(request);
1027 break;
1028
Sooraj Sasindran37444802020-08-11 10:40:43 -07001029 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1032 Phone phone = getPhoneFromRequest(request);
1033 if (phone != null) {
1034 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1035 request.workSource);
1036 } else {
1037 loge("enableNrDualConnectivity: No phone object");
1038 request.result =
1039 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1040 notifyRequester(request);
1041 }
1042 break;
1043 }
1044
1045 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1046 ar = (AsyncResult) msg.obj;
1047 request = (MainThreadRequest) ar.userObj;
1048 if (ar.exception == null) {
1049 request.result =
1050 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1051 } else {
1052 request.result =
1053 TelephonyManager
1054 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1055 if (ar.exception instanceof CommandException) {
1056 CommandException.Error error =
1057 ((CommandException) (ar.exception)).getCommandError();
1058 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1059 request.result =
1060 TelephonyManager
1061 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001062 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1063 request.result =
1064 TelephonyManager
1065 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001066 }
1067 loge("enableNrDualConnectivity" + ": CommandException: "
1068 + ar.exception);
1069 } else {
1070 loge("enableNrDualConnectivity" + ": Unknown exception");
1071 }
1072 }
1073 notifyRequester(request);
1074 break;
1075 }
1076
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001077 case CMD_ENABLE_VONR: {
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1080 Phone phone = getPhoneFromRequest(request);
1081 if (phone != null) {
1082 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1083 request.workSource);
1084 } else {
1085 loge("setVoNrEnabled: No phone object");
1086 request.result =
1087 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1088 notifyRequester(request);
1089 }
1090 break;
1091 }
1092
1093 case EVENT_ENABLE_VONR_DONE: {
1094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
1096 if (ar.exception == null) {
1097 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1098 } else {
1099 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1100 if (ar.exception instanceof CommandException) {
1101 CommandException.Error error =
1102 ((CommandException) (ar.exception)).getCommandError();
1103 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1104 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1105 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1106 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1107 } else {
1108 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1109 }
1110 loge("setVoNrEnabled" + ": CommandException: "
1111 + ar.exception);
1112 } else {
1113 loge("setVoNrEnabled" + ": Unknown exception");
1114 }
1115 }
1116 notifyRequester(request);
1117 break;
1118 }
1119
SongFerngWang3ef3e072020-12-21 16:41:52 +08001120 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001121 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001122 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1123 request);
1124 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001125 break;
1126
SongFerngWang3ef3e072020-12-21 16:41:52 +08001127 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
1130 if (ar.exception == null && ar.result != null) {
1131 request.result = ar.result; // Integer
1132 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301133 // request.result must be set to something non-null
1134 // for the calling thread to unblock
1135 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001139 loge("getAllowedNetworkTypesBitmask: CommandException: "
1140 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 }
1144 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001145 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 break;
1147
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001149 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001150 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1151 request);
1152 Pair<Integer, Long> reasonWithNetworkTypes =
1153 (Pair<Integer, Long>) request.argument;
1154 getPhoneFromRequest(request).setAllowedNetworkTypes(
1155 reasonWithNetworkTypes.first,
1156 reasonWithNetworkTypes.second,
1157 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 break;
1159
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1161 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 break;
1163
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001164 case CMD_SET_VOICEMAIL_NUMBER:
1165 request = (MainThreadRequest) msg.obj;
1166 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1167 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001168 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1169 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001170 break;
1171
1172 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1173 handleNullReturnEvent(msg, "setVoicemailNumber");
1174 break;
1175
Stuart Scott54788802015-03-30 13:18:01 -07001176 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1177 request = (MainThreadRequest) msg.obj;
1178 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1179 request);
1180 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1181 break;
1182
1183 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1184 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1185 break;
1186
Shishir Agrawal302c8692015-06-19 13:49:39 -07001187 case CMD_PERFORM_NETWORK_SCAN:
1188 request = (MainThreadRequest) msg.obj;
1189 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1190 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1191 break;
1192
Hall Liu27d24262020-09-18 19:04:59 -07001193 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001194 request = (MainThreadRequest) msg.obj;
1195 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001196 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1197 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1198 request.argument;
1199 int callForwardingReason = args.first;
1200 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001201 break;
Hall Liu27d24262020-09-18 19:04:59 -07001202 }
1203 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001204 ar = (AsyncResult) msg.obj;
1205 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001206 TelephonyManager.CallForwardingInfoCallback callback =
1207 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1208 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001210 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001211 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1212 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1213 // Service Class is a bit mask per 3gpp 27.007. Search for
1214 // any service for voice call.
1215 if ((callForwardInfo.serviceClass
1216 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001217 callForwardingInfo = new CallForwardingInfo(
1218 callForwardInfo.status
1219 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001220 callForwardInfo.reason,
1221 callForwardInfo.number,
1222 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001223 break;
1224 }
1225 }
1226 // Didn't find a call forward info for voice call.
1227 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001228 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1229 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 }
Hall Liu27d24262020-09-18 19:04:59 -07001231 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 } else {
1233 if (ar.result == null) {
1234 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1235 }
1236 if (ar.exception != null) {
1237 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1238 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 int errorCode = TelephonyManager
1240 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 if (ar.exception instanceof CommandException) {
1242 CommandException.Error error =
1243 ((CommandException) (ar.exception)).getCommandError();
1244 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001245 errorCode = TelephonyManager
1246 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001247 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager
1249 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001250 }
1251 }
Hall Liu27d24262020-09-18 19:04:59 -07001252 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 }
Shuo Qian4a594052020-01-23 11:59:30 -08001254 break;
Hall Liu27d24262020-09-18 19:04:59 -07001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256
Hall Liu27d24262020-09-18 19:04:59 -07001257 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001258 request = (MainThreadRequest) msg.obj;
1259 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001260 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001261 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001262 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1263 request.argument).first;
1264 request.phone.setCallForwardingOption(
1265 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001266 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001267 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001268 callForwardingInfoToSet.getReason(),
1269 callForwardingInfoToSet.getNumber(),
1270 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1271 break;
Hall Liu27d24262020-09-18 19:04:59 -07001272 }
Shuo Qian4a594052020-01-23 11:59:30 -08001273
Hall Liu27d24262020-09-18 19:04:59 -07001274 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001277 Consumer<Integer> callback =
1278 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1279 request.argument).second;
1280 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001281 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001282 int errorCode = TelephonyManager.CallForwardingInfoCallback
1283 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001284 if (ar.exception instanceof CommandException) {
1285 CommandException.Error error =
1286 ((CommandException) (ar.exception)).getCommandError();
1287 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001288 errorCode = TelephonyManager.CallForwardingInfoCallback
1289 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001290 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001291 errorCode = TelephonyManager.CallForwardingInfoCallback
1292 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
1294 }
1295 callback.accept(errorCode);
1296 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001297 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001298 }
Shuo Qian4a594052020-01-23 11:59:30 -08001299 break;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
Shuo Qian4a594052020-01-23 11:59:30 -08001301
Hall Liu27d24262020-09-18 19:04:59 -07001302 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001303 request = (MainThreadRequest) msg.obj;
1304 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1305 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1306 break;
Hall Liu27d24262020-09-18 19:04:59 -07001307 }
Shuo Qian4a594052020-01-23 11:59:30 -08001308
Hall Liu27d24262020-09-18 19:04:59 -07001309 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001312 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001313 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001314 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001315 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001316 // Service Class is a bit mask per 3gpp 27.007.
1317 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001318 if (callForwardResults.length > 1
1319 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001320 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001321 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001322 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1323 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001324 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001325 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001326 }
1327 } else {
1328 if (ar.result == null) {
1329 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1330 }
1331 if (ar.exception != null) {
1332 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1333 }
1334 if (ar.exception instanceof CommandException) {
1335 CommandException.Error error =
1336 ((CommandException) (ar.exception)).getCommandError();
1337 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001339 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1341 callWaitingStatus =
1342 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001343 }
1344 }
1345 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001347 break;
Hall Liu27d24262020-09-18 19:04:59 -07001348 }
Shuo Qian4a594052020-01-23 11:59:30 -08001349
Hall Liu27d24262020-09-18 19:04:59 -07001350 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001351 request = (MainThreadRequest) msg.obj;
1352 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001353 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1354 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001355 break;
Hall Liu27d24262020-09-18 19:04:59 -07001356 }
Shuo Qian4a594052020-01-23 11:59:30 -08001357
Hall Liu27d24262020-09-18 19:04:59 -07001358 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001359 ar = (AsyncResult) msg.obj;
1360 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001361 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1362 Consumer<Integer> callback =
1363 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1364 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001365 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001366 if (ar.exception instanceof CommandException) {
1367 CommandException.Error error =
1368 ((CommandException) (ar.exception)).getCommandError();
1369 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1370 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001371 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1372 callback.accept(
1373 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001374 } else {
1375 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1376 }
1377 } else {
1378 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1379 }
1380 } else {
1381 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1382 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001383 }
Shuo Qian4a594052020-01-23 11:59:30 -08001384 break;
Hall Liu27d24262020-09-18 19:04:59 -07001385 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001386 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1387 ar = (AsyncResult) msg.obj;
1388 request = (MainThreadRequest) ar.userObj;
1389 CellNetworkScanResult cellScanResult;
1390 if (ar.exception == null && ar.result != null) {
1391 cellScanResult = new CellNetworkScanResult(
1392 CellNetworkScanResult.STATUS_SUCCESS,
1393 (List<OperatorInfo>) ar.result);
1394 } else {
1395 if (ar.result == null) {
1396 loge("getCellNetworkScanResults: Empty response");
1397 }
1398 if (ar.exception != null) {
1399 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1400 }
1401 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1402 if (ar.exception instanceof CommandException) {
1403 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001404 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001405 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1406 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1407 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1408 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1409 }
1410 }
1411 cellScanResult = new CellNetworkScanResult(errorCode, null);
1412 }
1413 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001414 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001415 break;
1416
1417 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1418 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001419 ManualNetworkSelectionArgument selArg =
1420 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001421 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1422 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001423 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1424 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001425 break;
1426
1427 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 if (ar.exception == null) {
1431 request.result = true;
1432 } else {
1433 request.result = false;
1434 loge("setNetworkSelectionModeManual " + ar.exception);
1435 }
1436 notifyRequester(request);
1437 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001438 break;
1439
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001440 case CMD_GET_MODEM_ACTIVITY_INFO:
1441 request = (MainThreadRequest) msg.obj;
1442 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001443 if (defaultPhone != null) {
1444 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001445 } else {
1446 ResultReceiver result = (ResultReceiver) request.argument;
1447 Bundle bundle = new Bundle();
1448 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001449 new ModemActivityInfo(0, 0, 0,
1450 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001452 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001453 break;
1454
Hall Liud0f208c2020-10-14 16:54:44 -07001455 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001459 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001460 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001461 if (mLastModemActivityInfo == null) {
1462 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1463 mLastModemActivitySpecificInfo[0] =
1464 new ActivityStatsTechSpecificInfo(
1465 0,
1466 0,
1467 new int[ModemActivityInfo.getNumTxPowerLevels()],
1468 0);
1469 mLastModemActivityInfo =
1470 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1471 }
1472
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001474 // Update the last modem activity info and the result of the request.
1475 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1476 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001477 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001478 } else {
1479 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001480 }
Kai Shi917fdc62022-11-28 14:01:02 -08001481 // This is needed to decouple ret from mLastModemActivityInfo
1482 // We don't want to return mLastModemActivityInfo which is updated
1483 // inside mergeModemActivityInfo()
1484 ret = new ModemActivityInfo(
1485 mLastModemActivityInfo.getTimestampMillis(),
1486 mLastModemActivityInfo.getSleepTimeMillis(),
1487 mLastModemActivityInfo.getIdleTimeMillis(),
1488 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001489
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490 } else {
1491 if (ar.result == null) {
1492 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001493 error = TelephonyManager.ModemActivityInfoException
1494 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001495 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001496 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001497 error = TelephonyManager.ModemActivityInfoException
1498 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001499 } else {
1500 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001501 error = TelephonyManager.ModemActivityInfoException
1502 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001503 }
1504 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001505 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001506 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001507 bundle.putParcelable(
1508 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001509 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001510 } else {
1511 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1512 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001513 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001514 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001516 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001518 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001520 CarrierRestrictionRules argument =
1521 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001523 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001525 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526
1527 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null && ar.result != null) {
1531 request.result = ar.result;
1532 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001533 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1534 if (ar.exception instanceof CommandException) {
1535 loge("setAllowedCarriers: CommandException: " + ar.exception);
1536 CommandException.Error error =
1537 ((CommandException) (ar.exception)).getCommandError();
1538 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1539 request.result =
1540 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1541 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 } else {
1543 loge("setAllowedCarriers: Unknown exception");
1544 }
1545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001546 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 break;
1548
1549 case CMD_GET_ALLOWED_CARRIERS:
1550 request = (MainThreadRequest) msg.obj;
1551 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001552 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001553 break;
1554
1555 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1556 ar = (AsyncResult) msg.obj;
1557 request = (MainThreadRequest) ar.userObj;
1558 if (ar.exception == null && ar.result != null) {
1559 request.result = ar.result;
1560 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001561 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001562 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 if (ar.result == null) {
1564 loge("getAllowedCarriers: Empty response");
1565 } else if (ar.exception instanceof CommandException) {
1566 loge("getAllowedCarriers: CommandException: " +
1567 ar.exception);
1568 } else {
1569 loge("getAllowedCarriers: Unknown exception");
1570 }
1571 }
arunvoddud7401012022-12-15 16:08:12 +00001572 if (request.argument != null) {
1573 // This is for the implementation of carrierRestrictionStatus.
1574 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1575 Consumer<Integer> callback = callbackInfo.getConsumer();
1576 int callerCarrierId = callbackInfo.getCarrierId();
1577 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1578 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1579 CarrierRestrictionRules carrierRestrictionRules =
1580 (CarrierRestrictionRules) ar.result;
1581 int carrierId = -1;
1582 try {
1583 CarrierIdentifier carrierIdentifier =
1584 carrierRestrictionRules.getAllowedCarriers().get(0);
1585 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1586 carrierIdentifier);
1587 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1588 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1589 }
1590 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1591 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1592 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001593 lockStatus = TelephonyManager
1594 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001595 }
1596 } else {
1597 Rlog.e(LOG_TAG,
1598 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1599 }
1600 callback.accept(lockStatus);
1601 } else {
1602 // This is for the implementation of getAllowedCarriers.
1603 notifyRequester(request);
1604 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001605 break;
1606
Nathan Haroldb3014052017-01-25 15:57:32 -08001607 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1608 ar = (AsyncResult) msg.obj;
1609 request = (MainThreadRequest) ar.userObj;
1610 if (ar.exception == null && ar.result != null) {
1611 request.result = ar.result;
1612 } else {
1613 request.result = new IllegalArgumentException(
1614 "Failed to retrieve Forbidden Plmns");
1615 if (ar.result == null) {
1616 loge("getForbiddenPlmns: Empty response");
1617 } else {
1618 loge("getForbiddenPlmns: Unknown exception");
1619 }
1620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001621 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001622 break;
1623
1624 case CMD_GET_FORBIDDEN_PLMNS:
1625 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001626 uiccPort = getUiccPortFromRequest(request);
1627 if (uiccPort == null) {
1628 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001630 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001631 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001632 break;
1633 }
1634 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001635 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001636 if (uiccApp == null) {
1637 loge("getForbiddenPlmns() no app with specified type -- "
1638 + appType);
1639 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001641 break;
1642 } else {
1643 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1644 + " specified type -- " + appType);
1645 }
1646 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1647 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001648 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001649 break;
1650
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001651 case CMD_SWITCH_SLOTS:
1652 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001653 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001654 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001655 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001656 break;
1657
1658 case EVENT_SWITCH_SLOTS_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001662 notifyRequester(request);
1663 break;
1664 case CMD_GET_NETWORK_SELECTION_MODE:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1667 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1668 break;
1669
1670 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1671 ar = (AsyncResult) msg.obj;
1672 request = (MainThreadRequest) ar.userObj;
1673 if (ar.exception != null) {
1674 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1675 } else {
1676 int mode = ((int[]) ar.result)[0];
1677 if (mode == 0) {
1678 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1679 } else {
1680 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1681 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001683 notifyRequester(request);
1684 break;
1685 case CMD_GET_CDMA_ROAMING_MODE:
1686 request = (MainThreadRequest) msg.obj;
1687 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1688 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1689 break;
1690 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1691 ar = (AsyncResult) msg.obj;
1692 request = (MainThreadRequest) ar.userObj;
1693 if (ar.exception != null) {
1694 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1695 } else {
1696 request.result = ((int[]) ar.result)[0];
1697 }
1698 notifyRequester(request);
1699 break;
1700 case CMD_SET_CDMA_ROAMING_MODE:
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1703 int mode = (int) request.argument;
1704 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1705 break;
1706 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1707 ar = (AsyncResult) msg.obj;
1708 request = (MainThreadRequest) ar.userObj;
1709 request.result = ar.exception == null;
1710 notifyRequester(request);
1711 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001712 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1715 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1716 break;
1717 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1718 ar = (AsyncResult) msg.obj;
1719 request = (MainThreadRequest) ar.userObj;
1720 if (ar.exception != null) {
1721 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1722 } else {
1723 request.result = ((int[]) ar.result)[0];
1724 }
1725 notifyRequester(request);
1726 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001727 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1730 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001731 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1732 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001733 break;
1734 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 request.result = ar.exception == null;
1738 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001739 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 case CMD_GET_ALL_CELL_INFO:
1741 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001743 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001744 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 case EVENT_GET_ALL_CELL_INFO_DONE:
1746 ar = (AsyncResult) msg.obj;
1747 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001748 // If a timeout occurs, the response will be null
1749 request.result = (ar.exception == null && ar.result != null)
1750 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 synchronized (request) {
1752 request.notifyAll();
1753 }
1754 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001755 case CMD_REQUEST_CELL_INFO_UPDATE:
1756 request = (MainThreadRequest) msg.obj;
1757 request.phone.requestCellInfoUpdate(request.workSource,
1758 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1759 break;
1760 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1761 ar = (AsyncResult) msg.obj;
1762 request = (MainThreadRequest) ar.userObj;
1763 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1764 try {
1765 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001766 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001767 cb.onError(
1768 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1769 ar.exception.getClass().getName(),
1770 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001771 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001772 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001773 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001774 } else {
1775 // use the result as returned
1776 cb.onCellInfo((List<CellInfo>) ar.result);
1777 }
1778 } catch (RemoteException re) {
1779 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1780 }
1781 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001782 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001783 request = (MainThreadRequest) msg.obj;
1784 WorkSource ws = (WorkSource) request.argument;
1785 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001786 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001787 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001788 }
1789 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 ar = (AsyncResult) msg.obj;
1791 request = (MainThreadRequest) ar.userObj;
1792 if (ar.exception == null) {
1793 request.result = ar.result;
1794 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001796 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001797 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001798 }
1799
1800 synchronized (request) {
1801 request.notifyAll();
1802 }
1803 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001804 }
chen xu6dac5ab2018-10-26 17:39:23 -07001805 case CMD_MODEM_REBOOT:
1806 request = (MainThreadRequest) msg.obj;
1807 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001808 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001809 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001810 case EVENT_CMD_MODEM_REBOOT_DONE:
1811 handleNullReturnEvent(msg, "rebootModem");
1812 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001813 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001814 request = (MainThreadRequest) msg.obj;
1815 boolean enable = (boolean) request.argument;
1816 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001817 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001818 PhoneConfigurationManager.getInstance()
1819 .enablePhone(request.phone, enable, onCompleted);
1820 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001821 }
Michele Berionne5e411512020-11-13 02:36:59 +00001822 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001823 ar = (AsyncResult) msg.obj;
1824 request = (MainThreadRequest) ar.userObj;
1825 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001826 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001827 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001828 if ((boolean) request.result) {
1829 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1830 updateModemStateMetrics();
1831 } else {
1832 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1833 + ar.exception);
1834 }
1835 notifyRequester(request);
1836 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001837 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001838 case CMD_GET_MODEM_STATUS:
1839 request = (MainThreadRequest) msg.obj;
1840 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1841 PhoneConfigurationManager.getInstance()
1842 .getPhoneStatusFromModem(request.phone, onCompleted);
1843 break;
1844 case EVENT_GET_MODEM_STATUS_DONE:
1845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 int id = request.phone.getPhoneId();
1848 if (ar.exception == null && ar.result != null) {
1849 request.result = ar.result;
1850 //update the cache as modem status has changed
1851 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1852 (boolean) request.result);
1853 } else {
1854 // Return true if modem status cannot be retrieved. For most cases,
1855 // modem status is on. And for older version modems, GET_MODEM_STATUS
1856 // and disable modem are not supported. Modem is always on.
1857 // TODO: this should be fixed in R to support a third
1858 // status UNKNOWN b/131631629
1859 request.result = true;
1860 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1861 + ar.exception);
1862 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001863 notifyRequester(request);
1864 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001865 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1866 request = (MainThreadRequest) msg.obj;
1867 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1868 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1869 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1870 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1871 break;
1872 }
1873 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1874 ar = (AsyncResult) msg.obj;
1875 request = (MainThreadRequest) ar.userObj;
1876 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1877 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1878 args.second.accept(ar.exception == null);
1879 notifyRequester(request);
1880 break;
1881 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001882 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1883 request = (MainThreadRequest) msg.obj;
1884 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1885 Phone phone = getPhoneFromRequest(request);
1886 if (phone != null) {
1887 phone.getSystemSelectionChannels(onCompleted);
1888 } else {
1889 loge("getSystemSelectionChannels: No phone object");
1890 request.result = new ArrayList<RadioAccessSpecifier>();
1891 notifyRequester(request);
1892 }
1893 break;
1894 }
1895 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 if (ar.exception == null && ar.result != null) {
1899 request.result = ar.result;
1900 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001901 request.result = new IllegalStateException(
1902 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001903 if (ar.result == null) {
1904 loge("getSystemSelectionChannels: Empty response");
1905 } else {
1906 loge("getSystemSelectionChannels: Unknown exception");
1907 }
1908 }
1909 notifyRequester(request);
1910 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001911 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914 if (ar.exception == null && ar.result != null) {
1915 request.result = ar.result;
1916 } else {
1917 request.result = -1;
1918 loge("Failed to set Forbidden Plmns");
1919 if (ar.result == null) {
1920 loge("setForbidenPlmns: Empty response");
1921 } else if (ar.exception != null) {
1922 loge("setForbiddenPlmns: Exception: " + ar.exception);
1923 request.result = -1;
1924 } else {
1925 loge("setForbiddenPlmns: Unknown exception");
1926 }
1927 }
1928 notifyRequester(request);
1929 break;
1930 case CMD_SET_FORBIDDEN_PLMNS:
1931 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001932 uiccPort = getUiccPortFromRequest(request);
1933 if (uiccPort == null) {
1934 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001935 request.result = -1;
1936 notifyRequester(request);
1937 break;
1938 }
1939 Pair<Integer, List<String>> setFplmnsArgs =
1940 (Pair<Integer, List<String>>) request.argument;
1941 appType = setFplmnsArgs.first;
1942 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001943 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001944 if (uiccApp == null) {
1945 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1946 request.result = -1;
1947 loge("Failed to get UICC App");
1948 notifyRequester(request);
1949 } else {
1950 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1951 ((SIMRecords) uiccApp.getIccRecords())
1952 .setForbiddenPlmns(onCompleted, fplmns);
1953 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001954 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001955 case CMD_ERASE_MODEM_CONFIG:
1956 request = (MainThreadRequest) msg.obj;
1957 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1958 defaultPhone.eraseModemConfig(onCompleted);
1959 break;
1960 case EVENT_ERASE_MODEM_CONFIG_DONE:
1961 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001962 break;
zoey chene02881a2019-12-30 16:11:23 +08001963
Kai Shif70f46f2021-03-03 13:59:46 -08001964 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1965 request = (MainThreadRequest) msg.obj;
1966 request.result = defaultPhone.eraseDataInSharedPreferences();
1967 notifyRequester(request);
1968 break;
1969
zoey chene02881a2019-12-30 16:11:23 +08001970 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1973 Pair<String, String> changed = (Pair<String, String>) request.argument;
1974 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1975 changed.first, changed.second, onCompleted);
1976 break;
1977 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1978 ar = (AsyncResult) msg.obj;
1979 request = (MainThreadRequest) ar.userObj;
1980 if (ar.exception == null) {
1981 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001982 // If the operation is successful, update the PIN storage
1983 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1984 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001985 UiccController.getInstance().getPinStorage()
1986 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001987 } else {
1988 request.result = msg.arg1;
1989 }
1990 notifyRequester(request);
1991 break;
1992
Michele Berionne5e411512020-11-13 02:36:59 +00001993 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001994 request = (MainThreadRequest) msg.obj;
1995 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1996 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1997 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1998 enabled.first, enabled.second, onCompleted);
1999 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002000 }
zoey chene02881a2019-12-30 16:11:23 +08002001 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2002 ar = (AsyncResult) msg.obj;
2003 request = (MainThreadRequest) ar.userObj;
2004 if (ar.exception == null) {
2005 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002006 // If the operation is successful, update the PIN storage
2007 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2008 int phoneId = getPhoneFromRequest(request).getPhoneId();
2009 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002010 UiccController.getInstance().getPinStorage()
2011 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002012 } else {
2013 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2014 }
zoey chene02881a2019-12-30 16:11:23 +08002015 } else {
2016 request.result = msg.arg1;
2017 }
Michele Berionne5e411512020-11-13 02:36:59 +00002018
2019
zoey chene02881a2019-12-30 16:11:23 +08002020 notifyRequester(request);
2021 break;
2022
Peter Wangdafb9ac2020-01-15 14:13:38 -08002023 case MSG_NOTIFY_USER_ACTIVITY:
2024 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002025 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002026 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2027 getDefaultPhone().getContext().sendBroadcastAsUser(
2028 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2029 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002030
2031 case CMD_SET_DATA_THROTTLING: {
2032 request = (MainThreadRequest) msg.obj;
2033 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2034 DataThrottlingRequest dataThrottlingRequest =
2035 (DataThrottlingRequest) request.argument;
2036 Phone phone = getPhoneFromRequest(request);
2037 if (phone != null) {
2038 phone.setDataThrottling(onCompleted,
2039 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2040 dataThrottlingRequest.getCompletionDurationMillis());
2041 } else {
2042 loge("setDataThrottling: No phone object");
2043 request.result =
2044 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2045 notifyRequester(request);
2046 }
2047
2048 break;
2049 }
2050 case EVENT_SET_DATA_THROTTLING_DONE:
2051 ar = (AsyncResult) msg.obj;
2052 request = (MainThreadRequest) ar.userObj;
2053
2054 if (ar.exception == null) {
2055 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2056 } else if (ar.exception instanceof CommandException) {
2057 loge("setDataThrottling: CommandException: " + ar.exception);
2058 CommandException.Error error =
2059 ((CommandException) (ar.exception)).getCommandError();
2060
2061 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2062 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002063 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002064 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2065 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002066 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2067 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002068 } else {
2069 request.result =
2070 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2071 }
2072 } else {
2073 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2074 }
2075 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2076 notifyRequester(request);
2077 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002078
2079 case CMD_SET_SIM_POWER: {
2080 request = (MainThreadRequest) msg.obj;
2081 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2082 request = (MainThreadRequest) msg.obj;
2083 int stateToSet =
2084 ((Pair<Integer, IIntegerConsumer>)
2085 request.argument).first;
2086 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2087 break;
2088 }
2089 case EVENT_SET_SIM_POWER_DONE: {
2090 ar = (AsyncResult) msg.obj;
2091 request = (MainThreadRequest) ar.userObj;
2092 IIntegerConsumer callback =
2093 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2094 if (ar.exception != null) {
2095 loge("setSimPower exception: " + ar.exception);
2096 int errorCode = TelephonyManager.CallForwardingInfoCallback
2097 .RESULT_ERROR_UNKNOWN;
2098 if (ar.exception instanceof CommandException) {
2099 CommandException.Error error =
2100 ((CommandException) (ar.exception)).getCommandError();
2101 if (error == CommandException.Error.SIM_ERR) {
2102 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2103 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2104 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2105 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2106 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2107 } else {
2108 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2109 }
2110 }
2111 try {
2112 callback.accept(errorCode);
2113 } catch (RemoteException e) {
2114 // Ignore if the remote process is no longer available to call back.
2115 Log.w(LOG_TAG, "setSimPower: callback not available.");
2116 }
2117 } else {
2118 try {
2119 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2120 } catch (RemoteException e) {
2121 // Ignore if the remote process is no longer available to call back.
2122 Log.w(LOG_TAG, "setSimPower: callback not available.");
2123 }
2124 }
2125 break;
2126 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002127 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2128 request = (MainThreadRequest) msg.obj;
2129
2130 final Phone phone = getPhoneFromRequest(request);
2131 if (phone == null || phone.getServiceStateTracker() == null) {
2132 request.result = new IllegalStateException("Phone or SST is null");
2133 notifyRequester(request);
2134 break;
2135 }
2136
2137 Pair<Integer, SignalStrengthUpdateRequest> pair =
2138 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2139 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2140 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002141 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002142 request.subId, pair.first /*callingUid*/,
2143 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002144 break;
2145 }
2146 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2147 ar = (AsyncResult) msg.obj;
2148 request = (MainThreadRequest) ar.userObj;
2149 // request.result will be the exception of ar if present, true otherwise.
2150 // Be cautious not to leave result null which will wait() forever
2151 request.result = ar.exception != null ? ar.exception : true;
2152 notifyRequester(request);
2153 break;
2154 }
2155 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2156 request = (MainThreadRequest) msg.obj;
2157
2158 Phone phone = getPhoneFromRequest(request);
2159 if (phone == null || phone.getServiceStateTracker() == null) {
2160 request.result = new IllegalStateException("Phone or SST is null");
2161 notifyRequester(request);
2162 break;
2163 }
2164
2165 Pair<Integer, SignalStrengthUpdateRequest> pair =
2166 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2167 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2168 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002169 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002170 request.subId, pair.first /*callingUid*/,
2171 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002172 break;
2173 }
2174 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2175 ar = (AsyncResult) msg.obj;
2176 request = (MainThreadRequest) ar.userObj;
2177 request.result = ar.exception != null ? ar.exception : true;
2178 notifyRequester(request);
2179 break;
2180 }
Jordan Liu109698e2020-11-24 14:50:34 -08002181
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002182 case CMD_GET_SLICING_CONFIG: {
2183 request = (MainThreadRequest) msg.obj;
2184 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2185 request.phone.getSlicingConfig(onCompleted);
2186 break;
2187 }
2188 case EVENT_GET_SLICING_CONFIG_DONE: {
2189 ar = (AsyncResult) msg.obj;
2190 request = (MainThreadRequest) ar.userObj;
2191 ResultReceiver result = (ResultReceiver) request.argument;
2192
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002193 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002194 Bundle bundle = new Bundle();
2195 int resultCode = 0;
2196 if (ar.exception != null) {
2197 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2198 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002199 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002200 } else if (ar.result == null) {
2201 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002202 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002203 } else {
2204 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002205 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2206 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002207 }
2208
2209 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002210 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002211 }
2212 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2213 result.send(resultCode, bundle);
2214 notifyRequester(request);
2215 break;
2216 }
2217
Sarah Chin71b3a852022-09-28 15:54:19 -07002218 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002219 request = (MainThreadRequest) msg.obj;
2220 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002221 PurchasePremiumCapabilityArgument arg =
2222 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002223 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2224 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002225 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002229 ar = (AsyncResult) msg.obj;
2230 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002231 PurchasePremiumCapabilityArgument arg =
2232 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002233 try {
2234 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002237 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002238 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239 + TelephonyManager.convertPurchaseResultToString(result));
2240 } catch (RemoteException e) {
2241 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 + " failed: " + e;
2244 if (DBG) log(logStr);
2245 AnomalyReporter.reportAnomaly(
2246 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2247 }
2248 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250
Michele Berionne5e411512020-11-13 02:36:59 +00002251 case CMD_PREPARE_UNATTENDED_REBOOT:
2252 request = (MainThreadRequest) msg.obj;
2253 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002254 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002255 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002256 notifyRequester(request);
2257 break;
2258
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 default:
2260 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2261 break;
2262 }
2263 }
Jake Hambye994d462014-02-03 13:10:13 -08002264
Pengquan Menga1bb6272018-09-06 09:59:22 -07002265 private void notifyRequester(MainThreadRequest request) {
2266 synchronized (request) {
2267 request.notifyAll();
2268 }
2269 }
2270
Jake Hambye994d462014-02-03 13:10:13 -08002271 private void handleNullReturnEvent(Message msg, String command) {
2272 AsyncResult ar = (AsyncResult) msg.obj;
2273 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2274 if (ar.exception == null) {
2275 request.result = true;
2276 } else {
2277 request.result = false;
2278 if (ar.exception instanceof CommandException) {
2279 loge(command + ": CommandException: " + ar.exception);
2280 } else {
2281 loge(command + ": Unknown exception");
2282 }
2283 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002284 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 }
2287
2288 /**
2289 * Posts the specified command to be executed on the main thread,
2290 * waits for the request to complete, and returns the result.
2291 * @see #sendRequestAsync
2292 */
2293 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002294 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2295 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002296 }
2297
2298 /**
2299 * Posts the specified command to be executed on the main thread,
2300 * waits for the request to complete, and returns the result.
2301 * @see #sendRequestAsync
2302 */
2303 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2304 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002305 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002306 }
2307
2308 /**
2309 * Posts the specified command to be executed on the main thread,
2310 * waits for the request to complete, and returns the result.
2311 * @see #sendRequestAsync
2312 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002313 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002314 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2315 }
2316
2317 /**
2318 * Posts the specified command to be executed on the main thread,
2319 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2320 * if not timeout or null otherwise.
2321 * @see #sendRequestAsync
2322 */
2323 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2324 long timeoutInMs) {
2325 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002326 }
2327
2328 /**
2329 * Posts the specified command to be executed on the main thread,
2330 * waits for the request to complete, and returns the result.
2331 * @see #sendRequestAsync
2332 */
Nathan Harold92bed182018-10-12 18:16:49 -07002333 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002334 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002335 }
2336
2337 /**
2338 * Posts the specified command to be executed on the main thread,
2339 * waits for the request to complete, and returns the result.
2340 * @see #sendRequestAsync
2341 */
2342 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002343 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2344 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002345 }
2346
2347 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002348 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2349 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2350 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002351 * @see #sendRequestAsync
2352 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002353 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2354 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2356 throw new RuntimeException("This method will deadlock if called from the main thread.");
2357 }
2358
Nathan Harold92bed182018-10-12 18:16:49 -07002359 MainThreadRequest request = null;
2360 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2361 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2362 } else if (phone != null) {
2363 request = new MainThreadRequest(argument, phone, workSource);
2364 } else {
2365 request = new MainThreadRequest(argument, subId, workSource);
2366 }
2367
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 Message msg = mMainThreadHandler.obtainMessage(command, request);
2369 msg.sendToTarget();
2370
Rambo Wang0f050d82021-02-12 11:43:36 -08002371
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002373 if (timeoutInMs >= 0) {
2374 // Wait for at least timeoutInMs before returning null request result
2375 long now = SystemClock.elapsedRealtime();
2376 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002377 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002378 try {
2379 request.wait(deadline - now);
2380 } catch (InterruptedException e) {
2381 // Do nothing, go back and check if request is completed or timeout
2382 } finally {
2383 now = SystemClock.elapsedRealtime();
2384 }
2385 }
2386 } else {
2387 // Wait for the request to complete
2388 while (request.result == null) {
2389 try {
2390 request.wait();
2391 } catch (InterruptedException e) {
2392 // Do nothing, go back and wait until the request is complete
2393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 }
2395 }
2396 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002397 if (request.result == null) {
2398 Log.wtf(LOG_TAG,
2399 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 return request.result;
2402 }
2403
2404 /**
2405 * Asynchronous ("fire and forget") version of sendRequest():
2406 * Posts the specified command to be executed on the main thread, and
2407 * returns immediately.
2408 * @see #sendRequest
2409 */
2410 private void sendRequestAsync(int command) {
2411 mMainThreadHandler.sendEmptyMessage(command);
2412 }
2413
2414 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002415 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002416 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002417 */
2418 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002419 sendRequestAsync(command, argument, null, null);
2420 }
2421
2422 /**
2423 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2424 * @see {@link #sendRequest(int,Object)}
2425 */
2426 private void sendRequestAsync(
2427 int command, Object argument, Phone phone, WorkSource workSource) {
2428 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002429 Message msg = mMainThreadHandler.obtainMessage(command, request);
2430 msg.sendToTarget();
2431 }
2432
2433 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 * Initialize the singleton PhoneInterfaceManager instance.
2435 * This is only done once, at startup, from PhoneApp.onCreate().
2436 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002437 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 synchronized (PhoneInterfaceManager.class) {
2439 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002440 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 } else {
2442 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2443 }
2444 return sInstance;
2445 }
2446 }
2447
2448 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002449 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002451 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002453 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002454 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002455 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2457 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002458 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002459 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002460 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002461 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002462 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002463 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 publish();
arunvoddud7401012022-12-15 16:08:12 +00002465 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 }
2467
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002468 @VisibleForTesting
2469 public SharedPreferences getSharedPreferences() {
2470 return mTelephonySharedPreferences;
2471 }
2472
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002473 /**
2474 * Get the default phone for this device.
2475 */
2476 @VisibleForTesting
2477 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002478 Phone thePhone = getPhone(getDefaultSubscription());
2479 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2480 }
2481
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 private void publish() {
2483 if (DBG) log("publish: " + this);
2484
Peter Wangc035ce42020-01-08 21:00:22 -08002485 TelephonyFrameworkInitializer
2486 .getTelephonyServiceManager()
2487 .getTelephonyServiceRegisterer()
2488 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
Stuart Scott584921c2015-01-15 17:10:34 -08002491 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002492 if (request.phone != null) {
2493 return request.phone;
2494 } else {
2495 return getPhoneFromSubId(request.subId);
2496 }
2497 }
2498
2499 private Phone getPhoneFromSubId(int subId) {
2500 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2501 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002502 }
2503
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002504 /**
2505 * Get phone object associated with a subscription.
2506 * Return default phone if phone object associated with subscription is null
2507 * @param subId - subscriptionId
2508 * @return phone object associated with a subscription or default phone if null.
2509 */
Ling Mac28f0212023-03-24 16:07:15 -07002510 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002511 Phone phone = getPhoneFromSubId(subId);
2512 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002513 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002514 phone = getDefaultPhone();
2515 }
2516 return phone;
2517 }
2518
Rambo Wange53e07d2022-05-10 13:01:13 -07002519 @Nullable
2520 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002521 Phone phone = getPhoneFromRequest(request);
2522 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002523 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002524 }
2525
Ling Mac28f0212023-03-24 16:07:15 -07002526 /**
2527 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2528 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2529 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2530 * @return The Phone associated the sub Id
2531 */
2532 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002533 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535
Kai Shif70f46f2021-03-03 13:59:46 -08002536 private void sendEraseModemConfig(@NonNull Phone phone) {
2537 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2538 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2539 }
2540
2541 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2542 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2543 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002544 }
2545
Peter Wang44b186e2020-01-13 23:33:09 -08002546 private boolean isImsAvailableOnDevice() {
2547 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2548 if (pm == null) {
2549 // For some reason package manger is not available.. This will fail internally anyway,
2550 // so do not throw error and allow.
2551 return true;
2552 }
2553 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2554 }
2555
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002557 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002558 }
2559
Wink Savilleb564aae2014-10-23 10:18:09 -07002560 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 if (DBG) log("dial: " + number);
2562 // No permission check needed here: This is just a wrapper around the
2563 // ACTION_DIAL intent, which is available to any app since it puts up
2564 // the UI before it does anything.
2565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 String url = createTelUrl(number);
2569 if (url == null) {
2570 return;
2571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 // PENDING: should we just silently fail if phone is offhook or ringing?
2574 PhoneConstants.State state = mCM.getState(subId);
2575 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2576 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2577 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2578 mApp.startActivity(intent);
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583 }
2584
2585 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002586 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 if (DBG) log("call: " + number);
2591
2592 // This is just a wrapper around the ACTION_CALL intent, but we still
2593 // need to do a permission check since we're calling startActivity()
2594 // from the context of the phone app.
2595 enforceCallPermission();
2596
Jordan Liu1617b712019-07-10 15:06:26 -07002597 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 != AppOpsManager.MODE_ALLOWED) {
2599 return;
2600 }
2601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 String url = createTelUrl(number);
2605 if (url == null) {
2606 return;
2607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 boolean isValid = false;
2610 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2611 if (slist != null) {
2612 for (SubscriptionInfo subInfoRecord : slist) {
2613 if (subInfoRecord.getSubscriptionId() == subId) {
2614 isValid = true;
2615 break;
2616 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002617 }
Wink Saville08874612014-08-31 19:19:58 -07002618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 if (!isValid) {
2620 return;
2621 }
Wink Saville08874612014-08-31 19:19:58 -07002622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2624 intent.putExtra(SUBSCRIPTION_KEY, subId);
2625 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2626 mApp.startActivity(intent);
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
Wink Savilleb564aae2014-10-23 10:18:09 -07002632 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002633 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002634 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2635 }
2636
Wink Savilleb564aae2014-10-23 10:18:09 -07002637 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002638 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002639 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2640 }
2641
Wink Savilleb564aae2014-10-23 10:18:09 -07002642 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002647 Phone phone = getPhone(subId);
2648 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 checkSimPin.start();
2650 return checkSimPin.unlockSim(null, pin);
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
Wink Savilleb564aae2014-10-23 10:18:09 -07002656 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658
2659 final long identity = Binder.clearCallingIdentity();
2660 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002661 Phone phone = getPhone(subId);
2662 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 checkSimPuk.start();
2664 return checkSimPuk.unlockSim(puk, pin);
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 }
2669
2670 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002671 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 * a synchronous one.
2673 */
2674 private static class UnlockSim extends Thread {
2675
2676 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002677 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678
2679 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002680 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2681 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682
2683 // For replies from SimCard interface
2684 private Handler mHandler;
2685
2686 // For async handler to identify request type
2687 private static final int SUPPLY_PIN_COMPLETE = 100;
2688
Michele Berionne5e411512020-11-13 02:36:59 +00002689 UnlockSim(int phoneId, IccCard simCard) {
2690 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 mSimCard = simCard;
2692 }
2693
2694 @Override
2695 public void run() {
2696 Looper.prepare();
2697 synchronized (UnlockSim.this) {
2698 mHandler = new Handler() {
2699 @Override
2700 public void handleMessage(Message msg) {
2701 AsyncResult ar = (AsyncResult) msg.obj;
2702 switch (msg.what) {
2703 case SUPPLY_PIN_COMPLETE:
2704 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2705 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002706 mRetryCount = msg.arg1;
2707 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002708 CommandException.Error error = null;
2709 if (ar.exception instanceof CommandException) {
2710 error = ((CommandException) (ar.exception))
2711 .getCommandError();
2712 }
2713 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002714 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002715 } else if (error == CommandException.Error.ABORTED) {
2716 /* When UiccCardApp dispose, handle message and return
2717 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002718 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002719 } else {
2720 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2721 }
2722 } else {
2723 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 mDone = true;
2726 UnlockSim.this.notifyAll();
2727 }
2728 break;
2729 }
2730 }
2731 };
2732 UnlockSim.this.notifyAll();
2733 }
2734 Looper.loop();
2735 }
2736
2737 /*
2738 * Use PIN or PUK to unlock SIM card
2739 *
2740 * If PUK is null, unlock SIM card with PIN
2741 *
2742 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302743 *
2744 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2745 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 */
Wink Saville9de0f752013-10-22 19:04:03 -07002747 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748
2749 while (mHandler == null) {
2750 try {
2751 wait();
2752 } catch (InterruptedException e) {
2753 Thread.currentThread().interrupt();
2754 }
2755 }
2756 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2757
2758 if (puk == null) {
2759 mSimCard.supplyPin(pin, callback);
2760 } else {
2761 mSimCard.supplyPuk(puk, pin, callback);
2762 }
2763
2764 while (!mDone) {
2765 try {
2766 Log.d(LOG_TAG, "wait for done");
2767 wait();
2768 } catch (InterruptedException e) {
2769 // Restore the interrupted status
2770 Thread.currentThread().interrupt();
2771 }
2772 }
2773 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002774 int[] resultArray = new int[2];
2775 resultArray[0] = mResult;
2776 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002777
2778 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002779 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002780 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302781 // This instance is no longer reused, so quit its thread's looper.
2782 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002783
Wink Saville9de0f752013-10-22 19:04:03 -07002784 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002785 }
2786 }
2787
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002788 /**
2789 * This method has been removed due to privacy and stability concerns.
2790 */
2791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002793 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2794 return;
Wink Saville36469e72014-06-11 15:17:00 -07002795 }
2796
Nathan Harold1f889d82020-06-04 17:05:26 -07002797 @Override
2798 public void updateServiceLocationWithPackageName(String callingPackage) {
2799 mApp.getSystemService(AppOpsManager.class)
2800 .checkPackage(Binder.getCallingUid(), callingPackage);
2801
Nathan Haroldf096d982020-11-18 17:18:06 -08002802 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002803 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2804 // Callers targeting S have no business invoking this method.
2805 return;
2806 }
2807
2808 LocationAccessPolicy.LocationPermissionResult locationResult =
2809 LocationAccessPolicy.checkLocationPermission(mApp,
2810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2811 .setCallingPackage(callingPackage)
2812 .setCallingFeatureId(null)
2813 .setCallingPid(Binder.getCallingPid())
2814 .setCallingUid(Binder.getCallingUid())
2815 .setMethod("updateServiceLocation")
2816 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2817 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2818 .build());
2819 // Apps that lack location permission have no business calling this method;
2820 // however, because no permission was declared in the public API, denials must
2821 // all be "soft".
2822 switch (locationResult) {
2823 case DENIED_HARD: /* fall through */
2824 case DENIED_SOFT:
2825 return;
2826 }
2827
2828 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
Ling Mac28f0212023-03-24 16:07:15 -07002831 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 }
2836
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002837 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002838 @Override
2839 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002840 return isRadioOnWithFeature(callingPackage, null);
2841 }
2842
2843
2844 @Override
2845 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2846 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2847 callingFeatureId);
2848 }
2849
2850 @Deprecated
2851 @Override
2852 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2853 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002854 }
2855
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002856 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002857 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2858 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002860 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002861 return false;
2862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 return isRadioOnForSubscriber(subId);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002870 }
2871
2872 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
2876 if (phone != null) {
2877 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2878 } else {
2879 return false;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
2886 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002887 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 }
Wink Saville36469e72014-06-11 15:17:00 -07002889
Wink Savilleb564aae2014-10-23 10:18:09 -07002890 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 final Phone phone = getPhone(subId);
2896 if (phone != null) {
2897 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Wink Saville36469e72014-06-11 15:17:00 -07002902 }
2903
2904 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002905 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002906 }
2907
Wink Savilleb564aae2014-10-23 10:18:09 -07002908 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002909 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 final Phone phone = getPhone(subId);
2914 if (phone == null) {
2915 return false;
2916 }
2917 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2918 toggleRadioOnOffForSubscriber(subId);
2919 }
2920 return true;
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 }
Wink Saville36469e72014-06-11 15:17:00 -07002925
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002926 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002927 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002928 /*
2929 * If any of the Radios are available, it will need to be
2930 * shutdown. So return true if any Radio is available.
2931 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2935 Phone phone = PhoneFactory.getPhone(i);
2936 if (phone != null && phone.isRadioAvailable()) return true;
2937 }
2938 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2939 return false;
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002942 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002943 }
2944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002946 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947 enforceModifyPermission();
2948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2952 logv("Shutting down Phone " + i);
2953 shutdownRadioUsingPhoneId(i);
2954 }
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002957 }
2958 }
2959
2960 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002961 Phone phone = PhoneFactory.getPhone(phoneId);
2962 if (phone != null && phone.isRadioAvailable()) {
2963 phone.shutdownRadio();
2964 }
2965 }
2966
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969
Ling Ma83dc5ea2023-01-12 15:06:04 -08002970 if (!turnOn) {
2971 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2972 }
2973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2977 if (defaultPhone != null) {
2978 defaultPhone.setRadioPower(turnOn);
2979 return true;
2980 } else {
2981 loge("There's no default phone.");
2982 return false;
2983 }
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002986 }
Wink Saville36469e72014-06-11 15:17:00 -07002987 }
2988
Wink Savilleb564aae2014-10-23 10:18:09 -07002989 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991
Ling Ma83dc5ea2023-01-12 15:06:04 -08002992 if (!turnOn) {
2993 log("setRadioPowerForSubscriber off: subId=" + subId
2994 + ",callingPackage=" + getCurrentPackageName());
2995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 final Phone phone = getPhone(subId);
2999 if (phone != null) {
3000 phone.setRadioPower(turnOn);
3001 return true;
3002 } else {
3003 return false;
3004 }
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 }
3009
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003010 /**
3011 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3012 * no reason to power it off. When any of the voters want to power it off, it will be turned
3013 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3014 * powering it off, and these radio off votes will be cleared.
3015 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3016 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3017 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3018 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3019 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3020 * check its vote.
3021 *
3022 * @param subId The subscription ID.
3023 * @param reason The reason for powering off radio.
3024 * @return true on success and false on failure.
3025 */
3026 public boolean requestRadioPowerOffForReason(int subId,
3027 @TelephonyManager.RadioPowerReason int reason) {
3028 enforceModifyPermission();
3029
Ling Ma83dc5ea2023-01-12 15:06:04 -08003030 log("requestRadioPowerOffForReason: subId=" + subId
3031 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003032 final long identity = Binder.clearCallingIdentity();
3033 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003034 boolean result = false;
3035 for (Phone phone : PhoneFactory.getPhones()) {
3036 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003037 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003038 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003039 if (!result) {
3040 loge("requestRadioPowerOffForReason: no phone exists");
3041 }
3042 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
3046 }
3047
3048 /**
3049 * Remove the vote on powering off the radio for a reason, as requested by
3050 * {@link requestRadioPowerOffForReason}.
3051 *
3052 * @param subId The subscription ID.
3053 * @param reason The reason for powering off radio.
3054 * @return true on success and false on failure.
3055 */
3056 public boolean clearRadioPowerOffForReason(int subId,
3057 @TelephonyManager.RadioPowerReason int reason) {
3058 enforceModifyPermission();
3059
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003062 boolean result = false;
3063 for (Phone phone : PhoneFactory.getPhones()) {
3064 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003065 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003066 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003067 if (!result) {
3068 loge("clearRadioPowerOffForReason: no phone exists");
3069 }
3070 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
3074 }
3075
3076 /**
3077 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3078 *
3079 * @param subId The subscription ID.
3080 * @param callingPackage The package making the call.
3081 * @param callingFeatureId The feature in the package.
3082 * @return List of reasons for powering off radio.
3083 */
3084 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3085 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3086
3087 final long identity = Binder.clearCallingIdentity();
3088 List result = new ArrayList();
3089 try {
3090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3091 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3092 return result;
3093 }
3094
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003095 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003096 if (phone != null) {
3097 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003098 } else {
3099 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003100 }
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 return result;
3105 }
3106
Wink Saville36469e72014-06-11 15:17:00 -07003107 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003108 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003109 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
Jack Yu285100e2022-12-02 22:48:35 -08003114 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final Phone phone = getPhone(subId);
3116 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003117 phone.getDataSettingsManager().setDataEnabled(
3118 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 return true;
3120 } else {
3121 return false;
3122 }
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 }
3127
Wink Saville36469e72014-06-11 15:17:00 -07003128 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003129 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003130 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
Jack Yu285100e2022-12-02 22:48:35 -08003135 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136 final Phone phone = getPhone(subId);
3137 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003138 phone.getDataSettingsManager().setDataEnabled(
3139 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 return true;
3141 } else {
3142 return false;
3143 }
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147 }
3148
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003150 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 final Phone phone = getPhone(subId);
3154 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003155 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 } else {
3157 return false;
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 }
3163
3164 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003165 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003166 }
3167
pkanwarae03a6b2016-11-06 20:37:09 -08003168 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 enforceCallPermission();
3170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3174 return;
3175 }
3176 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3177 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
pkanwar32d516d2016-10-14 19:37:38 -07003181 };
3182
Wink Savilleb564aae2014-10-23 10:18:09 -07003183 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3189 return false;
3190 }
3191 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003197 /**
3198 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3199 * tag on getCallState Binder call.
3200 */
3201 @Deprecated
3202 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003204 if (CompatChanges.isChangeEnabled(
3205 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3206 Binder.getCallingUid())) {
3207 // Do not allow this API to be called on API version 31+, it should only be
3208 // called on old apps using this Binder call directly.
3209 throw new SecurityException("This method can only be used for applications "
3210 + "targeting API version 30 or less.");
3211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
Ling Mac28f0212023-03-24 16:07:15 -07003214 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3215 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
3222 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3223 if (CompatChanges.isChangeEnabled(
3224 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3225 Binder.getCallingUid())) {
3226 // Check READ_PHONE_STATE for API version 31+
3227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3228 featureId, "getCallStateForSubscription")) {
3229 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3230 + "targeting API level 31+.");
3231 }
3232 }
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3237 PhoneConstantConversions.convertCallState(phone.getState());
3238 } finally {
3239 Binder.restoreCallingIdentity(identity);
3240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003241 }
3242
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003244 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003245 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003246 }
3247
3248 @Override
3249 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 final long identity = Binder.clearCallingIdentity();
3251 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003252 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003254 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 } else {
3256 return PhoneConstantConversions.convertDataState(
3257 PhoneConstants.DataState.DISCONNECTED);
3258 }
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 }
3263
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003265 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003266 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003267 }
3268
3269 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003270 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 final long identity = Binder.clearCallingIdentity();
3272 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003273 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003275 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 } else {
3277 return TelephonyManager.DATA_ACTIVITY_NONE;
3278 }
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 }
3283
3284 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003285 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003287 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003288
3289 LocationAccessPolicy.LocationPermissionResult locationResult =
3290 LocationAccessPolicy.checkLocationPermission(mApp,
3291 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3292 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003293 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003294 .setCallingPid(Binder.getCallingPid())
3295 .setCallingUid(Binder.getCallingUid())
3296 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003297 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003298 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3299 .build());
3300 switch (locationResult) {
3301 case DENIED_HARD:
3302 throw new SecurityException("Not allowed to access cell location");
3303 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003304 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3305 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306 }
3307
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003312 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003313 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Svetoslav64fad262015-04-14 14:35:21 -07003317 }
3318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003319 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003320 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003321 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3322 // registered cell info, so return a NULL country instead.
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003325 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3326 // Get default phone in this case.
3327 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3328 }
Jack Yu285100e2022-12-02 22:48:35 -08003329 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003331 if (phone == null) return "";
3332 ServiceStateTracker sst = phone.getServiceStateTracker();
3333 if (sst == null) return "";
3334 LocaleTracker lt = sst.getLocaleTracker();
3335 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003336 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003340 }
3341
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003342 /**
3343 * This method was removed due to potential issues caused by performing partial
3344 * updates of service state, and lack of a credible use case.
3345 *
3346 * This has the ability to break the telephony implementation by disabling notification of
3347 * changes in device connectivity. DO NOT USE THIS!
3348 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003349 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 public void enableLocationUpdates() {
3351 mApp.enforceCallingOrSelfPermission(
3352 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 }
3354
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003355 /**
3356 * This method was removed due to potential issues caused by performing partial
3357 * updates of service state, and lack of a credible use case.
3358 *
3359 * This has the ability to break the telephony implementation by disabling notification of
3360 * changes in device connectivity. DO NOT USE THIS!
3361 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003362 @Override
3363 public void disableLocationUpdates() {
3364 mApp.enforceCallingOrSelfPermission(
3365 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 }
3367
3368 @Override
3369 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003370 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3371 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003372 try {
3373 mApp.getSystemService(AppOpsManager.class)
3374 .checkPackage(Binder.getCallingUid(), callingPackage);
3375 } catch (SecurityException e) {
3376 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3377 throw e;
3378 }
3379
Nathan Haroldf096d982020-11-18 17:18:06 -08003380 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003381 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3382 throw new SecurityException(
3383 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3384 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003385
Jordan Liu1617b712019-07-10 15:06:26 -07003386 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3388 return null;
3389 }
Svetoslav64fad262015-04-14 14:35:21 -07003390
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003391 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003393 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003394 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003395
Nathan Haroldf180aac2018-06-01 18:43:55 -07003396 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3397 for (CellInfo ci : info) {
3398 if (ci instanceof CellInfoGsm) {
3399 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3400 } else if (ci instanceof CellInfoWcdma) {
3401 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003404 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 }
3406
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003407 private List<CellInfo> getCachedCellInfo() {
3408 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3409 for (Phone phone : PhoneFactory.getPhones()) {
3410 List<CellInfo> info = phone.getAllCellInfo();
3411 if (info != null) cellInfos.addAll(info);
3412 }
3413 return cellInfos;
3414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415
3416 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003417 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003418 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003419 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003420
3421 LocationAccessPolicy.LocationPermissionResult locationResult =
3422 LocationAccessPolicy.checkLocationPermission(mApp,
3423 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3424 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003425 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003426 .setCallingPid(Binder.getCallingPid())
3427 .setCallingUid(Binder.getCallingUid())
3428 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003429 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003430 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3431 .build());
3432 switch (locationResult) {
3433 case DENIED_HARD:
3434 throw new SecurityException("Not allowed to access cell info");
3435 case DENIED_SOFT:
3436 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 }
3438
Nathan Haroldf096d982020-11-18 17:18:06 -08003439 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003440 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3441 return getCachedCellInfo();
3442 }
3443
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003444 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3449 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003450 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003451 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 if (info != null) cellInfos.addAll(info);
3453 }
3454 return cellInfos;
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 }
3458 }
3459
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003460 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003461 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3462 String callingFeatureId) {
3463 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3464 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003465 }
3466
3467 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003468 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3469 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003470 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003471 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003472 }
3473
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003474 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3475 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003476 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003477 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003478
3479 LocationAccessPolicy.LocationPermissionResult locationResult =
3480 LocationAccessPolicy.checkLocationPermission(mApp,
3481 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3482 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003483 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003484 .setCallingPid(Binder.getCallingPid())
3485 .setCallingUid(Binder.getCallingUid())
3486 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003487 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3488 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003489 .build());
3490 switch (locationResult) {
3491 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003492 if (TelephonyPermissions
3493 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003494 // Safetynet logging for b/154934934
3495 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3496 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003497 throw new SecurityException("Not allowed to access cell info");
3498 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003499 if (TelephonyPermissions
3500 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003501 // Safetynet logging for b/154934934
3502 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3503 }
Nathan Harold5320c422019-05-09 10:26:08 -07003504 try {
3505 cb.onCellInfo(new ArrayList<CellInfo>());
3506 } catch (RemoteException re) {
3507 // Drop without consequences
3508 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003509 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003510 }
3511
Nathan Harolda939a962019-05-09 10:13:47 -07003512
3513 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003514 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3515
3516 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3517 }
3518
3519 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003520 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003521 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003526 Phone phone = getPhone(subId);
3527 if (phone == null) {
3528 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3529 } else {
3530 phone.setCellInfoListRate(rateInMillis, workSource);
3531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535 }
3536
Shishir Agrawala9f32182016-04-12 12:00:16 -07003537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003538 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003539 Phone phone = PhoneFactory.getPhone(slotIndex);
3540 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 return null;
3542 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003544 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003545 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003546 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003547 return null;
3548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 return phone.getImei();
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003556 }
3557
3558 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003559 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3560 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3561 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3562 callingFeatureId, "getPrimaryImei")) {
3563 throw new SecurityException("Caller does not have permission");
3564 }
3565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 for (Phone phone : PhoneFactory.getPhones()) {
3568 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3569 return phone.getImei();
3570 }
3571 }
3572 throw new UnsupportedOperationException("Operation not supported");
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
3578 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003579 public String getTypeAllocationCodeForSlot(int slotIndex) {
3580 Phone phone = PhoneFactory.getPhone(slotIndex);
3581 String tac = null;
3582 if (phone != null) {
3583 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003584 try {
3585 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3586 } catch (IndexOutOfBoundsException e) {
3587 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3588 return null;
3589 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003590 }
3591 return tac;
3592 }
3593
3594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003595 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003596 try {
3597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3598 } catch (SecurityException se) {
3599 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3600 throw new SecurityException("Package " + callingPackage + " does not belong to "
3601 + Binder.getCallingUid());
3602 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003603 Phone phone = PhoneFactory.getPhone(slotIndex);
3604 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003605 return null;
3606 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607
Jeff Davidson913390f2018-02-23 17:11:49 -08003608 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003609 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003610 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003611 return null;
3612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613
3614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 return phone.getMeid();
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
3619 }
Jack Yu2af8d712017-03-15 17:14:14 -07003620 }
3621
3622 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003623 public String getManufacturerCodeForSlot(int slotIndex) {
3624 Phone phone = PhoneFactory.getPhone(slotIndex);
3625 String manufacturerCode = null;
3626 if (phone != null) {
3627 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003628 try {
3629 manufacturerCode =
3630 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3631 } catch (IndexOutOfBoundsException e) {
3632 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3633 return null;
3634 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003635 }
3636 return manufacturerCode;
3637 }
3638
3639 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003640 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3641 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003642 Phone phone = PhoneFactory.getPhone(slotIndex);
3643 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 return null;
3645 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003646 int subId = phone.getSubId();
3647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003648 mApp, subId, callingPackage, callingFeatureId,
3649 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003650 return null;
3651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652
3653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 return phone.getDeviceSvn();
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003659 }
3660
fionaxu43304da2017-11-27 22:51:16 -08003661 @Override
3662 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 final Phone phone = getPhone(subId);
3666 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
fionaxu43304da2017-11-27 22:51:16 -08003670 }
3671
3672 @Override
3673 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 final Phone phone = getPhone(subId);
3677 return phone == null ? null : phone.getCarrierName();
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
fionaxu43304da2017-11-27 22:51:16 -08003681 }
3682
calvinpanffe225e2018-11-01 19:43:06 +08003683 @Override
chen xu0026ca62019-03-06 15:28:50 -08003684 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 final Phone phone = getPhone(subId);
3688 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003689 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
3693 }
3694
3695 @Override
chen xu0026ca62019-03-06 15:28:50 -08003696 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003700 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
chen xu651eec72018-11-11 19:03:44 -08003706 @Override
chen xu864e11c2018-12-06 22:10:03 -08003707 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3708 if (!isSubscriptionMccMnc) {
3709 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3710 }
chen xu651eec72018-11-11 19:03:44 -08003711 final Phone phone = PhoneFactory.getPhone(slotIndex);
3712 if (phone == null) {
3713 return TelephonyManager.UNKNOWN_CARRIER_ID;
3714 }
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
3721 }
3722
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003723 //
3724 // Internal helper methods.
3725 //
3726
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003727 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003728 * Make sure the caller is the calling package itself
3729 *
3730 * @throws SecurityException if the caller is not the calling package
3731 */
3732 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3733 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003734 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3735 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003736 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003737 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003738 } catch (PackageManager.NameNotFoundException e) {
3739 // packageUid is -1
3740 }
3741 if (packageUid != callingUid) {
3742 throw new SecurityException(message + ": Package " + callingPackage
3743 + " does not belong to " + callingUid);
3744 }
3745 }
3746
3747 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003748 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3749 *
3750 * @throws SecurityException if the caller does not have the required permission
3751 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003752 @VisibleForTesting
3753 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003754 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3755 }
3756
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003757 /**
arunvoddud7401012022-12-15 16:08:12 +00003758 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003759 *
3760 * @throws SecurityException if the caller does not have the required permission
3761 */
3762 @VisibleForTesting
3763 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003764 enforceReadPermission(null);
3765 }
3766
3767 /**
3768 * Make sure the caller has the READ_PHONE_STATE permissions.
3769 *
3770 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3771 */
3772 @VisibleForTesting
3773 public void enforceReadPermission(String msg) {
3774 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003775 }
3776
Shuo Qian3b6ee772019-11-13 17:43:31 -08003777 private void enforceActiveEmergencySessionPermission() {
3778 mApp.enforceCallingOrSelfPermission(
3779 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3780 }
3781
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003782 /**
3783 * Make sure the caller has the CALL_PHONE permission.
3784 *
3785 * @throws SecurityException if the caller does not have the required permission
3786 */
3787 private void enforceCallPermission() {
3788 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3789 }
3790
paulhu5a773602019-08-23 19:17:33 +08003791 private void enforceSettingsPermission() {
3792 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003793 }
3794
Michele Berionne5e411512020-11-13 02:36:59 +00003795 private void enforceRebootPermission() {
3796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3797 }
3798
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003799 /**
3800 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3801 * @param message - log message to print.
3802 * @throws SecurityException if the caller does not have the required permission
3803 */
3804 private void enforceSatelliteCommunicationPermission(String message) {
3805 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3806 }
3807
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003808 private String createTelUrl(String number) {
3809 if (TextUtils.isEmpty(number)) {
3810 return null;
3811 }
3812
Jake Hambye994d462014-02-03 13:10:13 -08003813 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003814 }
3815
Ihab Awadf9e92732013-12-05 18:02:52 -08003816 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003817 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003818 }
3819
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003820 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003821 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003822 }
3823
Ihab Awadf9e92732013-12-05 18:02:52 -08003824 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003825 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003826 }
3827
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003828 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003829 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003830 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003831 }
3832
Sanket Padawe356d7632015-06-22 14:03:32 -07003833 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003834 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 final Phone phone = PhoneFactory.getPhone(slotIndex);
3838 if (phone == null) {
3839 return PhoneConstants.PHONE_TYPE_NONE;
3840 } else {
3841 return phone.getPhoneType();
3842 }
3843 } finally {
3844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003846 }
3847
3848 /**
3849 * Returns the CDMA ERI icon index to display
3850 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3853 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3854 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003855 }
3856
Sanket Padawe356d7632015-06-22 14:03:32 -07003857 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003858 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3859 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003861 mApp, subId, callingPackage, callingFeatureId,
3862 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003863 return -1;
3864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865
3866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 final Phone phone = getPhone(subId);
3869 if (phone != null) {
3870 return phone.getCdmaEriIconIndex();
3871 } else {
3872 return -1;
3873 }
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003877 }
3878
3879 /**
3880 * Returns the CDMA ERI icon mode,
3881 * 0 - ON
3882 * 1 - FLASHING
3883 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003884 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003885 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3886 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3887 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003888 }
3889
Sanket Padawe356d7632015-06-22 14:03:32 -07003890 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003891 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3892 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003894 mApp, subId, callingPackage, callingFeatureId,
3895 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003896 return -1;
3897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 final Phone phone = getPhone(subId);
3902 if (phone != null) {
3903 return phone.getCdmaEriIconMode();
3904 } else {
3905 return -1;
3906 }
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003910 }
3911
3912 /**
3913 * Returns the CDMA ERI text,
3914 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003916 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3917 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3918 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003919 }
3920
Sanket Padawe356d7632015-06-22 14:03:32 -07003921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003922 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3923 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003925 mApp, subId, callingPackage, callingFeatureId,
3926 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003927 return null;
3928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929
3930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 final Phone phone = getPhone(subId);
3933 if (phone != null) {
3934 return phone.getCdmaEriText();
3935 } else {
3936 return null;
3937 }
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003941 }
3942
3943 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003944 * Returns the CDMA MDN.
3945 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003946 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003947 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3949 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950
3951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003954 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 return phone.getLine1Number();
3956 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 return null;
3959 }
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003962 }
3963 }
3964
3965 /**
3966 * Returns the CDMA MIN.
3967 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003968 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003969 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3971 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003972
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 final Phone phone = getPhone(subId);
3976 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3977 return phone.getCdmaMin();
3978 } else {
3979 return null;
3980 }
3981 } finally {
3982 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003983 }
3984 }
3985
Hall Liud892bec2018-11-30 14:51:45 -08003986 @Override
3987 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3988 INumberVerificationCallback callback, String callingPackage) {
3989 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3990 != PERMISSION_GRANTED) {
3991 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3992 }
3993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3994
3995 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3996 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003997 throw new SecurityException("Calling package must be configured in the device config: "
3998 + "calling package: " + callingPackage
3999 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004000 }
4001
4002 if (range == null) {
4003 throw new NullPointerException("Range must be non-null");
4004 }
4005
4006 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004007 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004008
4009 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4010 }
4011
Junda Liuca05d5d2014-08-14 22:36:34 -07004012 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004013 * Returns true if CDMA provisioning needs to run.
4014 */
4015 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004022 }
4023
4024 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004025 * Sets the voice mail number of a given subId.
4026 */
4027 @Override
4028 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004029 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4030 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4035 new Pair<String, String>(alphaTag, number), new Integer(subId));
4036 return success;
4037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004040 }
4041
Ta-wei Yen87c49842016-05-13 21:19:52 -07004042 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004043 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004045 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4046 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004047 if (!TextUtils.equals(callingPackage, systemDialer)) {
4048 throw new SecurityException("caller must be system dialer");
4049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4054 if (phoneAccountHandle == null) {
4055 return null;
4056 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 } finally {
4059 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004060 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004061 }
4062
4063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4065 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 mApp, subId, callingPackage, callingFeatureId,
4069 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004070 return null;
4071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004073 final long identity = Binder.clearCallingIdentity();
4074 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004075 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004079 }
4080
4081 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004082 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4083 VisualVoicemailSmsFilterSettings settings) {
4084 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004089 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004093 }
4094
4095 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004096 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004102 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004106 }
4107
4108 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004109 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4110 String callingPackage, int subId) {
4111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004116 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004120 }
4121
4122 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004123 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004129 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004133 }
4134
4135 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004136 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4137 String callingAttributionTag, int subId, String number, int port, String text,
4138 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004139 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004140 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004141 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004142 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004143 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4144 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004145 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004146
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004147 /**
fionaxu0152e512016-11-14 13:36:14 -08004148 * Sets the voice activation state of a given subId.
4149 */
4150 @Override
4151 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4153 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004154
4155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 final Phone phone = getPhone(subId);
4158 if (phone != null) {
4159 phone.setVoiceActivationState(activationState);
4160 } else {
4161 loge("setVoiceActivationState fails with invalid subId: " + subId);
4162 }
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004165 }
4166 }
4167
4168 /**
4169 * Sets the data activation state of a given subId.
4170 */
4171 @Override
4172 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4174 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 final Phone phone = getPhone(subId);
4179 if (phone != null) {
4180 phone.setDataActivationState(activationState);
4181 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004182 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 }
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004186 }
4187 }
4188
4189 /**
4190 * Returns the voice activation state of a given subId.
4191 */
4192 @Override
4193 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195
fionaxu0152e512016-11-14 13:36:14 -08004196 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 if (phone != null) {
4200 return phone.getVoiceActivationState();
4201 } else {
4202 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4203 }
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004206 }
4207 }
4208
4209 /**
4210 * Returns the data activation state of a given subId.
4211 */
4212 @Override
4213 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215
fionaxu0152e512016-11-14 13:36:14 -08004216 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 if (phone != null) {
4220 return phone.getDataActivationState();
4221 } else {
4222 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4223 }
4224 } finally {
4225 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004226 }
4227 }
4228
4229 /**
Wink Saville36469e72014-06-11 15:17:00 -07004230 * Returns the unread count of voicemails for a subId
4231 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004233 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4234 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004236 mApp, subId, callingPackage, callingFeatureId,
4237 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004238 return 0;
4239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 final Phone phone = getPhone(subId);
4243 if (phone != null) {
4244 return phone.getVoiceMessageCount();
4245 } else {
4246 return 0;
4247 }
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004251 }
4252
4253 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004254 * returns true, if the device is in a state where both voice and data
4255 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004256 */
4257 @Override
4258 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 final long identity = Binder.clearCallingIdentity();
4260 try {
Ling Mac28f0212023-03-24 16:07:15 -07004261 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004265 }
4266
4267 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004268 * Send the dialer code if called from the current default dialer or the caller has
4269 * carrier privilege.
4270 * @param inputCode The dialer code to send
4271 */
4272 @Override
4273 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004274 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004276 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4277 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004278 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004279 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004280 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004285 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
fionaxu235cc5e2017-03-06 22:25:57 -08004289 }
4290
Pengquan Menga1bb6272018-09-06 09:59:22 -07004291 @Override
4292 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004293 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004294 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4295 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 if (!isActiveSubscription(subId)) {
4299 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4300 }
4301 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004304 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004305 }
4306
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004308 public boolean isInEmergencySmsMode() {
4309 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 for (Phone phone : PhoneFactory.getPhones()) {
4313 if (phone.isInEmergencySmsMode()) {
4314 return true;
4315 }
4316 }
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
4320 return false;
4321 }
4322
shilu366312e2019-12-17 09:28:10 -08004323 /**
4324 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4325 * @param subId The subscription to use to check the configuration.
4326 * @param c The callback that will be used to send the result.
4327 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004328 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004329 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4330 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004331 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004332 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004333
4334 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4336 "IMS not available on device.");
4337 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 final long token = Binder.clearCallingIdentity();
4339 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004340 int slotId = getSlotIndexOrException(subId);
4341 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004342
4343 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4344 if (controller != null) {
4345 ImsManager imsManager = controller.getImsManager(subId);
4346 if (imsManager != null) {
4347 imsManager.addRegistrationCallbackForSubscription(c, subId);
4348 } else {
4349 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4350 }
4351 } else {
4352 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4353 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(token);
4358 }
4359 }
4360
shilu366312e2019-12-17 09:28:10 -08004361 /**
4362 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4363 * @param subId The subscription to use to check the configuration.
4364 * @param c The callback that will be used to send the result.
4365 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004367 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004369 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004370 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4371 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4372 }
Meng Wangafbc5852019-09-19 17:37:13 -07004373 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004374
Meng Wangafbc5852019-09-19 17:37:13 -07004375 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004376 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4377 if (controller != null) {
4378 ImsManager imsManager = controller.getImsManager(subId);
4379 if (imsManager != null) {
4380 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4381 } else {
4382 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4383 + "is inactive, ignoring unregister.");
4384 // If the ImsManager is not valid, just return, since the callback
4385 // will already have been removed internally.
4386 }
4387 }
Meng Wangafbc5852019-09-19 17:37:13 -07004388 } finally {
4389 Binder.restoreCallingIdentity(token);
4390 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 }
4392
Brad Ebingera34a6c22019-10-22 17:36:18 -07004393 /**
4394 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4395 */
4396 @Override
4397 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4398 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4399 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4400 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4401 "IMS not available on device.");
4402 }
4403 final long token = Binder.clearCallingIdentity();
4404 try {
4405 Phone phone = getPhone(subId);
4406 if (phone == null) {
4407 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4408 + subId + "'");
4409 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4410 }
4411 phone.getImsRegistrationState(regState -> {
4412 try {
4413 consumer.accept((regState == null)
4414 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4415 } catch (RemoteException e) {
4416 // Ignore if the remote process is no longer available to call back.
4417 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4418 }
4419 });
4420 } finally {
4421 Binder.restoreCallingIdentity(token);
4422 }
4423 }
4424
4425 /**
4426 * Get the transport type for the IMS service registration state.
4427 */
4428 @Override
4429 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004430 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004431 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004432 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4433 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4434 "IMS not available on device.");
4435 }
4436 final long token = Binder.clearCallingIdentity();
4437 try {
4438 Phone phone = getPhone(subId);
4439 if (phone == null) {
4440 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4441 + subId + "'");
4442 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4443 }
4444 phone.getImsRegistrationTech(regTech -> {
4445 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4446 int regTechConverted = (regTech == null)
4447 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4448 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4449 regTechConverted);
4450 try {
4451 consumer.accept(regTechConverted);
4452 } catch (RemoteException e) {
4453 // Ignore if the remote process is no longer available to call back.
4454 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4455 }
4456 });
4457 } finally {
4458 Binder.restoreCallingIdentity(token);
4459 }
4460 }
4461
shilu366312e2019-12-17 09:28:10 -08004462 /**
4463 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4464 * @param subId The subscription to use to check the configuration.
4465 * @param c The callback that will be used to send the result.
4466 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004468 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4469 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004470 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004471 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004472 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4473 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4474 "IMS not available on device.");
4475 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 final long token = Binder.clearCallingIdentity();
4477 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004478 int slotId = getSlotIndexOrException(subId);
4479 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004480
4481 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4482 if (controller != null) {
4483 ImsManager imsManager = controller.getImsManager(subId);
4484 if (imsManager != null) {
4485 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4486 } else {
4487 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4488 }
4489 } else {
4490 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4491 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004492 } catch (ImsException e) {
4493 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 } finally {
4495 Binder.restoreCallingIdentity(token);
4496 }
4497 }
4498
shilu366312e2019-12-17 09:28:10 -08004499 /**
4500 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4501 * @param subId The subscription to use to check the configuration.
4502 * @param c The callback that will be used to send the result.
4503 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004505 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004506 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004507 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004508 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4509 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4510 }
Meng Wangafbc5852019-09-19 17:37:13 -07004511
4512 final long token = Binder.clearCallingIdentity();
4513 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004514 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4515 if (controller != null) {
4516 ImsManager imsManager = controller.getImsManager(subId);
4517 if (imsManager != null) {
4518 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4519 } else {
4520 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4521 + " is inactive, ignoring unregister.");
4522 // If the ImsManager is not valid, just return, since the callback
4523 // will already have been removed internally.
4524 }
4525 }
Meng Wangafbc5852019-09-19 17:37:13 -07004526 } finally {
4527 Binder.restoreCallingIdentity(token);
4528 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 }
4530
4531 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004532 public boolean isCapable(int subId, int capability, int regTech) {
4533 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004534 final long token = Binder.clearCallingIdentity();
4535 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004536 int slotId = getSlotIndexOrException(subId);
4537 verifyImsMmTelConfiguredOrThrow(slotId);
4538 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4539 } catch (com.android.ims.ImsException e) {
4540 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4541 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004543 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4544 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 } finally {
4546 Binder.restoreCallingIdentity(token);
4547 }
4548 }
4549
4550 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004551 public boolean isAvailable(int subId, int capability, int regTech) {
4552 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004553 final long token = Binder.clearCallingIdentity();
4554 try {
4555 Phone phone = getPhone(subId);
4556 if (phone == null) return false;
4557 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004558 } catch (com.android.ims.ImsException e) {
4559 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4560 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(token);
4563 }
4564 }
4565
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004566 /**
4567 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4568 * subscription.
4569 * @param subId The subscription to use to check the configuration.
4570 * @param callback The callback that will be used to send the result.
4571 * @param capability The MmTelFeature capability that will be used to send the result.
4572 * @param transportType The transport type of the MmTelFeature capability.
4573 */
4574 @Override
4575 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4576 int transportType) {
4577 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004578 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4579 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4580 "IMS not available on device.");
4581 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004582 final long token = Binder.clearCallingIdentity();
4583 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004584 int slotId = getSlotIndex(subId);
4585 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4586 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4587 + subId + "'");
4588 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4589 }
4590 verifyImsMmTelConfiguredOrThrow(slotId);
4591 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4592 transportType, aBoolean -> {
4593 try {
4594 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4595 } catch (RemoteException e) {
4596 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4597 + "running. Ignore");
4598 }
4599 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004600 } catch (ImsException e) {
4601 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004602 } finally {
4603 Binder.restoreCallingIdentity(token);
4604 }
4605 }
4606
shilu366312e2019-12-17 09:28:10 -08004607 /**
4608 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4609 * @param subId The subscription to use to check the configuration.
4610 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 @Override
4612 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004613 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004614 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004615
Brad Ebinger35c841c2018-10-01 10:40:55 -07004616 final long token = Binder.clearCallingIdentity();
4617 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004619 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004620 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 } finally {
4624 Binder.restoreCallingIdentity(token);
4625 }
4626 }
4627
4628 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004629 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004631 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 final long identity = Binder.clearCallingIdentity();
4633 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004635 // This setting doesn't require an active ImsService connection, so do not verify. The
4636 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004637 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004638 } catch (ImsException e) {
4639 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
shilu366312e2019-12-17 09:28:10 -08004645 /**
4646 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4647 * @param subId The subscription to use to check the configuration.
4648 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004650 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004651 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004652 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004653 final long identity = Binder.clearCallingIdentity();
4654 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004655 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004656 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004657 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004658 } catch (ImsException e) {
4659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
4663 }
4664
4665 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004666 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004668 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004669 final long identity = Binder.clearCallingIdentity();
4670 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004671 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004672 // This setting doesn't require an active ImsService connection, so do not verify. The
4673 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004674 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004675 } catch (ImsException e) {
4676 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
4680 }
4681
shilu366312e2019-12-17 09:28:10 -08004682 /**
4683 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4684 * @param subId The subscription to use to check the configuration.
4685 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004686 @Override
4687 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004688 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004689 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004690 final long identity = Binder.clearCallingIdentity();
4691 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004693 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004694 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004695 } catch (ImsException e) {
4696 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
4700 }
4701
4702 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004703 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004705 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004706 final long identity = Binder.clearCallingIdentity();
4707 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004708 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004709 // This setting doesn't require an active ImsService connection, so do not verify. The
4710 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004711 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004712 } catch (ImsException e) {
4713 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004714 } finally {
4715 Binder.restoreCallingIdentity(identity);
4716 }
4717 }
4718
shilu366312e2019-12-17 09:28:10 -08004719 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004720 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4721 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4722 * @param subId The subscription to use to check the configuration.
4723 */
4724 @Override
4725 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004726 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004727 mApp, subId, "isCrossSimCallingEnabledByUser");
4728 final long identity = Binder.clearCallingIdentity();
4729 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004730 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004731 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004732 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004733 } catch (ImsException e) {
4734 throw new ServiceSpecificException(e.getCode());
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 /**
4741 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4742 * Requires MODIFY_PHONE_STATE permission.
4743 * @param subId The subscription to use to check the configuration.
4744 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4745 * false otherwise
4746 */
4747 @Override
4748 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4750 "setCrossSimCallingEnabled");
4751 final long identity = Binder.clearCallingIdentity();
4752 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004753 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004754 // This setting doesn't require an active ImsService connection, so do not verify. The
4755 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004756 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004757 } catch (ImsException e) {
4758 throw new ServiceSpecificException(e.getCode());
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
4764 /**
shilu366312e2019-12-17 09:28:10 -08004765 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4766 * @param subId The subscription to use to check the configuration.
4767 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004769
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004771 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004772 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004773 final long identity = Binder.clearCallingIdentity();
4774 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004775 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004776 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004777 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004778 } catch (ImsException e) {
4779 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
4783 }
4784
4785 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004786 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004788 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004789 final long identity = Binder.clearCallingIdentity();
4790 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004791 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004792 // This setting doesn't require an active ImsService connection, so do not verify. The
4793 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004794 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004795 } catch (ImsException e) {
4796 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004797 } finally {
4798 Binder.restoreCallingIdentity(identity);
4799 }
4800 }
4801
4802 @Override
4803 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4805 "setVoWiFiNonPersistent");
4806 final long identity = Binder.clearCallingIdentity();
4807 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004808 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004809 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004810 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004811 } catch (ImsException e) {
4812 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 } finally {
4814 Binder.restoreCallingIdentity(identity);
4815 }
4816 }
4817
shilu366312e2019-12-17 09:28:10 -08004818 /**
4819 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4820 * @param subId The subscription to use to check the configuration.
4821 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004822 @Override
4823 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004824 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004825 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004826 final long identity = Binder.clearCallingIdentity();
4827 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004828 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004829 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004830 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004831 } catch (ImsException e) {
4832 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
4836 }
4837
4838 @Override
4839 public void setVoWiFiModeSetting(int subId, int mode) {
4840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4841 "setVoWiFiModeSetting");
4842 final long identity = Binder.clearCallingIdentity();
4843 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004844 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004845 // This setting doesn't require an active ImsService connection, so do not verify. The
4846 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004847 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004848 } catch (ImsException e) {
4849 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004850 } finally {
4851 Binder.restoreCallingIdentity(identity);
4852 }
4853 }
4854
4855 @Override
4856 public int getVoWiFiRoamingModeSetting(int subId) {
4857 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4858 final long identity = Binder.clearCallingIdentity();
4859 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004860 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004861 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004862 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004863 } catch (ImsException e) {
4864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
4868 }
4869
4870 @Override
4871 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4873 "setVoWiFiRoamingModeSetting");
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004876 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004877 // This setting doesn't require an active ImsService connection, so do not verify. The
4878 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004879 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004880 } catch (ImsException e) {
4881 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
4887 @Override
4888 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4890 "setRttCapabilityEnabled");
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004893 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004894 // This setting doesn't require an active ImsService connection, so do not verify. The
4895 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004896 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004897 } catch (ImsException e) {
4898 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
4902 }
4903
shilu366312e2019-12-17 09:28:10 -08004904 /**
4905 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4906 * @param subId The subscription to use to check the configuration.
4907 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 @Override
4909 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004910 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004911 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004912 final long identity = Binder.clearCallingIdentity();
4913 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004914 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004915 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004916 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004917 } catch (ImsException e) {
4918 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
4922 }
4923
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004924 @Override
4925 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4926 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004927
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004928 final long identity = Binder.clearCallingIdentity();
4929 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004930 if (!isImsAvailableOnDevice()) {
4931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4932 "IMS not available on device.");
4933 }
4934 int slotId = getSlotIndexOrException(subId);
4935 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004936
4937 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4938 if (controller != null) {
4939 ImsManager imsManager = controller.getImsManager(subId);
4940 if (imsManager != null) {
4941 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4942 } else {
4943 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4944 }
4945 } else {
4946 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4947 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004948 } catch (ImsException e) {
4949 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
4953 }
4954
4955 @Override
4956 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4957 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004958
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004960 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4961 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4962 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004964 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4965 if (controller != null) {
4966 ImsManager imsManager = controller.getImsManager(subId);
4967 if (imsManager != null) {
4968 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4969 } else {
4970 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4971 + " is inactive, ignoring unregister.");
4972 // If the ImsManager is not valid, just return, since the callback will already
4973 // have been removed internally.
4974 }
4975 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
4979 }
4980
joonhunshincffb7fc2021-11-28 07:32:01 +00004981 @Override
4982 public void registerFeatureProvisioningChangedCallback(int subId,
4983 IFeatureProvisioningCallback callback) {
4984 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4985 mApp, subId, "registerFeatureProvisioningChangedCallback");
4986
4987 final long identity = Binder.clearCallingIdentity();
4988 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4989 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4990 }
4991
joonhunshin91bc1952022-04-29 08:47:15 +00004992 try {
4993 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4994 if (controller == null) {
4995 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4996 "Device does not support IMS");
4997 }
4998 controller.addFeatureProvisioningChangedCallback(subId, callback);
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005002 }
5003
5004 @Override
5005 public void unregisterFeatureProvisioningChangedCallback(int subId,
5006 IFeatureProvisioningCallback callback) {
5007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5008 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5009
5010 final long identity = Binder.clearCallingIdentity();
5011 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5012 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5013 }
5014
joonhunshin91bc1952022-04-29 08:47:15 +00005015 try {
5016 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5017 if (controller == null) {
5018 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5019 return;
5020 }
5021 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005025 }
allenwtsu99c623b2020-01-03 18:24:23 +08005026
5027 private void checkModifyPhoneStatePermission(int subId, String message) {
5028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5029 message);
5030 }
5031
allenwtsu99c623b2020-01-03 18:24:23 +08005032 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005033 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005034 boolean isProvisioned) {
5035 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005039 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5040 if (controller == null) {
5041 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5042 return;
5043 }
5044 controller.setRcsProvisioningStatusForCapability(
5045 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
allenwtsu99c623b2020-01-03 18:24:23 +08005049 }
5050
5051
5052 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005053 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5054 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5055 mApp, subId, "getRcsProvisioningStatusForCapability");
5056
allenwtsu99c623b2020-01-03 18:24:23 +08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005059 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5060 if (controller == null) {
5061 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5062
5063 // device does not support IMS, this method will return true always.
5064 return true;
5065 }
5066 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
5070 }
5071
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005072 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005073 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5074 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005075 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005076
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005079 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5080 if (controller == null) {
5081 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5082 return;
5083 }
5084 controller.setImsProvisioningStatusForCapability(
5085 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005086 } finally {
5087 Binder.restoreCallingIdentity(identity);
5088 }
5089 }
5090
5091 @Override
5092 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005093 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5094 mApp, subId, "getProvisioningStatusForCapability");
5095
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005098 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5099 if (controller == null) {
5100 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005101
joonhunshin91bc1952022-04-29 08:47:15 +00005102 // device does not support IMS, this method will return true always.
5103 return true;
5104 }
5105 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
5109 }
5110
5111 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005112 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5113 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5114 mApp, subId, "isProvisioningRequiredForCapability");
5115
5116 final long identity = Binder.clearCallingIdentity();
5117 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005118 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5119 if (controller == null) {
5120 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5121
5122 // device does not support IMS, this method will return false
5123 return false;
5124 }
5125 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005128 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005129 }
5130
5131 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005132 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5133 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5134 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005135
joonhunshincffb7fc2021-11-28 07:32:01 +00005136 final long identity = Binder.clearCallingIdentity();
5137 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005138 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5139 if (controller == null) {
5140 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5141
5142 // device does not support IMS, this method will return false
5143 return false;
5144 }
5145 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 }
5150
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005151 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005152 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005153 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5154 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5155 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005156 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5157 mApp, subId, "getImsProvisioningInt");
5158
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005162 int slotId = getSlotIndex(subId);
5163 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5164 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5165 + subId + "' for key:" + key);
5166 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5167 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005168
joonhunshin91bc1952022-04-29 08:47:15 +00005169 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5170 if (controller == null) {
5171 loge("getImsProvisioningInt: Device does not support IMS");
5172
5173 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5174 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5175 }
5176 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005177 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5178 return retVal;
5179 }
5180
calvinpanb5a34062021-02-08 19:59:36 +08005181 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005182 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005183 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5184 + subId + "' for key:" + key);
5185 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
5189 }
5190
5191 @Override
5192 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5194 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5195 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005196 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5197 mApp, subId, "getImsProvisioningString");
5198
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005202 int slotId = getSlotIndex(subId);
5203 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5204 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5205 + subId + "' for key:" + key);
5206 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5207 }
calvinpanb5a34062021-02-08 19:59:36 +08005208 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005209 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005210 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5211 + subId + "' for key:" + key);
5212 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
5216 }
5217
5218 @Override
5219 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005220 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5221 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5222 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5224 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005225
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005226 final long identity = Binder.clearCallingIdentity();
5227 try {
5228 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005229 int slotId = getSlotIndex(subId);
5230 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5231 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5232 + subId + "' for key:" + key);
5233 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5234 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005235
joonhunshin91bc1952022-04-29 08:47:15 +00005236 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5237 if (controller == null) {
5238 loge("setImsProvisioningInt: Device does not support IMS");
5239
5240 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5241 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5242 }
5243 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005244 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5245 return retVal;
5246 }
5247
calvinpanb5a34062021-02-08 19:59:36 +08005248 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5249 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005250 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005251 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005252 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
5256 }
5257
5258 @Override
5259 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005260 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5261 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5262 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5264 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005268 int slotId = getSlotIndex(subId);
5269 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5270 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5271 + subId + "' for key:" + key);
5272 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5273 }
calvinpanb5a34062021-02-08 19:59:36 +08005274 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5275 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005276 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005277 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005278 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
5282 }
5283
Brad Ebinger919631e2021-06-02 17:46:35 -07005284 /**
5285 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5286 * for the given slot ID or no ImsResolver instance has been created.
5287 * @param slotId The slot ID that the IMS service is created for.
5288 * @throws ImsException If there is no ImsService configured for this slot.
5289 */
5290 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5291 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5292 ImsFeature.FEATURE_MMTEL)) {
5293 throw new ImsException("This subscription does not support MMTEL over IMS",
5294 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5295 }
5296 }
5297
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005298 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005299 int slotId = SubscriptionManager.getSlotIndex(subId);
5300 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005301 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5302 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005303 }
5304 return slotId;
5305 }
5306
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005307 private int getSlotIndex(int subId) {
5308 int slotId = SubscriptionManager.getSlotIndex(subId);
5309 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5310 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5311 }
5312 return slotId;
5313 }
5314
Wink Saville36469e72014-06-11 15:17:00 -07005315 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005316 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005317 */
5318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005319 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5320 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005321 try {
5322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5323 } catch (SecurityException se) {
5324 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5325 throw new SecurityException("Package " + callingPackage + " does not belong to "
5326 + Binder.getCallingUid());
5327 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005328 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005329 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005330 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005331 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005332 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005333 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005334 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005335 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5336 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 final Phone phone = getPhone(subId);
5341 if (phone != null) {
5342 return phone.getServiceState().getDataNetworkType();
5343 } else {
5344 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5345 }
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005349 }
5350
5351 /**
5352 * Returns the data network type
5353 */
5354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005355 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005356 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005357 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005358 }
5359
5360 /**
5361 * Returns the data network type for a subId
5362 */
5363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005364 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5365 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005366 String functionName = "getDataNetworkTypeForSubscriber";
5367 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5368 mApp, functionName)) {
5369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5370 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5371 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5372 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005373 }
5374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 final Phone phone = getPhone(subId);
5378 if (phone != null) {
5379 return phone.getServiceState().getDataNetworkType();
5380 } else {
5381 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5382 }
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005386 }
5387
5388 /**
Wink Saville36469e72014-06-11 15:17:00 -07005389 * Returns the Voice network type for a subId
5390 */
5391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005392 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5393 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005394 String functionName = "getVoiceNetworkTypeForSubscriber";
5395 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5396 mApp, functionName)) {
5397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5398 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5399 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5400 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005401 }
5402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
5405 final Phone phone = getPhone(subId);
5406 if (phone != null) {
5407 return phone.getServiceState().getVoiceNetworkType();
5408 } else {
5409 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5410 }
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005414 }
5415
5416 /**
5417 * @return true if a ICC card is present
5418 */
5419 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005420 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005421 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005422 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005423 }
5424
5425 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005426 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005427 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005428 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005429 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 final Phone phone = PhoneFactory.getPhone(slotIndex);
5433 if (phone != null) {
5434 return phone.getIccCard().hasIccCard();
5435 } else {
5436 return false;
5437 }
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005441 }
5442
5443 /**
5444 * Return if the current radio is LTE on CDMA. This
5445 * is a tri-state return value as for a period of time
5446 * the mode may be unknown.
5447 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005448 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005449 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005450 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005451 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005452 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005453 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5454 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5455 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005456 }
5457
Sanket Padawe356d7632015-06-22 14:03:32 -07005458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005459 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5460 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005461 try {
5462 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5463 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005464 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5465 }
5466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 final long identity = Binder.clearCallingIdentity();
5468 try {
5469 final Phone phone = getPhone(subId);
5470 if (phone == null) {
5471 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5472 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005473 return TelephonyProperties.lte_on_cdma_device()
5474 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 }
5476 } finally {
5477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005478 }
Wink Saville36469e72014-06-11 15:17:00 -07005479 }
5480
Wink Saville36469e72014-06-11 15:17:00 -07005481 /**
5482 * {@hide}
5483 * Returns Default subId, 0 in the case of single standby.
5484 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005485 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005486 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005487 }
5488
Shishir Agrawala9f32182016-04-12 12:00:16 -07005489 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005490 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005491 }
5492
Wink Savilleb564aae2014-10-23 10:18:09 -07005493 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005494 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005495 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005496
Pengquan Menge92a50d2018-09-21 15:54:48 -07005497 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005498 return getSubscriptionManagerService().isActiveSubId(subId,
5499 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005500 }
5501
Ihab Awadf2177b72013-11-25 13:33:23 -08005502 /**
5503 * @see android.telephony.TelephonyManager.WifiCallingChoices
5504 */
5505 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 final long identity = Binder.clearCallingIdentity();
5507 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005508 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5510 getWhenToMakeWifiCallsDefaultPreference());
5511 } finally {
5512 Binder.restoreCallingIdentity(identity);
5513 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005514 }
5515
5516 /**
5517 * @see android.telephony.TelephonyManager.WifiCallingChoices
5518 */
5519 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005523 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005528 }
5529
Sailesh Nepald1e68152013-12-12 19:08:02 -08005530 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005531 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005532 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005533 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005534
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005535 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5536 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5537 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005538 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005539 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005540 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005541 }
5542 return PhoneFactory.getPhone(phoneId);
5543 }
5544
Shishir Agrawal566b7612013-10-28 14:41:00 -07005545 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005546 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005547 @NonNull IccLogicalChannelRequest request) {
5548 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5549 /*message=*/ "iccOpenLogicalChannel");
5550
5551 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5552 // Verify that the callingPackage in the request belongs to the calling UID
5553 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5554
5555 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005556 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005557
Rambo Wanga1782702021-11-10 20:15:19 -08005558 private Phone getPhoneFromValidIccLogicalChannelRequest(
5559 @NonNull IccLogicalChannelRequest request, String message) {
5560 Phone phone;
5561 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5563 mApp, request.subId, message);
5564 phone = getPhoneFromSubId(request.subId);
5565 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5566 enforceModifyPermission();
5567 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5568 } else {
5569 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005570 }
Rambo Wanga1782702021-11-10 20:15:19 -08005571 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005572 }
5573
5574 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005575 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 final long identity = Binder.clearCallingIdentity();
5577 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005578 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005580 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5581 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005582 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5583 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 loge("The calling package is not allowed to access ISD-R.");
5585 throw new SecurityException(
5586 "The calling package is not allowed to access ISD-R.");
5587 }
Derek Tan740e1672017-06-27 14:56:27 -07005588 }
Derek Tan740e1672017-06-27 14:56:27 -07005589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005591 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5592 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 return response;
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005597 }
5598
5599 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005600 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5601 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5602 /*message=*/"iccCloseLogicalChannel");
5603
5604 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5605
5606 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005608
Rambo Wanga1782702021-11-10 20:15:19 -08005609 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5610 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005611 // before this feature is enabled, this API should only return false if
5612 // the operation fails instead of throwing runtime exception for
5613 // backward-compatibility.
5614 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5615 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 final long identity = Binder.clearCallingIdentity();
5617 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005618 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005619 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 }
Chen Xue9d737e2022-01-01 23:41:31 -08005621 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005622 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005623 Boolean success = false;
5624 if (result instanceof RuntimeException) {
5625 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005626 if (shouldThrowExceptionOnFailure) {
5627 throw (RuntimeException) result;
5628 } else {
5629 return false;
5630 }
Chen Xue9d737e2022-01-01 23:41:31 -08005631 } else if (result instanceof Boolean) {
5632 success = (Boolean) result;
5633 } else {
5634 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5635 }
Rambo Wanga1782702021-11-10 20:15:19 -08005636 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 return success;
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005640 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005641 }
5642
5643 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005644 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005645 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5647 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005648 if (DBG) {
5649 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5650 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5651 + p3 + " data=" + data);
5652 }
5653 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5654 command, p1, p2, p3, data);
5655 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005656
Jordan Liu4c733742019-02-28 12:03:40 -08005657 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005658 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005659 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005660 enforceModifyPermission();
5661 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005662 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005663 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5664 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005665 }
5666 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005667 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5668 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005669 }
5670
5671 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5672 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 final long identity = Binder.clearCallingIdentity();
5674 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005675 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 return "";
5677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005680 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5681 null /* workSource */);
5682 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 // Append the returned status code to the end of the response payload.
5685 String s = Integer.toHexString(
5686 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5687 if (response.payload != null) {
5688 s = IccUtils.bytesToHexString(response.payload) + s;
5689 }
5690 return s;
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005693 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005694 }
Jake Hambye994d462014-02-03 13:10:13 -08005695
Evan Charltonc66da362014-05-16 14:06:40 -07005696 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005697 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5698 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5700 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005702 if (DBG) {
5703 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5704 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5705 }
5706 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5707 cla, command, p1, p2, p3, data);
5708 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005709
Jordan Liu4c733742019-02-28 12:03:40 -08005710 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005711 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005712 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005713 enforceModifyPermission();
5714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5715 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005716 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005717 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5718 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005719 }
5720
5721 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005722 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5723 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005724 }
5725
5726 // open APDU basic channel assuming the caller has sufficient permissions
5727 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5728 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5732 && TextUtils.equals(ISDR_AID, data)) {
5733 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005734 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5735 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 if (bestComponent == null
5737 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5738 loge("The calling package is not allowed to select ISD-R.");
5739 throw new SecurityException(
5740 "The calling package is not allowed to select ISD-R.");
5741 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005742 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005745 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5746 null /* workSource */);
5747 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 // Append the returned status code to the end of the response payload.
5750 String s = Integer.toHexString(
5751 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5752 if (response.payload != null) {
5753 s = IccUtils.bytesToHexString(response.payload) + s;
5754 }
5755 return s;
5756 } finally {
5757 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005758 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005759 }
5760
5761 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005762 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005763 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5765 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 if (DBG) {
5770 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5771 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5772 }
5773
5774 IccIoResult response =
5775 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5776 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5777 subId);
5778
5779 if (DBG) {
5780 log("Exchange SIM_IO [R]" + response);
5781 }
5782
5783 byte[] result = null;
5784 int length = 2;
5785 if (response.payload != null) {
5786 length = 2 + response.payload.length;
5787 result = new byte[length];
5788 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5789 } else {
5790 result = new byte[length];
5791 }
5792
5793 result[length - 1] = (byte) response.sw2;
5794 result[length - 2] = (byte) response.sw1;
5795 return result;
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005798 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005799 }
5800
Nathan Haroldb3014052017-01-25 15:57:32 -08005801 /**
5802 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5803 * on a particular subscription
5804 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005805 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5806 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005808 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005809 return null;
5810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811
5812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 if (appType != TelephonyManager.APPTYPE_USIM
5815 && appType != TelephonyManager.APPTYPE_SIM) {
5816 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5817 return null;
5818 }
5819 Object response = sendRequest(
5820 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5821 if (response instanceof String[]) {
5822 return (String[]) response;
5823 }
yincheng zhao2737e882019-09-06 17:06:54 -07005824 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005826 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 } finally {
5828 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005829 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005830 }
5831
yincheng zhao2737e882019-09-06 17:06:54 -07005832 /**
5833 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5834 * subscription.
5835 *
5836 * @param subId the id of the subscription.
5837 * @param appType the uicc app type, must be USIM or SIM.
5838 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5839 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005840 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005841 * @return number of fplmns that is successfully written to the SIM.
5842 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005843 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5844 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5846 mApp, subId, "setForbiddenPlmns");
5847
yincheng zhao2737e882019-09-06 17:06:54 -07005848 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5849 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5850 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5851 }
5852 if (fplmns == null) {
5853 throw new IllegalArgumentException("Fplmn List provided is null");
5854 }
5855 for (String fplmn : fplmns) {
5856 if (!CellIdentity.isValidPlmn(fplmn)) {
5857 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5858 }
5859 }
5860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 Object response = sendRequest(
5863 CMD_SET_FORBIDDEN_PLMNS,
5864 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5865 subId);
5866 return (int) response;
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
5870 }
5871
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005872 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005873 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5875 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005876
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5880 if (response.payload == null) {
5881 return "";
5882 }
Evan Charltonc66da362014-05-16 14:06:40 -07005883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 // Append the returned status code to the end of the response payload.
5885 String s = Integer.toHexString(
5886 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5887 s = IccUtils.bytesToHexString(response.payload) + s;
5888 return s;
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
Evan Charltonc66da362014-05-16 14:06:40 -07005892 }
5893
Jake Hambye994d462014-02-03 13:10:13 -08005894 /**
5895 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5896 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5897 *
5898 * @param itemID the ID of the item to read
5899 * @return the NV item as a String, or null on error.
5900 */
5901 @Override
5902 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5905 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
5909 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005910 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5912 return value;
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Jake Hambye994d462014-02-03 13:10:13 -08005916 }
5917
5918 /**
5919 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5920 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5921 *
5922 * @param itemID the ID of the item to read
5923 * @param itemValue the value to write, as a String
5924 * @return true on success; false on any failure
5925 */
5926 @Override
5927 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5930 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931
5932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5935 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005936 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5938 return success;
5939 } finally {
5940 Binder.restoreCallingIdentity(identity);
5941 }
Jake Hambye994d462014-02-03 13:10:13 -08005942 }
5943
5944 /**
5945 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5946 * Used for device configuration by some CDMA operators.
5947 *
5948 * @param preferredRoamingList byte array containing the new PRL
5949 * @return true on success; false on any failure
5950 */
5951 @Override
5952 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5954 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
5957 try {
5958 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5959 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5960 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5961 return success;
5962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Jake Hambye994d462014-02-03 13:10:13 -08005965 }
5966
5967 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005968 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005969 * Used for device configuration by some CDMA operators.
5970 *
chen xu6dac5ab2018-10-26 17:39:23 -07005971 * @param slotIndex - device slot.
5972 *
Jake Hambye994d462014-02-03 13:10:13 -08005973 * @return true on success; false on any failure
5974 */
5975 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005976 public boolean resetModemConfig(int slotIndex) {
5977 Phone phone = PhoneFactory.getPhone(slotIndex);
5978 if (phone != null) {
5979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5980 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981
chen xu6dac5ab2018-10-26 17:39:23 -07005982 final long identity = Binder.clearCallingIdentity();
5983 try {
5984 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5985 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5986 return success;
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 }
chen xu6dac5ab2018-10-26 17:39:23 -07005991 return false;
5992 }
5993
5994 /**
5995 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5996 *
5997 * @param slotIndex - device slot.
5998 *
5999 * @return true on success; false on any failure
6000 */
6001 @Override
6002 public boolean rebootModem(int slotIndex) {
6003 Phone phone = PhoneFactory.getPhone(slotIndex);
6004 if (phone != null) {
6005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6006 mApp, phone.getSubId(), "rebootModem");
6007
6008 final long identity = Binder.clearCallingIdentity();
6009 try {
6010 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6011 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6012 return success;
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 }
6017 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006018 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006019
Brad Ebinger51f743a2017-01-23 13:50:20 -08006020 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006021 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6022 * {@link #disableIms(int)}.
6023 * @param slotIndex device slot.
6024 */
6025 public void resetIms(int slotIndex) {
6026 enforceModifyPermission();
6027
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
6030 if (mImsResolver == null) {
6031 // may happen if the does not support IMS.
6032 return;
6033 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006034 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
6038 }
6039
6040 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006041 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6042 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006043 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006044 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006045 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006049 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006050 // may happen if the device does not support IMS.
6051 return;
6052 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006053 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006057 }
6058
6059 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006060 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6061 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006062 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006063 public void disableIms(int slotId) {
6064 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065
6066 final long identity = Binder.clearCallingIdentity();
6067 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006068 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006069 // may happen if the device does not support IMS.
6070 return;
6071 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006072 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 } finally {
6074 Binder.restoreCallingIdentity(identity);
6075 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006076 }
6077
6078 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006079 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6080 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006081 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006082 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006083 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006084 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006088 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006089 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6090 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006091 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006092 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 } finally {
6094 Binder.restoreCallingIdentity(identity);
6095 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006096 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006097 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006098 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6099 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006100 @Override
6101 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006102 enforceModifyPermission();
6103
6104 final long identity = Binder.clearCallingIdentity();
6105 try {
6106 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006107 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
6111 }
6112
6113 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006114 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006115 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006116 */
6117 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119
6120 final long identity = Binder.clearCallingIdentity();
6121 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006122 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006123 // may happen if the device does not support IMS.
6124 return null;
6125 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006126 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006130 }
6131
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006132 /**
6133 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006134 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006135 */
6136 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138
6139 final long identity = Binder.clearCallingIdentity();
6140 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006141 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006142 // may happen if the device does not support IMS.
6143 return null;
6144 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006145 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146 } finally {
6147 Binder.restoreCallingIdentity(identity);
6148 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006149 }
6150
Brad Ebinger884c07b2018-02-15 16:17:40 -08006151 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006152 * Sets the ImsService Package Name that Telephony will bind to.
6153 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006154 * @param slotIndex the slot ID that the ImsService should bind for.
6155 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006156 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006157 * @param featureTypes An integer array of feature types associated with a packageName.
6158 * @param packageName The name of the package that the current configuration will be replaced
6159 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006160 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006161 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006162 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6163 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006164 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006166 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 final long identity = Binder.clearCallingIdentity();
6169 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006170 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006171 // may happen if the device does not support IMS.
6172 return false;
6173 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006174 Map<Integer, String> featureConfig = new HashMap<>();
6175 for (int featureType : featureTypes) {
6176 featureConfig.put(featureType, packageName);
6177 }
6178 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6179 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 } finally {
6181 Binder.restoreCallingIdentity(identity);
6182 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006183 }
6184
6185 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006186 * Clears any carrier ImsService overrides for the slot index specified that were previously
6187 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6188 *
6189 * This should only be used for testing.
6190 *
6191 * @param slotIndex the slot ID that the ImsService should bind for.
6192 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6193 */
6194 @Override
6195 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6197 "clearCarrierImsServiceOverride");
6198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006199 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006200
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 if (mImsResolver == null) {
6204 // may happen if the device does not support IMS.
6205 return false;
6206 }
6207 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6208 } finally {
6209 Binder.restoreCallingIdentity(identity);
6210 }
6211 }
6212
6213 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006214 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006215 *
6216 * @param slotId The slot that the ImsService is associated with.
6217 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6218 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006219 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006220 * @return the package name of the ImsService configuration.
6221 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006222 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6223 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006224 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006225 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6226 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 final long identity = Binder.clearCallingIdentity();
6229 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006230 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006231 // may happen if the device does not support IMS.
6232 return "";
6233 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006234 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006235 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6236 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006240 }
6241
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006242 /**
6243 * Get the MmTelFeature state associated with the requested subscription id.
6244 * @param subId The subscription that the MmTelFeature is associated with.
6245 * @param callback A callback with an integer containing the
6246 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6247 */
6248 @Override
6249 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6250 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006251 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6252 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6253 "IMS not available on device.");
6254 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006255 final long token = Binder.clearCallingIdentity();
6256 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006257 int slotId = getSlotIndex(subId);
6258 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6259 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6260 + subId + "'");
6261 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6262 }
6263 verifyImsMmTelConfiguredOrThrow(slotId);
6264 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6265 try {
6266 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6267 } catch (RemoteException e) {
6268 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6269 + "Ignore");
6270 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006271 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006272 } catch (ImsException e) {
6273 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006274 } finally {
6275 Binder.restoreCallingIdentity(token);
6276 }
6277 }
6278
Daniel Brightbb5840b2021-01-12 15:48:18 -08006279 /**
6280 * Sets the ims registration state on all valid {@link Phone}s.
6281 */
6282 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006287 // NOTE: Before S, this method only set the default phone.
6288 for (final Phone phone : PhoneFactory.getPhones()) {
6289 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6290 phone.setImsRegistrationState(registered);
6291 }
6292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 } finally {
6294 Binder.restoreCallingIdentity(identity);
6295 }
Wink Saville36469e72014-06-11 15:17:00 -07006296 }
6297
6298 /**
Stuart Scott54788802015-03-30 13:18:01 -07006299 * Set the network selection mode to automatic.
6300 *
6301 */
6302 @Override
6303 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6305 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306
6307 final long identity = Binder.clearCallingIdentity();
6308 try {
shilufc958392020-01-20 11:36:01 -08006309 if (!isActiveSubscription(subId)) {
6310 return;
6311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006313 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6314 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Stuart Scott54788802015-03-30 13:18:01 -07006318 }
6319
Jack Yud10cdd42020-09-28 20:28:01 -07006320 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006321 * Ask the radio to connect to the input network and change selection mode to manual.
6322 *
6323 * @param subId the id of the subscription.
6324 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6325 * the operator to attach to.
6326 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6327 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6328 * normal network selection next time.
6329 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006330 */
6331 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006332 public boolean setNetworkSelectionModeManual(
6333 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6335 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006336
Jack Yu285100e2022-12-02 22:48:35 -08006337 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006338 if (!isActiveSubscription(subId)) {
6339 return false;
6340 }
6341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006343 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006345 if (DBG) {
6346 log("setNetworkSelectionModeManual: subId: " + subId
6347 + " operator: " + operatorInfo);
6348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6350 } finally {
6351 Binder.restoreCallingIdentity(identity);
6352 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006353 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006354 /**
shilu84f6e8b2019-12-19 13:58:01 -08006355 * Get the manual network selection
6356 *
6357 * @param subId the id of the subscription.
6358 *
6359 * @return the previously saved user selected PLMN
6360 */
6361 @Override
6362 public String getManualNetworkSelectionPlmn(int subId) {
6363 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006364 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6365 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006366
6367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006370 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006371 }
6372
6373 final Phone phone = getPhone(subId);
6374 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006375 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006376 }
6377 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6378 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006379 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006384
6385 /**
6386 * Scans for available networks.
6387 */
6388 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006389 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6390 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6392 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006393 LocationAccessPolicy.LocationPermissionResult locationResult =
6394 LocationAccessPolicy.checkLocationPermission(mApp,
6395 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6396 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006397 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006398 .setCallingPid(Binder.getCallingPid())
6399 .setCallingUid(Binder.getCallingUid())
6400 .setMethod("getCellNetworkScanResults")
6401 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006402 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6403 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006404 .build());
6405 switch (locationResult) {
6406 case DENIED_HARD:
6407 throw new SecurityException("Not allowed to access scan results -- location");
6408 case DENIED_SOFT:
6409 return null;
6410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411
Pengquan Menga1bb6272018-09-06 09:59:22 -07006412 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 try {
6414 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006415 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006420 }
6421
6422 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006423 * Get the call forwarding info, given the call forwarding reason.
6424 */
6425 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006426 public void getCallForwarding(int subId, int callForwardingReason,
6427 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006428 enforceReadPrivilegedPermission("getCallForwarding");
6429 long identity = Binder.clearCallingIdentity();
6430 try {
6431 if (DBG) {
6432 log("getCallForwarding: subId " + subId
6433 + " callForwardingReason" + callForwardingReason);
6434 }
Hall Liu27d24262020-09-18 19:04:59 -07006435
6436 Phone phone = getPhone(subId);
6437 if (phone == null) {
6438 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006439 callback.onError(
6440 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006441 } catch (RemoteException e) {
6442 // ignore
6443 }
6444 return;
6445 }
6446
6447 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6448 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6449 @Override
6450 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6451 try {
6452 callback.onCallForwardingInfoAvailable(info);
6453 } catch (RemoteException e) {
6454 // ignore
6455 }
6456 }
6457
6458 @Override
6459 public void onError(int error) {
6460 try {
6461 callback.onError(error);
6462 } catch (RemoteException e) {
6463 // ignore
6464 }
6465 }
6466 });
6467 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
6471 }
6472
6473 /**
6474 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6475 * reason, the number to forward, and the timeout before the forwarding is attempted.
6476 */
6477 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006478 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6479 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006480 enforceModifyPermission();
6481 long identity = Binder.clearCallingIdentity();
6482 try {
6483 if (DBG) {
6484 log("setCallForwarding: subId " + subId
6485 + " callForwardingInfo" + callForwardingInfo);
6486 }
Hall Liu27d24262020-09-18 19:04:59 -07006487
6488 Phone phone = getPhone(subId);
6489 if (phone == null) {
6490 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006491 callback.accept(
6492 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006493 } catch (RemoteException e) {
6494 // ignore
6495 }
6496 return;
6497 }
6498
6499 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6500 FunctionalUtils.ignoreRemoteException(callback::accept));
6501
6502 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
Hall Liu27d24262020-09-18 19:04:59 -07006509 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006510 */
6511 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006512 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006513 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006514 long identity = Binder.clearCallingIdentity();
6515 try {
Hall Liu27d24262020-09-18 19:04:59 -07006516 Phone phone = getPhone(subId);
6517 if (phone == null) {
6518 try {
6519 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6520 } catch (RemoteException e) {
6521 // ignore
6522 }
6523 return;
6524 }
SongFerngWang0e767992021-03-31 22:08:45 +08006525 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6526 PersistableBundle c = configManager.getConfigForSubId(subId);
6527 boolean requireUssd = c.getBoolean(
6528 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006529
Shuo Qian4a594052020-01-23 11:59:30 -08006530 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006531 if (requireUssd) {
6532 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6533 getSubscriptionCarrierId(subId));
6534 String newUssdCommand = "";
6535 try {
6536 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006537 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006538 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6539 } catch (NullPointerException e) {
6540 loge("Failed to generate USSD number" + e);
6541 }
6542 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6543 mMainThreadHandler, callback, carrierXmlParser,
6544 CarrierXmlParser.SsEntry.SSAction.QUERY);
6545 final String ussdCommand = newUssdCommand;
6546 Executors.newSingleThreadExecutor().execute(() -> {
6547 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6548 });
6549 } else {
6550 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6551 callback::accept);
6552 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6553 }
Shuo Qian4a594052020-01-23 11:59:30 -08006554 } finally {
6555 Binder.restoreCallingIdentity(identity);
6556 }
6557 }
6558
6559 /**
Hall Liu27d24262020-09-18 19:04:59 -07006560 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006561 */
6562 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006563 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006564 enforceModifyPermission();
6565 long identity = Binder.clearCallingIdentity();
6566 try {
Hall Liu27d24262020-09-18 19:04:59 -07006567 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6568
6569 Phone phone = getPhone(subId);
6570 if (phone == null) {
6571 try {
6572 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6573 } catch (RemoteException e) {
6574 // ignore
6575 }
6576 return;
6577 }
6578
SongFerngWang0e767992021-03-31 22:08:45 +08006579 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6580 PersistableBundle c = configManager.getConfigForSubId(subId);
6581 boolean requireUssd = c.getBoolean(
6582 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006583
SongFerngWang0e767992021-03-31 22:08:45 +08006584 if (DBG) log("getCallWaitingStatus: subId " + subId);
6585 if (requireUssd) {
6586 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6587 getSubscriptionCarrierId(subId));
6588 CarrierXmlParser.SsEntry.SSAction ssAction =
6589 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6590 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6591 String newUssdCommand = "";
6592 try {
6593 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006594 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006595 .makeCommand(ssAction, null);
6596 } catch (NullPointerException e) {
6597 loge("Failed to generate USSD number" + e);
6598 }
6599 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6600 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6601 final String ussdCommand = newUssdCommand;
6602 Executors.newSingleThreadExecutor().execute(() -> {
6603 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6604 });
6605 } else {
6606 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6607 FunctionalUtils.ignoreRemoteException(callback::accept));
6608
6609 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6610 }
Shuo Qian4a594052020-01-23 11:59:30 -08006611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
6614 }
6615
6616 /**
yinxub1bed742017-04-17 11:45:04 -07006617 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006618 *
yinxub1bed742017-04-17 11:45:04 -07006619 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006620 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6621 * location related information which will be sent if the caller already possess
6622 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006623 * @param request contains the radio access networks with bands/channels to scan
6624 * @param messenger callback messenger for scan results or errors
6625 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006626 * @return the id of the requested scan which can be used to stop the scan.
6627 */
6628 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006629 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6630 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006631 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6633 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006634 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006635 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6636 if (!renounceFineLocationAccess) {
6637 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006638 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6639 .setCallingPackage(callingPackage)
6640 .setCallingFeatureId(callingFeatureId)
6641 .setCallingPid(Binder.getCallingPid())
6642 .setCallingUid(Binder.getCallingUid())
6643 .setMethod("requestNetworkScan")
6644 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6645 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6646 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6647 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006648 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006649 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006650 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6651 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006652 if (e != null) {
6653 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6654 throw e;
6655 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006656 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006657 return TelephonyScanManager.INVALID_SCAN_ID;
6658 }
6659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 }
Hall Liu912dfd32019-04-25 14:02:26 -07006661 int callingUid = Binder.getCallingUid();
6662 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006666 renounceFineLocationAccess, request, messenger, binder,
6667 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006668 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
yinxu504e1392017-04-12 16:03:22 -07006672 }
6673
Hall Liub2ac8ef2019-02-28 15:56:23 -08006674 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006675 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006676 boolean hasCarrierPriv;
6677 final long identity = Binder.clearCallingIdentity();
6678 try {
6679 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6680 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
Hall Liu558027f2019-05-15 19:14:05 -07006684 boolean hasNetworkScanPermission =
6685 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006686 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006687
6688 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6689 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6690 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006691 }
6692
6693 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6694 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006695 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6696 return new SecurityException("Specific channels must not be"
6697 + " scanned without location access.");
6698 }
6699 }
6700 }
6701
Hall Liub2ac8ef2019-02-28 15:56:23 -08006702 return null;
6703 }
6704
yinxu504e1392017-04-12 16:03:22 -07006705 /**
6706 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006707 *
6708 * @param subId id of the subscription
6709 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006710 */
6711 @Override
6712 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6714 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715
Hall Liu912dfd32019-04-25 14:02:26 -07006716 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 final long identity = Binder.clearCallingIdentity();
6718 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006719 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 } finally {
6721 Binder.restoreCallingIdentity(identity);
6722 }
yinxu504e1392017-04-12 16:03:22 -07006723 }
6724
6725 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006726 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006727 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006728 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006729 */
6730 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006731 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006732 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006733 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006734 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735
6736 final long identity = Binder.clearCallingIdentity();
6737 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006738 if (DBG) log("getAllowedNetworkTypesBitmask");
6739 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6740 int networkTypesBitmask = (result != null ? result[0] : -1);
6741 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6742 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006746 }
6747
6748 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006749 * Get the allowed network types for certain reason.
6750 *
6751 * @param subId the id of the subscription.
6752 * @param reason the reason the allowed network type change is taking place
6753 * @return the allowed network types.
6754 */
6755 @Override
6756 public long getAllowedNetworkTypesForReason(int subId,
6757 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006758 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006759 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006760 final long identity = Binder.clearCallingIdentity();
6761 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006762 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
6766 }
6767
6768 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006769 * Enable/Disable E-UTRA-NR Dual Connectivity
6770 * @param subId subscription id of the sim card
6771 * @param nrDualConnectivityState expected NR dual connectivity state
6772 * This can be passed following states
6773 * <ol>
6774 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6775 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6776 * <li>Disable NR dual connectivity and force secondary cell to be released
6777 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6778 * </ol>
6779 * @return operation result.
6780 */
6781 @Override
6782 public int setNrDualConnectivityState(int subId,
6783 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6785 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006786 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006787 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6788 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6789 }
6790
Sooraj Sasindran37444802020-08-11 10:40:43 -07006791 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6792 final long identity = Binder.clearCallingIdentity();
6793 try {
6794 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6795 nrDualConnectivityState, subId,
6796 workSource);
6797 if (DBG) log("enableNRDualConnectivity result: " + result);
6798 return result;
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
6802 }
6803
6804 /**
6805 * Is E-UTRA-NR Dual Connectivity enabled
6806 * @return true if dual connectivity is enabled else false
6807 */
6808 @Override
6809 public boolean isNrDualConnectivityEnabled(int subId) {
6810 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006811 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006812 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006813 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006814 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6815 return false;
6816 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006817 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6818 final long identity = Binder.clearCallingIdentity();
6819 try {
6820 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6821 null, subId, workSource);
6822 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6823 return isEnabled;
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
6826 }
6827 }
6828
6829 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006830 * Set the allowed network types of the device and
6831 * provide the reason triggering the allowed network change.
6832 *
6833 * @param subId the id of the subscription.
6834 * @param reason the reason the allowed network type change is taking place
6835 * @param allowedNetworkTypes the allowed network types.
6836 * @return true on success; false on any failure.
6837 */
6838 @Override
6839 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006840 @TelephonyManager.AllowedNetworkTypesReason int reason,
6841 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6843 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006844 // If the caller only has carrier privileges, then they should not be able to override
6845 // any network types which were set for security reasons.
6846 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6847 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006848 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006849 throw new SecurityException(
6850 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006851 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006852 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006853 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006854 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006855 return false;
6856 }
6857 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6858 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006859 return false;
6860 }
6861
Jack Yu5b494332023-01-23 18:18:04 +00006862 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6863 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006864
Jack Yue37dd262022-12-16 11:53:37 -08006865 Phone phone = getPhone(subId);
6866 if (phone == null) {
6867 return false;
6868 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006869
Jack Yue37dd262022-12-16 11:53:37 -08006870 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006871 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006872 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006873 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006874
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006875 final long identity = Binder.clearCallingIdentity();
6876 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006877 Boolean success = (Boolean) sendRequest(
6878 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6879 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6880
6881 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6882 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
6886 }
6887
6888 /**
Miaoa84611c2019-03-15 09:21:10 +08006889 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006890 *
Miaoa84611c2019-03-15 09:21:10 +08006891 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006892 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006893 * @hide
6894 */
6895 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006896 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006899 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 try {
Miaoa84611c2019-03-15 09:21:10 +08006901 if (phone != null) {
6902 return phone.hasMatchedTetherApnSetting();
6903 } else {
6904 return false;
6905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 } finally {
6907 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006908 }
Junda Liu475951f2014-11-07 16:45:03 -08006909 }
6910
6911 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006912 * Get the user enabled state of Mobile Data.
6913 *
6914 * TODO: remove and use isUserDataEnabled.
6915 * This can't be removed now because some vendor codes
6916 * calls through ITelephony directly while they should
6917 * use TelephonyManager.
6918 *
6919 * @return true on enabled
6920 */
6921 @Override
6922 public boolean getDataEnabled(int subId) {
6923 return isUserDataEnabled(subId);
6924 }
6925
6926 /**
6927 * Get whether mobile data is enabled per user setting.
6928 *
6929 * There are other factors deciding whether mobile data is actually enabled, but they are
6930 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006931 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006932 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6933 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006934 *
6935 * @return {@code true} if data is enabled else {@code false}
6936 */
6937 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006938 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006939 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006940 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006941 try {
6942 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6943 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006944 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006945 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6946 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006947 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006949 mApp, subId, functionName);
6950
Robert Greenwalt646120a2014-05-23 11:54:03 -07006951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952
6953 final long identity = Binder.clearCallingIdentity();
6954 try {
Jack Yu285100e2022-12-02 22:48:35 -08006955 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6957 Phone phone = PhoneFactory.getPhone(phoneId);
6958 if (phone != null) {
6959 boolean retVal = phone.isUserDataEnabled();
6960 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6961 return retVal;
6962 } else {
6963 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6964 return false;
6965 }
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006968 }
6969 }
6970
6971 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006972 * Checks if the device is capable of mobile data by considering whether whether the
6973 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6974 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006975 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006976 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006977 */
6978 @Override
6979 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006980 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006981 try {
6982 try {
6983 mApp.enforceCallingOrSelfPermission(
6984 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006985 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006986 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006987 try {
6988 mApp.enforceCallingOrSelfPermission(
6989 android.Manifest.permission.READ_PHONE_STATE,
6990 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006991 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006992 mApp.enforceCallingOrSelfPermission(
6993 permission.READ_BASIC_PHONE_STATE, functionName);
6994 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006995 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006996 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006997 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999
7000 final long identity = Binder.clearCallingIdentity();
7001 try {
Jack Yu285100e2022-12-02 22:48:35 -08007002 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 Phone phone = PhoneFactory.getPhone(phoneId);
7004 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007005 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007006 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 return retVal;
7008 } else {
7009 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7010 return false;
7011 }
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007014 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007015 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007016
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007017 /**
7018 * Check if data is enabled for a specific reason
7019 * @param subId Subscription index
7020 * @param reason the reason the data enable change is taking place
7021 * @return {@code true} if the overall data is enabled; {@code false} if not.
7022 */
7023 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007024 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007025 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007026 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007027 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007028 try {
7029 mApp.enforceCallingOrSelfPermission(
7030 android.Manifest.permission.ACCESS_NETWORK_STATE,
7031 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007032 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007033 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7034 functionName);
7035 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007036 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007037 try {
7038 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007039 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007040 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007042 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007043 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007044 }
7045
7046
7047 final long identity = Binder.clearCallingIdentity();
7048 try {
Jack Yu285100e2022-12-02 22:48:35 -08007049 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007050 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007051 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007052 + " reason=" + reason);
7053 }
7054 Phone phone = PhoneFactory.getPhone(phoneId);
7055 if (phone != null) {
7056 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007057 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007058 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007059 return retVal;
7060 } else {
7061 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007062 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007063 + subId + " retVal=false");
7064 }
7065 return false;
7066 }
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
7070 }
7071
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007072 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007073 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007074 // No permission needed; this only lets the caller inspect their own status.
7075 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007076 }
Junda Liu29340342014-07-10 15:23:27 -07007077
7078 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007079 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007080 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007081 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7082 }
7083
7084 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7085 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007087 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007088 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7089 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007090 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7091 if (cpt == null) {
7092 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007093 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7094 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007095 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007096 }
7097
7098 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007099 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007100 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007101 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007102 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007103 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007104 Phone phone = getPhone(subId);
7105 if (phone == null) {
7106 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7107 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7108 }
7109 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7110 if (cpt == null) {
7111 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007112 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7113 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007114 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007115 }
7116
7117 @Override
7118 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007119 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007120 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7121 }
7122
7123 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007124 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007125 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007126 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007127 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007128 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7129 Phone phone = PhoneFactory.getPhone(phoneId);
7130 if (phone == null) {
7131 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007132 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007133 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7134 if (cpt == null) {
7135 continue;
7136 }
7137 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007138 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7139 break;
7140 }
7141 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007142 return result;
Junda Liu29340342014-07-10 15:23:27 -07007143 }
Derek Tan89e89d42014-07-08 17:00:10 -07007144
7145 @Override
Junda Liue64de782015-04-16 17:19:16 -07007146 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007147 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007148 Phone phone = PhoneFactory.getPhone(phoneId);
7149 if (phone == null) {
7150 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007151 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007152 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7153 if (cpt == null) {
7154 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007155 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007156 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007157 }
7158
Amith Yamasani6e118872016-02-19 12:53:51 -08007159 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007160 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007161 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007162 Phone phone = PhoneFactory.getPhone(phoneId);
7163 if (phone == null) {
7164 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007165 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007166 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7167 if (cpt == null) {
7168 return Collections.emptyList();
7169 }
7170 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007171 }
7172
chen xuf7e9fe82019-05-09 19:31:02 -07007173 @Override
7174 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007175 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007176 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007177 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007178 try {
7179 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7180 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7181 }
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007184 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007185 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007186 }
7187
Rambo Wang6812ffb2022-03-15 16:54:17 -07007188 @Override
7189 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7190 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7191
7192 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7193 if (phone == null) {
7194 return null;
7195 }
7196 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7197 if (cpt == null) {
7198 return null;
7199 }
7200 return cpt.getCarrierServicePackageName();
7201 }
7202
Wink Savilleb564aae2014-10-23 10:18:09 -07007203 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007204 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007205 UiccPort port = phone == null ? null : phone.getUiccPort();
7206 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007207 return null;
7208 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007209 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007210 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007211 return null;
7212 }
7213 return iccId;
7214 }
7215
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007216 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007217 public void setCallComposerStatus(int subId, int status) {
7218 enforceModifyPermission();
7219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 Phone phone = getPhone(subId);
7223 if (phone != null) {
7224 Phone defaultPhone = phone.getImsPhone();
7225 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7226 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7227 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007228 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7229 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007230 }
7231 }
Shuo Qian284ae752020-12-22 19:10:14 -08007232 } catch (ImsException e) {
7233 throw new ServiceSpecificException(e.getCode());
7234 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007235 Binder.restoreCallingIdentity(identity);
7236 }
7237 }
7238
7239 @Override
7240 public int getCallComposerStatus(int subId) {
7241 enforceReadPrivilegedPermission("getCallComposerStatus");
7242
7243 final long identity = Binder.clearCallingIdentity();
7244 try {
7245 Phone phone = getPhone(subId);
7246 if (phone != null) {
7247 Phone defaultPhone = phone.getImsPhone();
7248 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7249 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7250 return imsPhone.getCallComposerStatus();
7251 }
7252 }
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
7256 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7257 }
7258
7259 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007260 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7261 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007262 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007263 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 final String iccId = getIccId(subId);
7268 final Phone phone = getPhone(subId);
7269 if (phone == null) {
7270 return false;
7271 }
7272 final String subscriberId = phone.getSubscriberId();
7273
7274 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007275 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276 + subscriberId + " to " + number);
7277 }
7278
7279 if (TextUtils.isEmpty(iccId)) {
7280 return false;
7281 }
7282
7283 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7284
7285 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7286 if (alphaTag == null) {
7287 editor.remove(alphaTagPrefKey);
7288 } else {
7289 editor.putString(alphaTagPrefKey, alphaTag);
7290 }
7291
7292 // Record both the line number and IMSI for this ICCID, since we need to
7293 // track all merged IMSIs based on line number
7294 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7295 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7296 if (number == null) {
7297 editor.remove(numberPrefKey);
7298 editor.remove(subscriberPrefKey);
7299 } else {
7300 editor.putString(numberPrefKey, number);
7301 editor.putString(subscriberPrefKey, subscriberId);
7302 }
7303
7304 editor.commit();
7305 return true;
7306 } finally {
7307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007308 }
Derek Tan7226c842014-07-02 17:42:23 -07007309 }
7310
7311 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007312 public String getLine1NumberForDisplay(int subId, String callingPackage,
7313 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007314 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007316 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007317 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007318 return null;
7319 }
Derek Tan97ebb422014-09-05 16:55:38 -07007320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 final long identity = Binder.clearCallingIdentity();
7322 try {
7323 String iccId = getIccId(subId);
7324 if (iccId != null) {
7325 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7326 if (DBG_MERGE) {
7327 log("getLine1NumberForDisplay returning "
7328 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7329 }
7330 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7333 return null;
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007336 }
Derek Tan7226c842014-07-02 17:42:23 -07007337 }
7338
7339 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007340 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7341 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007344 return null;
7345 }
Derek Tan97ebb422014-09-05 16:55:38 -07007346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 String iccId = getIccId(subId);
7350 if (iccId != null) {
7351 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7352 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7353 }
7354 return null;
7355 } finally {
7356 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007357 }
Derek Tan7226c842014-07-02 17:42:23 -07007358 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007359
7360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007361 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7362 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007363 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7364 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007366 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007367 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007368 return null;
7369 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007370
Jordan Liub49b04b2019-05-06 14:45:15 -07007371 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7372 // the process, where TelephonyManager was instantiated.
7373 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007374 final long identity = Binder.clearCallingIdentity();
7375 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007376 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final TelephonyManager tele = TelephonyManager.from(context);
7378 final SubscriptionManager sub = SubscriptionManager.from(context);
7379
7380 // Figure out what subscribers are currently active
7381 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382
Jordan Liub49b04b2019-05-06 14:45:15 -07007383 // Only consider subs which match the current subId
7384 // This logic can be simplified. See b/131189269 for progress.
7385 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007386 activeSubscriberIds.add(tele.getSubscriberId(subId));
7387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388
7389 // First pass, find a number override for an active subscriber
7390 String mergeNumber = null;
7391 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7392 for (String key : prefs.keySet()) {
7393 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7394 final String subscriberId = (String) prefs.get(key);
7395 if (activeSubscriberIds.contains(subscriberId)) {
7396 final String iccId = key.substring(
7397 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7398 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7399 mergeNumber = (String) prefs.get(numberKey);
7400 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007401 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 + " for active subscriber " + subscriberId);
7403 }
7404 if (!TextUtils.isEmpty(mergeNumber)) {
7405 break;
7406 }
7407 }
7408 }
7409 }
7410
7411 // Shortcut when no active merged subscribers
7412 if (TextUtils.isEmpty(mergeNumber)) {
7413 return null;
7414 }
7415
7416 // Second pass, find all subscribers under that line override
7417 final ArraySet<String> result = new ArraySet<>();
7418 for (String key : prefs.keySet()) {
7419 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7420 final String number = (String) prefs.get(key);
7421 if (mergeNumber.equals(number)) {
7422 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7423 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7424 final String subscriberId = (String) prefs.get(subscriberKey);
7425 if (!TextUtils.isEmpty(subscriberId)) {
7426 result.add(subscriberId);
7427 }
7428 }
7429 }
7430 }
7431
7432 final String[] resultArray = result.toArray(new String[result.size()]);
7433 Arrays.sort(resultArray);
7434 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007435 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7437 }
7438 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007439 } finally {
7440 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007441 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007442 }
7443
7444 @Override
zoey chen38003472019-12-13 17:16:31 +08007445 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7446 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007447
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
7450 final TelephonyManager telephonyManager = mApp.getSystemService(
7451 TelephonyManager.class);
7452 String subscriberId = telephonyManager.getSubscriberId(subId);
7453 if (subscriberId == null) {
7454 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007455 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007456 + subId);
7457 }
7458 return null;
7459 }
7460
Jack Yu3beaf9d2023-04-14 09:17:27 -07007461 final SubscriptionInfo info = getSubscriptionManagerService()
7462 .getSubscriptionInfo(subId);
7463 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007464 // If it doesn't belong to any group, return just subscriberId of itself.
7465 if (groupUuid == null) {
7466 return new String[]{subscriberId};
7467 }
7468
7469 // Get all subscriberIds from the group.
7470 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007471 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7472 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7473 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007474 for (SubscriptionInfo subInfo : groupInfos) {
7475 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7476 if (subscriberId != null) {
7477 mergedSubscriberIds.add(subscriberId);
7478 }
7479 }
7480
7481 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7482 } finally {
7483 Binder.restoreCallingIdentity(identity);
7484
7485 }
7486 }
7487
7488 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007489 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007490 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007491 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492
7493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 final Phone phone = getPhone(subId);
7496 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007500 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007501
7502 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007503 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007504 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7505 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007506 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7507 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508
7509 final long identity = Binder.clearCallingIdentity();
7510 try {
7511 final Phone phone = getPhone(subId);
7512 if (phone == null) {
7513 return false;
7514 }
7515 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7516 cdmaNonRoamingList);
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007519 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007520 }
7521
7522 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007523 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007524 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007525 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007526 if (phone == null) {
7527 return raf;
7528 }
7529
Shuo Qiandee53402020-05-29 14:08:15 -07007530 try {
7531 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007532 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007533 mApp, phone.getSubId(), "getRadioAccessFamily");
7534 } catch (SecurityException e) {
7535 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7536 throw e;
7537 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
chen xub97461a2018-10-26 14:17:57 -07007541 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
chen xub97461a2018-10-26 14:17:57 -07007545 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007546 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007547
7548 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007549 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007550 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007551 try {
7552 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7553 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007554 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007555 }
7556 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007557 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007558 }
7559 RoleManager rm = mApp.getSystemService(RoleManager.class);
7560 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7561 if (!dialerRoleHolders.contains(callingPackage)) {
7562 throw new SecurityException("App must be the dialer role holder to"
7563 + " upload a call composer pic");
7564 }
7565
7566 Executors.newSingleThreadExecutor().execute(() -> {
7567 ByteArrayOutputStream output = new ByteArrayOutputStream(
7568 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7569 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7570 boolean readUntilEnd = false;
7571 int totalBytesRead = 0;
7572 byte[] buffer = new byte[16 * 1024];
7573 while (true) {
7574 int numRead;
7575 try {
7576 numRead = input.read(buffer);
7577 } catch (IOException e) {
7578 try {
7579 fd.checkError();
7580 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7581 null);
7582 } catch (IOException e1) {
7583 // This means that the other side closed explicitly with an error. If this
7584 // happens, log and ignore.
7585 loge("Remote end of call composer picture pipe closed: " + e1);
7586 }
7587 break;
7588 }
7589 if (numRead == -1) {
7590 readUntilEnd = true;
7591 break;
7592 }
7593 totalBytesRead += numRead;
7594 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7595 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7596 try {
7597 input.close();
7598 } catch (IOException e) {
7599 // ignore
7600 }
7601 break;
7602 }
7603 output.write(buffer, 0, numRead);
7604 }
7605 // Generally, the remote end will close the file descriptors. The only case where we
7606 // close is above, where the picture size is too big.
7607
7608 try {
7609 fd.checkError();
7610 } catch (IOException e) {
7611 loge("Remote end for call composer closed with an error: " + e);
7612 return;
7613 }
7614
Hall Liuaa4211e2021-01-20 15:43:39 -08007615 if (!readUntilEnd) {
7616 loge("Did not finish reading entire image; aborting");
7617 return;
7618 }
Hall Liu82694d52020-12-11 18:22:04 -08007619
Hall Liuaa4211e2021-01-20 15:43:39 -08007620 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7621 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7622 new CallComposerPictureTransfer.Factory() {},
7623 imageData,
7624 (result) -> {
7625 if (result.first != null) {
7626 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7627 Bundle outputResult = new Bundle();
7628 outputResult.putParcelable(
7629 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7630 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7631 outputResult);
7632 } else {
7633 callback.send(result.second, null);
7634 }
7635 }
7636 );
Hall Liu82694d52020-12-11 18:22:04 -08007637 });
7638 }
7639
7640 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007641 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007642 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644
7645 final long identity = Binder.clearCallingIdentity();
7646 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007647 ImsManager.getInstance(defaultPhone.getContext(),
7648 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007652 }
7653
7654 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007655 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007656 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7658 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007659 return false;
7660 }
Svet Ganovb320e182015-04-16 12:30:10 -07007661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 // Check the user preference and the system-level IMS setting. Even if the user has
7665 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7666 // In the long run, we may instead need to check if there exists a connection service
7667 // which can support video calling.
7668 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007669 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670 return imsManager.isVtEnabledByPlatform()
7671 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7672 && imsManager.isVtEnabledByUser();
7673 } finally {
7674 Binder.restoreCallingIdentity(identity);
7675 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007676 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007677
Andrew Leea1239f22015-03-02 17:44:07 -08007678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007679 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7680 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007682 mApp, subId, callingPackage, callingFeatureId,
7683 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 return false;
7685 }
7686
7687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 CarrierConfigManager configManager =
7690 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007691 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7693 } finally {
7694 Binder.restoreCallingIdentity(identity);
7695 }
Andrew Leea1239f22015-03-02 17:44:07 -08007696 }
7697
7698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007699 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007701 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 return false;
7703 }
7704
7705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 CarrierConfigManager configManager =
7708 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007709 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
7713 }
Andrew Leea1239f22015-03-02 17:44:07 -08007714 }
7715
Andrew Lee9431b832015-03-09 18:46:45 -07007716 @Override
7717 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007718 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007719 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007720 }
7721
7722 @Override
7723 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
Andrew Lee9431b832015-03-09 18:46:45 -07007730 }
7731
Hall Liuf6668912018-10-31 17:05:23 -07007732 /**
7733 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7734 * support for the feature and device firmware support.
7735 *
7736 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7737 */
7738 @Override
7739 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 final Phone phone = getPhone(subscriptionId);
7742 if (phone == null) {
7743 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7744 return false;
7745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007747 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7749 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007750 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 return isCarrierSupported && isDeviceSupported;
7752 } finally {
7753 Binder.restoreCallingIdentity(identity);
7754 }
Hall Liu98187582018-01-22 19:15:32 -08007755 }
7756
Hall Liuf6668912018-10-31 17:05:23 -07007757 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007758 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7759 * RTT setting, will return true if the device and carrier both support RTT.
7760 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007761 */
7762 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 final long identity = Binder.clearCallingIdentity();
7764 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007765 boolean isRttSupported = isRttSupported(subscriptionId);
7766 boolean isUserRttSettingOn = Settings.Secure.getInt(
7767 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7768 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7769 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7770 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771 } finally {
7772 Binder.restoreCallingIdentity(identity);
7773 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007774 }
7775
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007776 @Deprecated
7777 @Override
7778 public String getDeviceId(String callingPackage) {
7779 return getDeviceIdWithFeature(callingPackage, null);
7780 }
7781
Sanket Padawe7310cc72015-01-14 09:53:20 -08007782 /**
7783 * Returns the unique device ID of phone, for example, the IMEI for
7784 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7785 *
7786 * <p>Requires Permission:
7787 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7788 */
7789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007790 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007791 try {
7792 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7793 } catch (SecurityException se) {
7794 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7795 throw new SecurityException("Package " + callingPackage + " does not belong to "
7796 + Binder.getCallingUid());
7797 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007798 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007799 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007800 return null;
7801 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007802 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007803 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007804 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007805 return null;
7806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807
7808 final long identity = Binder.clearCallingIdentity();
7809 try {
7810 return phone.getDeviceId();
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
7813 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007814 }
7815
Ping Sunc67b7c22016-03-02 19:16:45 +08007816 /**
7817 * {@hide}
7818 * Returns the IMS Registration Status on a particular subid
7819 *
7820 * @param subId
7821 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007822 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007823 Phone phone = getPhone(subId);
7824 if (phone != null) {
7825 return phone.isImsRegistered();
7826 } else {
7827 return false;
7828 }
7829 }
7830
Santos Cordon7a1885b2015-02-03 11:15:19 -08007831 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007832 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007833 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007835 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007836 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7837 }
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 }
7845
7846 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007847 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007848 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007849 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007850 mApp,
7851 subscriptionId,
7852 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7853 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 Phone phone = getPhone(subscriptionId);
7857 if (phone == null) {
7858 return null;
7859 }
7860 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
7864 }
7865
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007866 /**
7867 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007868 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007869 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 Phone phone = getPhone(subId);
7873 if (phone != null) {
7874 return phone.isWifiCallingEnabled();
7875 } else {
7876 return false;
7877 }
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007880 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007881 }
7882
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007883 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007884 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007885 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007886 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 Phone phone = getPhone(subId);
7890 if (phone != null) {
7891 return phone.isVideoEnabled();
7892 } else {
7893 return false;
7894 }
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007897 }
7898 }
7899
7900 /**
7901 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7902 * defined in {@link ImsRegistrationImplBase}.
7903 */
7904 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 Phone phone = getPhone(subId);
7908 if (phone != null) {
7909 return phone.getImsRegistrationTech();
7910 } else {
7911 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7912 }
7913 } finally {
7914 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007915 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007916 }
7917
Stuart Scott8eef64f2015-04-08 15:13:54 -07007918 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007919 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007920 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007921 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7922 return;
7923 }
Kai Shif70f46f2021-03-03 13:59:46 -08007924 Phone defaultPhone = getDefaultPhone();
7925 if (defaultPhone != null) {
7926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7927 mApp, getDefaultPhone().getSubId(), "factoryReset");
7928 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007929 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930
Svet Ganovcc087f82015-05-12 20:35:54 -07007931 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007932 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7933 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007934 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007935 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007936 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007937 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007938 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007939 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007940 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007941 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007942 // There has been issues when Sms raw table somehow stores orphan
7943 // fragments. They lead to garbled message when new fragments come
7944 // in and combined with those stale ones. In case this happens again,
7945 // user can reset all network settings which will clean up this table.
7946 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007947 // Clean up IMS settings as well here.
7948 int slotId = getSlotIndex(subId);
7949 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7950 ImsManager.getInstance(mApp, slotId).factoryReset();
7951 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007952
Kai Shif70f46f2021-03-03 13:59:46 -08007953 if (defaultPhone == null) {
7954 return;
7955 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007956 // Erase modem config if erase modem on network setting is enabled.
7957 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7958 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7959 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007960 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007961 }
Kai Shif70f46f2021-03-03 13:59:46 -08007962
7963 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007964 } finally {
7965 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007966 }
7967 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007968
SongFerngWangfd89b102021-05-27 22:44:54 +08007969 @VisibleForTesting
7970 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7971 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7972 return;
7973 }
7974 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7975 RILConstants.PREFERRED_NETWORK_MODE);
7976 SubscriptionManager.setSubscriptionProperty(subId,
7977 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7978 "user=" + defaultNetworkType);
7979 phone.loadAllowedNetworksFromSubscriptionDatabase();
7980 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7981 defaultNetworkType, null);
7982 }
7983
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007984 private void cleanUpSmsRawTable(Context context) {
7985 ContentResolver resolver = context.getContentResolver();
7986 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7987 resolver.delete(uri, null, null);
7988 }
7989
Narayan Kamath1c496c22015-04-16 14:40:19 +01007990 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007991 public String getSimLocaleForSubscriber(int subId) {
7992 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7993 final Phone phone = getPhone(subId);
7994 if (phone == null) {
7995 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007996 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 final long identity = Binder.clearCallingIdentity();
7999 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008000 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8001 phone.getContext().getOpPackageName(),
8002 phone.getContext().getAttributionTag());
8003 if (info == null) {
8004 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8005 return null;
chen xu6291c472019-02-04 12:55:53 -08008006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007 // Try and fetch the locale from the carrier properties or from the SIM language
8008 // preferences (EF-PL and EF-LI)...
8009 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008011 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8012 if (localeFromDefaultSim != null) {
8013 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8014 if (DBG) log("Using locale from subId: " + subId + " locale: "
8015 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008016 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008017 } else {
8018 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 }
8020 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 // The SIM language preferences only store a language (e.g. fr = French), not an
8023 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8024 // the SIM and carrier preferences does not include a country we add the country
8025 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008026 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008028 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008029 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 }
8031
8032 if (DBG) log("No locale found - returning null");
8033 return null;
8034 } finally {
8035 Binder.restoreCallingIdentity(identity);
8036 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008037 }
8038
tom hsu0b59d292022-09-29 23:49:21 +08008039 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008040 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008041 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008042 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008043 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008044 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8045 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008046 Locale.forLanguageTag(localeTag).getCountry())) {
8047 return localeTag;
8048 }
8049 }
8050 return inputLocale.toLanguageTag();
8051 }
8052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 /**
8054 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8055 */
8056 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008057 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008058 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008059 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008060
Gary Jian3aa9a762022-01-24 16:41:19 +08008061 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8062 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008063
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008064 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008065 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8066 * representing the state of the modem.
8067 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008068 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8069 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008070 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008071 */
8072 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008073 public void requestModemActivityInfo(ResultReceiver result) {
8074 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008075 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076
8077 final long identity = Binder.clearCallingIdentity();
8078 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008079 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 } finally {
8081 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008082 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008083 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008084
Gary Jian76280a42022-12-07 16:18:33 +08008085 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008086 // less than total activity duration.
8087 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8088 if (info == null) {
8089 return false;
8090 }
8091 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008092 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008093 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8094
Hall Liu49656c02020-10-09 19:00:11 -07008095 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8096
Siddharth Rayb8114062018-06-17 15:02:38 -07008097 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008098 && (info.getSleepTimeMillis() <= activityDurationMs)
8099 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008100 }
8101
Gary Jian3aa9a762022-01-24 16:41:19 +08008102 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8103 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8104 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8105 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8106
8107 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8108 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8109 }
8110
8111 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8112 mLastModemActivityInfo.setReceiveTimeMillis(
8113 rat,
8114 freq,
8115 info.getReceiveTimeMillis(rat, freq)
8116 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8117 }
8118
8119 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8120 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8121 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8122 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8123
8124 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8125 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8126 }
8127 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8128 mLastModemActivityInfo.setReceiveTimeMillis(
8129 rat,
8130 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8131 }
8132
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008133 /**
8134 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8135 * @param info recent ModemActivityInfo
8136 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008137 private void mergeModemActivityInfo(ModemActivityInfo info) {
8138 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008139 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008140 boolean matched;
8141 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8142 matched = false;
8143 int rat = info.getSpecificInfoRat(i);
8144 int freq = info.getSpecificInfoFrequencyRange(i);
8145 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8146 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8147 //if it already exists
8148 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8149 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8150 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8151 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8152 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8153 updateLastModemActivityInfo(info, rat, freq);
8154 matched = true;
8155 }
8156 } else {
8157 updateLastModemActivityInfo(info, rat);
8158 matched = true;
8159 }
8160 }
8161 }
8162
8163 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008164 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008165 new ActivityStatsTechSpecificInfo(
8166 rat,
8167 freq,
8168 info.getTransmitTimeMillis(rat, freq),
8169 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008170 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008171 }
8172 }
8173 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8174 mLastModemActivitySpecificInfo =
8175 new ActivityStatsTechSpecificInfo[merged.size()];
8176 merged.toArray(mLastModemActivitySpecificInfo);
8177
8178 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8179 mLastModemActivityInfo.setSleepTimeMillis(
8180 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008181 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008182 mLastModemActivityInfo.setIdleTimeMillis(
8183 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008184 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008185
8186 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008187 new ModemActivityInfo(
8188 mLastModemActivityInfo.getTimestampMillis(),
8189 mLastModemActivityInfo.getSleepTimeMillis(),
8190 mLastModemActivityInfo.getIdleTimeMillis(),
8191 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008192 }
8193
8194 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8195 ActivityStatsTechSpecificInfo[] info) {
8196 int infoSize = info.length;
8197 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8198 for (int i = 0; i < infoSize; i++) {
8199 ret[i] = new ActivityStatsTechSpecificInfo(
8200 info[i].getRat(), info[i].getFrequencyRange(),
8201 info[i].getTransmitTimeMillis(),
8202 (int) info[i].getReceiveTimeMillis());
8203 }
8204 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008205 }
8206
Jack Yu85bd38a2015-11-09 11:34:32 -08008207 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008208 * Returns the service state information on specified subscription.
8209 */
8210 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008211 public ServiceState getServiceStateForSubscriber(int subId,
8212 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8213 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008215 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008216 return null;
8217 }
8218
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008219 boolean hasFinePermission = false;
8220 boolean hasCoarsePermission = false;
8221 if (!renounceFineLocationAccess) {
8222 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8223 LocationAccessPolicy.checkLocationPermission(mApp,
8224 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8225 .setCallingPackage(callingPackage)
8226 .setCallingFeatureId(callingFeatureId)
8227 .setCallingPid(Binder.getCallingPid())
8228 .setCallingUid(Binder.getCallingUid())
8229 .setMethod("getServiceStateForSubscriber")
8230 .setLogAsInfo(true)
8231 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8232 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8233 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8234 .build());
8235 hasFinePermission =
8236 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8237 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008238
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008239 if (!renounceCoarseLocationAccess) {
8240 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8241 LocationAccessPolicy.checkLocationPermission(mApp,
8242 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8243 .setCallingPackage(callingPackage)
8244 .setCallingFeatureId(callingFeatureId)
8245 .setCallingPid(Binder.getCallingPid())
8246 .setCallingUid(Binder.getCallingUid())
8247 .setMethod("getServiceStateForSubscriber")
8248 .setLogAsInfo(true)
8249 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8250 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8251 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8252 .build());
8253 hasCoarsePermission =
8254 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8255 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008256
Jack Yu479f40e2020-10-27 21:29:25 -07008257 final Phone phone = getPhone(subId);
8258 if (phone == null) {
8259 return null;
8260 }
8261
Jordan Liu0f2bc442020-11-18 16:47:37 -08008262 final long identity = Binder.clearCallingIdentity();
8263
Jack Yu479f40e2020-10-27 21:29:25 -07008264 boolean isCallingPackageDataService = phone.getDataServicePackages()
8265 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008267 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008268 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8269 .getSubscriptionInfoInternal(subId);
8270 if (subInfo == null || !subInfo.isActive()) {
8271 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8272 + "subId=" + subId);
8273 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008274 }
8275
Hall Liuf19c44f2018-11-27 14:38:17 -08008276 ServiceState ss = phone.getServiceState();
8277
8278 // Scrub out the location info in ServiceState depending on what level of access
8279 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008280 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008281 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8282 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008286 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008287
8288 /**
8289 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8290 *
8291 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8292 * voicemail ringtone.
8293 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8294 * PhoneAccount.
8295 */
8296 @Override
8297 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8301 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008302 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008309 }
8310
8311 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008312 * Sets the per-account voicemail ringtone.
8313 *
8314 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8315 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8316 *
8317 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8318 * voicemail ringtone.
8319 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8320 * PhoneAccount.
8321 */
8322 @Override
8323 public void setVoicemailRingtoneUri(String callingPackage,
8324 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008325 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008327 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8328 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8330 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8331 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8337 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 }
8340 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008343 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008344 }
8345
8346 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008347 * Returns whether vibration is set for voicemail notification in Phone settings.
8348 *
8349 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8350 * voicemail vibration setting.
8351 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8352 */
8353 @Override
8354 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 final long identity = Binder.clearCallingIdentity();
8356 try {
8357 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8358 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008359 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008366 }
8367
Youhan Wange64578a2016-05-02 15:32:42 -07008368 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008369 * Sets the per-account voicemail vibration.
8370 *
8371 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8372 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8373 *
8374 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8375 * voicemail vibration setting.
8376 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8377 * specific PhoneAccount.
8378 */
8379 @Override
8380 public void setVoicemailVibrationEnabled(String callingPackage,
8381 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008382 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008384 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8385 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8387 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8388 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008389 }
8390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8394 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008395 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 }
8397 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008400 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008401 }
8402
8403 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008404 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8405 *
8406 * @throws SecurityException if the caller does not have the required permission
8407 */
arunvoddud7401012022-12-15 16:08:12 +00008408 @VisibleForTesting
8409 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008410 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008411 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008412 }
8413
8414 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008415 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8416 * permission.
8417 *
8418 * @throws SecurityException if the caller does not have the required permission
8419 */
8420 private void enforceSendSmsPermission() {
8421 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8422 }
8423
8424 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008425 * Make sure either called from same process as self (phone) or IPC caller has interact across
8426 * users permission.
8427 *
8428 * @throws SecurityException if the caller does not have the required permission
8429 */
8430 private void enforceInteractAcrossUsersPermission(String message) {
8431 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8432 }
8433
8434 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008435 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008436 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008437 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008438 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008439 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440 final long identity = Binder.clearCallingIdentity();
8441 try {
8442 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008443 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444 if (componentName == null) {
8445 throw new SecurityException(
8446 "Caller not current active visual voicemail package[null]");
8447 }
8448 String vvmPackage = componentName.getPackageName();
8449 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008450 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451 }
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008454 }
8455 }
8456
8457 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008458 * Return the application ID for the app type.
8459 *
8460 * @param subId the subscription ID that this request applies to.
8461 * @param appType the uicc app type.
8462 * @return Application ID for specificied app type, or null if no uicc.
8463 */
8464 @Override
8465 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008466 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008467 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468
8469 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008470 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 if (phone == null) {
8472 return null;
8473 }
8474 String aid = null;
8475 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008476 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008477 .getApplicationByType(appType).getAid();
8478 } catch (Exception e) {
8479 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8480 }
8481 return aid;
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008484 }
Youhan Wange64578a2016-05-02 15:32:42 -07008485 }
8486
Youhan Wang4001d252016-05-11 10:29:41 -07008487 /**
8488 * Return the Electronic Serial Number.
8489 *
8490 * @param subId the subscription ID that this request applies to.
8491 * @return ESN or null if error.
8492 */
8493 @Override
8494 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008495 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008496 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008497
8498 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008499 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008500 if (phone == null) {
8501 return null;
8502 }
8503 String esn = null;
8504 try {
8505 esn = phone.getEsn();
8506 } catch (Exception e) {
8507 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8508 }
8509 return esn;
8510 } finally {
8511 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008512 }
Youhan Wang4001d252016-05-11 10:29:41 -07008513 }
8514
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008515 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008516 * Return the Preferred Roaming List Version.
8517 *
8518 * @param subId the subscription ID that this request applies to.
8519 * @return PRLVersion or null if error.
8520 */
8521 @Override
8522 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008523 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008524 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525
8526 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008527 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528 if (phone == null) {
8529 return null;
8530 }
8531 String cdmaPrlVersion = null;
8532 try {
8533 cdmaPrlVersion = phone.getCdmaPrlVersion();
8534 } catch (Exception e) {
8535 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8536 }
8537 return cdmaPrlVersion;
8538 } finally {
8539 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008540 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008541 }
8542
8543 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008544 * Get snapshot of Telephony histograms
8545 * @return List of Telephony histograms
8546 * @hide
8547 */
8548 @Override
8549 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8551 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008552
8553 final long identity = Binder.clearCallingIdentity();
8554 try {
8555 return RIL.getTelephonyRILTimingHistograms();
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008559 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008560
8561 /**
8562 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008563 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8564 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008565 * Require system privileges. In the future we may add this to carrier APIs.
8566 *
Michele Berionne482f8202018-11-27 18:57:59 -08008567 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008568 */
8569 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008570 @TelephonyManager.SetCarrierRestrictionResult
8571 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008572 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008573 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008574
Michele Berionne482f8202018-11-27 18:57:59 -08008575 if (carrierRestrictionRules == null) {
8576 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008577 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 final long identity = Binder.clearCallingIdentity();
8580 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008581 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008582 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583 } finally {
8584 Binder.restoreCallingIdentity(identity);
8585 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008586 }
8587
8588 /**
8589 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008590 * Get the allowed carrier list and the excluded carrier list, including the priority between
8591 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008592 * Require system privileges. In the future we may add this to carrier APIs.
8593 *
Michele Berionne482f8202018-11-27 18:57:59 -08008594 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008595 */
8596 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008597 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008598 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600
8601 final long identity = Binder.clearCallingIdentity();
8602 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008603 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8604 if (response instanceof CarrierRestrictionRules) {
8605 return (CarrierRestrictionRules) response;
8606 }
8607 // Response is an Exception of some kind,
8608 // which is signalled to the user as a NULL retval
8609 return null;
8610 } catch (Exception e) {
8611 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8612 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008616 }
8617
fionaxu59545b42016-05-25 15:53:37 -07008618 /**
arunvoddud7401012022-12-15 16:08:12 +00008619 * Fetches the carrier restriction status of the device and sends the status to the caller
8620 * through the callback.
8621 *
8622 * @param callback The callback that will be used to send the result.
8623 * @throws SecurityException if the caller does not have the required permission/privileges or
8624 * the caller is not allowlisted.
8625 */
8626 @Override
8627 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8628 enforceReadPermission("getCarrierRestrictionStatus");
8629 int carrierId = validateCallerAndGetCarrierId(packageName);
8630 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8631 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8632 throw new SecurityException("Not an authorized caller");
8633 }
8634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8637 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8638 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
8642 }
8643
arunvoddu567f2b42023-04-25 17:22:00 +00008644 @Override
8645 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8646 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8647 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8648 return allowListInfo.getShaIdList(pkgName, carrierId);
8649 }
8650
arunvoddud7401012022-12-15 16:08:12 +00008651 @VisibleForTesting
8652 public int validateCallerAndGetCarrierId(String packageName) {
8653 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8654 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8655 }
8656
8657 /**
fionaxu59545b42016-05-25 15:53:37 -07008658 * Action set from carrier signalling broadcast receivers to enable/disable radio
8659 * @param subId the subscription ID that this action applies to.
8660 * @param enabled control enable or disable radio.
8661 * {@hide}
8662 */
8663 @Override
8664 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8665 enforceModifyPermission();
8666 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667
8668 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008669 if (phone == null) {
8670 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8671 return;
8672 }
8673 try {
8674 phone.carrierActionSetRadioEnabled(enabled);
8675 } catch (Exception e) {
8676 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008677 } finally {
8678 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008679 }
8680 }
8681
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008682 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008683 * Enable or disable Voice over NR (VoNR)
8684 * @param subId the subscription ID that this action applies to.
8685 * @param enabled enable or disable VoNR.
8686 * @return operation result.
8687 */
8688 @Override
8689 public int setVoNrEnabled(int subId, boolean enabled) {
8690 enforceModifyPermission();
8691 final Phone phone = getPhone(subId);
8692
8693 final long identity = Binder.clearCallingIdentity();
8694 if (phone == null) {
8695 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8696 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8697 }
8698
8699 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8700 try {
8701 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8702 workSource);
8703 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008704
8705 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8706 if (DBG) {
8707 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8708 }
8709 SubscriptionManager.setSubscriptionProperty(
8710 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8711 (enabled ? "1" : "0"));
8712 }
8713
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008714 return result;
8715 } finally {
8716 Binder.restoreCallingIdentity(identity);
8717 }
8718 }
8719
8720 /**
8721 * Is voice over NR enabled
8722 * @return true if VoNR is enabled else false
8723 */
8724 @Override
8725 public boolean isVoNrEnabled(int subId) {
8726 enforceReadPrivilegedPermission("isVoNrEnabled");
8727 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8728 final long identity = Binder.clearCallingIdentity();
8729 try {
8730 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8731 null, subId, workSource);
8732 if (DBG) log("isVoNrEnabled: " + isEnabled);
8733 return isEnabled;
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
8736 }
8737 }
8738
8739 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008740 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8741 * network status based on which carrier apps could apply actions accordingly,
8742 * enable/disable default url handler for example.
8743 *
8744 * @param subId the subscription ID that this action applies to.
8745 * @param report control start/stop reporting the default network status.
8746 * {@hide}
8747 */
8748 @Override
8749 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8750 enforceModifyPermission();
8751 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008752
8753 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008754 if (phone == null) {
8755 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8756 return;
8757 }
8758 try {
8759 phone.carrierActionReportDefaultNetworkStatus(report);
8760 } catch (Exception e) {
8761 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008762 } finally {
8763 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008764 }
8765 }
8766
8767 /**
fionaxud9622282017-07-17 17:51:30 -07008768 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8769 * @param subId the subscription ID that this action applies to.
8770 * {@hide}
8771 */
8772 @Override
8773 public void carrierActionResetAll(int subId) {
8774 enforceModifyPermission();
8775 final Phone phone = getPhone(subId);
8776 if (phone == null) {
8777 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8778 return;
8779 }
8780 try {
8781 phone.carrierActionResetAll();
8782 } catch (Exception e) {
8783 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8784 }
8785 }
8786
8787 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008788 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8789 * bug report is being generated.
8790 */
8791 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008792 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008793 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8794 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008795 writer.println("Permission Denial: can't dump Phone from pid="
8796 + Binder.getCallingPid()
8797 + ", uid=" + Binder.getCallingUid()
8798 + "without permission "
8799 + android.Manifest.permission.DUMP);
8800 return;
8801 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008802 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008803 }
Jack Yueb89b242016-06-22 13:27:47 -07008804
Brad Ebingerdac2f002018-04-03 15:17:52 -07008805 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008806 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8807 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8808 @NonNull String[] args) {
8809 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8810 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008811 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008812 }
8813
Jack Yueb89b242016-06-22 13:27:47 -07008814 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008815 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008816 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008817 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008818 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008819 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008820 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008821 */
8822 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008823 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008824 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008825 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8826 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8827 try {
8828 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008829 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008830 } catch (SecurityException se) {
8831 enforceModifyPermission();
8832 }
8833 } else {
8834 enforceModifyPermission();
8835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008836
Nate Myrenae97d192023-06-09 15:22:31 -07008837 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
8838 && null != callingPackage && opEnableMobileDataByUser()) {
8839 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
8840 callingPackage, null, null);
8841 }
8842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008843 final long identity = Binder.clearCallingIdentity();
8844 try {
8845 Phone phone = getPhone(subId);
8846 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008847 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8848 phone.carrierActionSetMeteredApnsEnabled(enabled);
8849 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008850 phone.getDataSettingsManager().setDataEnabled(
8851 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 }
8854 } finally {
8855 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008856 }
8857 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008858
8859 /**
8860 * Get Client request stats
8861 * @return List of Client Request Stats
8862 * @hide
8863 */
8864 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008865 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8866 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008868 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008869 return null;
8870 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008871 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 if (phone != null) {
8876 return phone.getClientRequestStats();
8877 }
8878
8879 return null;
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
8882 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008883 }
8884
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008885 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008886 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008887 if (uid == Process.ROOT_UID && packageName == null) {
8888 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8889 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8890 // exception. ROOT_UID seems not to have a valid package name returned by
8891 // PackageManager, so just fake it here to avoid issues when running telephony shell
8892 // commands that plumb through the RIL as root, like so:
8893 // $ adb root
8894 // $ adb shell cmd phone ...
8895 packageName = "root";
8896 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008897 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008898 }
Jack Yueb4124c2017-02-16 15:32:43 -08008899
8900 /**
Grace Chen70990072017-03-24 17:21:30 -07008901 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008902 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008903 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008904 * @param state State of SIM (power down, power up, pass through)
8905 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8906 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8907 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008908 *
8909 **/
8910 @Override
Grace Chen70990072017-03-24 17:21:30 -07008911 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008912 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008913 Phone phone = PhoneFactory.getPhone(slotIndex);
8914
vagdeviaf9a5b92018-08-15 16:01:53 -07008915 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008917 final long identity = Binder.clearCallingIdentity();
8918 try {
8919 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008920 phone.setSimPowerState(state, null, workSource);
8921 }
8922 } finally {
8923 Binder.restoreCallingIdentity(identity);
8924 }
8925 }
8926
8927 /**
8928 * Set SIM card power state.
8929 *
8930 * @param slotIndex SIM slot id.
8931 * @param state State of SIM (power down, power up, pass through)
8932 * @param callback callback to trigger after success or failure
8933 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8934 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8935 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8936 *
8937 **/
8938 @Override
8939 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8940 IIntegerConsumer callback) {
8941 enforceModifyPermission();
8942 Phone phone = PhoneFactory.getPhone(slotIndex);
8943
8944 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8945
8946 final long identity = Binder.clearCallingIdentity();
8947 try {
8948 if (phone != null) {
8949 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8950 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 }
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008954 }
8955 }
Shuo Qiandd210312017-04-12 22:11:33 +00008956
Tyler Gunn65d45c22017-06-05 11:22:26 -07008957 private boolean isUssdApiAllowed(int subId) {
8958 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008959 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008960 if (configManager == null) {
8961 return false;
8962 }
8963 PersistableBundle pb = configManager.getConfigForSubId(subId);
8964 if (pb == null) {
8965 return false;
8966 }
8967 return pb.getBoolean(
8968 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8969 }
8970
Shuo Qiandd210312017-04-12 22:11:33 +00008971 /**
Ling Mac28f0212023-03-24 16:07:15 -07008972 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008973 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008974 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008975 */
goneil9c5f4872017-12-05 14:07:56 -08008976 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008977 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008978 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 final long identity = Binder.clearCallingIdentity();
8980 try {
Ling Mac28f0212023-03-24 16:07:15 -07008981 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 } finally {
8983 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008984 }
8985 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008986
8987 /**
8988 * Get the current signal strength information for the given subscription.
8989 * Because this information is not updated when the device is in a low power state
8990 * it should not be relied-upon to be current.
8991 * @param subId Subscription index
8992 * @return the most recent cached signal strength info from the modem
8993 */
8994 @Override
8995 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008996 final long identity = Binder.clearCallingIdentity();
8997 try {
8998 Phone p = getPhone(subId);
8999 if (p == null) {
9000 return null;
9001 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009003 return p.getSignalStrength();
9004 } finally {
9005 Binder.restoreCallingIdentity(identity);
9006 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009007 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009008
Pengquan Meng77b7f132018-08-22 14:49:57 -07009009 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009010 * Get the current modem radio state for the given slot.
9011 * @param slotIndex slot index.
9012 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009013 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009014 * @return the current radio power state from the modem
9015 */
9016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009017 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009018 Phone phone = PhoneFactory.getPhone(slotIndex);
9019 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9021 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009022 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9023 }
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 return phone.getRadioPowerState();
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9033 }
9034
9035 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009036 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9037 *
9038 * <p>Requires one of the following permissions:
9039 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009040 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009041 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9042 * privileges.
9043 *
9044 * @param subId subscription id
9045 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9046 * {@code false}.
9047 */
9048 @Override
9049 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009050 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009051 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009052 try {
9053 mApp.enforceCallingOrSelfPermission(
9054 android.Manifest.permission.ACCESS_NETWORK_STATE,
9055 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009056 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009057 mApp.enforceCallingOrSelfPermission(
9058 permission.READ_BASIC_PHONE_STATE, functionName);
9059 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009060 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009061 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009062 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009063 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009064
Pengquan Menga1bb6272018-09-06 09:59:22 -07009065 boolean isEnabled = false;
9066 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009067 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009068 Phone phone = getPhone(subId);
9069 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009070 } finally {
9071 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009072 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009073 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009074 }
9075
9076
9077 /**
9078 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9079 *
9080 * <p> Requires permission:
9081 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9082 * privileges.
9083 *
9084 * @param subId subscription id
9085 * @param isEnabled {@code true} means enable, {@code false} means disable.
9086 */
9087 @Override
9088 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9090 mApp, subId, "setDataRoamingEnabled");
9091
Pengquan Menga1bb6272018-09-06 09:59:22 -07009092 final long identity = Binder.clearCallingIdentity();
9093 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009094 Phone phone = getPhone(subId);
9095 if (phone != null) {
9096 phone.setDataRoamingEnabled(isEnabled);
9097 }
9098 } finally {
9099 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009100 }
9101 }
9102
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009103 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009104 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009105 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009106 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009107 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009108
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009109 boolean isAllowed = true;
9110 final long identity = Binder.clearCallingIdentity();
9111 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009112 Phone phone = getPhone(subId);
9113 if (phone != null) {
9114 isAllowed = phone.isCspPlmnEnabled();
9115 }
9116 } finally {
9117 Binder.restoreCallingIdentity(identity);
9118 }
9119 return isAllowed;
9120 }
9121
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009122 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9123 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009124 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009125 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009126 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009127 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9128 if (phone == null) {
9129 return false;
9130 }
9131 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9132 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9133 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009134 }
9135
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009136 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009137 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009138 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009139 mApp.getSystemService(AppOpsManager.class)
9140 .checkPackage(Binder.getCallingUid(), callingPackage);
9141
Jordan Liu1e142fc2019-04-22 15:10:43 -07009142 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009143 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009144 try {
9145 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009146 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009147 } catch (SecurityException e) {
9148 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9149 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009150 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009151 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009152 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009153 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009154 }
sandeepjsb6c87872021-09-27 15:34:44 +00009155 // checking compatibility, if calling app's target SDK is T and beyond.
9156 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9157 Binder.getCallingUid())) {
9158 isIccIdAccessRestricted = true;
9159 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009160 final long identity = Binder.clearCallingIdentity();
9161 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009162 UiccController uiccController = UiccController.getInstance();
9163 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009164 if (hasReadPermission) {
9165 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009166 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009167
9168 // Remove private info if the caller doesn't have access
9169 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9170 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009171 //setting the value after compatibility check
9172 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009173 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9174 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009175 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009176 if (card == null) {
9177 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009178 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009179 continue;
9180 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009181 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9182 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009183 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009184 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009185 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009186 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9187 for (UiccPortInfo portInfo : portInfos) {
9188 UiccPort port = uiccController.getUiccPortForSlot(
9189 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9190 if (port == null) {
9191 // assume no access if port is null
9192 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9193 continue;
9194 }
9195 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9196 uiccPortInfos.add(portInfo);
9197 } else {
9198 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9199 }
9200 }
9201 filteredInfos.add(new UiccCardInfo(
9202 cardInfo.isEuicc(),
9203 cardInfo.getCardId(),
9204 null,
9205 cardInfo.getPhysicalSlotIndex(),
9206 cardInfo.isRemovable(),
9207 cardInfo.isMultipleEnabledProfilesSupported(),
9208 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009209 }
9210 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
sandeepjsb6c87872021-09-27 15:34:44 +00009216 /**
9217 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9218 * generally private and require carrier privileges to view.
9219 *
9220 * @hide
9221 */
9222 @NonNull
9223 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9224 List<UiccPortInfo> portinfo = new ArrayList<>();
9225 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9226 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9227 }
9228 return new UiccCardInfo(
9229 cardInfo.isEuicc(),
9230 cardInfo.getCardId(),
9231 null,
9232 cardInfo.getPhysicalSlotIndex(),
9233 cardInfo.isRemovable(),
9234 cardInfo.isMultipleEnabledProfilesSupported(),
9235 portinfo
9236 );
9237 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009238
sandeepjsb6c87872021-09-27 15:34:44 +00009239 /**
9240 * @hide
9241 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9242 * These values are generally private and require carrier privileges to view.
9243 */
9244 @NonNull
9245 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9246 return new UiccPortInfo(
9247 UiccPortInfo.ICCID_REDACTED,
9248 portInfo.getPortIndex(),
9249 portInfo.getLogicalSlotIndex(),
9250 portInfo.isActive()
9251 );
9252 }
9253 @Override
9254 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009255 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009256 mApp.getSystemService(AppOpsManager.class)
9257 .checkPackage(Binder.getCallingUid(), callingPackage);
9258
sandeepjsb6c87872021-09-27 15:34:44 +00009259 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009260
Aman Guptaf3c90b32022-03-17 04:54:16 +00009261 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9262 // we are reading iccId which is PII data.
9263 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009264
9265 // checking compatibility, if calling app's target SDK is T and beyond.
9266 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9267 Binder.getCallingUid())) {
9268 isLogicalSlotAccessRestricted = true;
9269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009270 final long identity = Binder.clearCallingIdentity();
9271 try {
9272 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009273 if (slots == null || slots.length == 0) {
9274 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009275 return null;
9276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009277 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9278 for (int i = 0; i < slots.length; i++) {
9279 UiccSlot slot = slots[i];
9280 if (slot == null) {
9281 continue;
9282 }
9283
Jordan Liu7be7e652019-05-06 18:55:02 +00009284 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009285 UiccCard card = slot.getUiccCard();
9286 if (card != null) {
9287 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009288 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009289 cardId = slot.getEid();
9290 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009291 // If cardId is null, use iccId of default port as cardId.
9292 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009294 }
9295
Jordan Liu857451f2019-05-09 16:35:35 -07009296 if (cardId != null) {
9297 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9298 // if cardId is an EID, it's all digits so this is fine
9299 cardId = IccUtils.stripTrailingFs(cardId);
9300 }
9301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009302 int cardState = 0;
9303 switch (slot.getCardState()) {
9304 case CARDSTATE_ABSENT:
9305 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9306 break;
9307 case CARDSTATE_PRESENT:
9308 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9309 break;
9310 case CARDSTATE_ERROR:
9311 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9312 break;
9313 case CARDSTATE_RESTRICTED:
9314 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9315 break;
9316 default:
9317 break;
9318
9319 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009320 List<UiccPortInfo> portInfos = new ArrayList<>();
9321 int[] portIndexes = slot.getPortList();
9322 for (int portIdx : portIndexes) {
9323 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009324 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009325 portInfos.add(new UiccPortInfo(iccId, portIdx,
9326 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009328 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009329 slot.isEuicc(),
9330 cardId,
9331 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009332 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009333 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009334 //setting the value after compatibility check
9335 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009336 }
9337 return infos;
9338 } finally {
9339 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009340 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009341 }
9342
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009343 /* Returns null if doesn't have read permission or carrier privilege access. */
9344 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9345 boolean hasReadPermission) {
9346 String iccId = slot.getIccId(portIndex);
9347 if (hasReadPermission) { // if has read permission
9348 return iccId;
9349 } else {
9350 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9351 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9352 // if no read permission, checking carrier privilege access
9353 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9354 return iccId;
9355 }
9356 }
9357 }
9358 // No read permission or carrier privilege access.
9359 return UiccPortInfo.ICCID_REDACTED;
9360 }
9361
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009362 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009363 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009364 public boolean switchSlots(int[] physicalSlots) {
9365 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009366
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009369 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9370 for (int i = 0; i < physicalSlots.length; i++) {
9371 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9372 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9373 physicalSlots[i], i));
9374 }
9375 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009376 } finally {
9377 Binder.restoreCallingIdentity(identity);
9378 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009379 }
Jack Yu4c988042018-02-27 15:30:01 -08009380
9381 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009382 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9383 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9384 enforceModifyPermission();
9385
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009388 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009389 } finally {
9390 Binder.restoreCallingIdentity(identity);
9391 }
9392 }
9393
9394 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009395 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009396 final long identity = Binder.clearCallingIdentity();
9397 try {
9398 return UiccController.getInstance().getCardIdForDefaultEuicc();
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
9403
Pengquan Meng85728fb2018-03-12 16:31:21 -07009404 /**
goneil47ffb6e2018-04-06 15:40:58 -07009405 * A test API to reload the UICC profile.
9406 *
9407 * <p>Requires that the calling app has permission
9408 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9409 * @hide
9410 */
9411 @Override
9412 public void refreshUiccProfile(int subId) {
9413 enforceModifyPermission();
9414
9415 final long identity = Binder.clearCallingIdentity();
9416 try {
9417 Phone phone = getPhone(subId);
9418 if (phone == null) {
9419 return;
9420 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009421 UiccPort uiccPort = phone.getUiccPort();
9422 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009423 return;
9424 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009425 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009426 if (uiccProfile == null) {
9427 return;
9428 }
9429 uiccProfile.refresh();
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
9435 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009436 * Returns false if the mobile data is disabled by default, otherwise return true.
9437 */
9438 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009439 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009440 }
9441
9442 /**
9443 * Returns true if the data roaming is enabled by default, i.e the system property
9444 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9445 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9446 */
9447 private boolean getDefaultDataRoamingEnabled(int subId) {
9448 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009449 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009450 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009451 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9452 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9453 return isDataRoamingEnabled;
9454 }
9455
9456 /**
9457 * Returns the default network type for the given {@code subId}, if the default network type is
9458 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9459 */
9460 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009461 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009462 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009463 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9464 return list.get(phoneId);
9465 }
9466 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009467 }
fionaxua13278b2018-03-21 00:08:13 -07009468
9469 @Override
9470 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009471 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009473
9474 final long identity = Binder.clearCallingIdentity();
9475 try {
9476 final Phone phone = getPhone(subId);
9477 if (phone == null) {
9478 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9479 return;
9480 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009481 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9482 if (cpt != null) {
9483 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9484 }
9485 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009486 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9487 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009488 if (carrierPrivilegeRules == null) {
9489 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9490 } else {
9491 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009493 } finally {
9494 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009495 }
fionaxua13278b2018-03-21 00:08:13 -07009496 }
9497
9498 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009499 public void setCarrierServicePackageOverride(
9500 int subId, String carrierServicePackage, String callingPackage) {
9501 TelephonyPermissions.enforceShellOnly(
9502 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9503
Benedict Wong66477622023-02-03 23:30:57 +00009504 final long identity = Binder.clearCallingIdentity();
9505 try {
9506 final Phone phone = getPhone(subId);
9507 if (phone == null || phone.getSubId() != subId) {
9508 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9509 throw new IllegalArgumentException("No phone for subid");
9510 }
9511 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9512 if (cpt == null) {
9513 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9514 throw new IllegalStateException("No CPT for phone");
9515 }
9516 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
9520 }
9521
9522 @Override
fionaxua13278b2018-03-21 00:08:13 -07009523 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009524 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009525
9526 final long identity = Binder.clearCallingIdentity();
9527 try {
9528 final Phone phone = getPhone(subId);
9529 if (phone == null) {
9530 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9531 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9532 }
9533 return phone.getCarrierIdListVersion();
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009536 }
fionaxua13278b2018-03-21 00:08:13 -07009537 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009538
9539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009540 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9541 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009543 mApp, subId, callingPackage, callingFeatureId,
9544 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009545 return -1;
9546 }
9547
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009555
9556 @Override
9557 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009558 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009559 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009560 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009561
9562 final long identity = Binder.clearCallingIdentity();
9563 try {
9564 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9565 } finally {
9566 Binder.restoreCallingIdentity(identity);
9567 }
9568 }
9569
9570 @Override
9571 public boolean setCdmaRoamingMode(int subId, int mode) {
9572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9573 mApp, subId, "setCdmaRoamingMode");
9574
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581 }
9582
9583 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009584 public int getCdmaSubscriptionMode(int subId) {
9585 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009586 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009587 mApp, subId, "getCdmaSubscriptionMode");
9588
9589 final long identity = Binder.clearCallingIdentity();
9590 try {
9591 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9592 } finally {
9593 Binder.restoreCallingIdentity(identity);
9594 }
9595 }
9596
9597 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009598 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9600 mApp, subId, "setCdmaSubscriptionMode");
9601
9602 final long identity = Binder.clearCallingIdentity();
9603 try {
9604 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9605 } finally {
9606 Binder.restoreCallingIdentity(identity);
9607 }
9608 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009609
sqianc5eccab2018-10-19 18:46:41 -07009610 @Override
sqian8c685422019-02-22 15:55:18 -08009611 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009612 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009614 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9615 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009616 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9617 }
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
sqian854d44b2018-12-12 16:48:18 -08009620 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9621 for (Phone phone: PhoneFactory.getPhones()) {
9622 if (phone.getEmergencyNumberTracker() != null
9623 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9624 emergencyNumberListInternal.put(
9625 phone.getSubId(),
9626 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9627 }
sqian11b7a0e2018-12-05 18:48:28 -08009628 }
sqian854d44b2018-12-12 16:48:18 -08009629 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
sqianc5eccab2018-10-19 18:46:41 -07009633 }
9634
9635 @Override
sqian8c685422019-02-22 15:55:18 -08009636 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009637 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009638 if (!exactMatch) {
9639 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009640 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009641 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009642 }
9643 final long identity = Binder.clearCallingIdentity();
9644 try {
sqian854d44b2018-12-12 16:48:18 -08009645 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009646 //Note: we ignore passed in param exactMatch. We can remove it once
9647 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009648 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009649 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009650 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009651 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009652 }
sqian11b7a0e2018-12-05 18:48:28 -08009653 }
9654 return false;
9655 } finally {
9656 Binder.restoreCallingIdentity(identity);
9657 }
9658 }
9659
sqianf4ca7ed2019-01-15 18:32:07 -08009660 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009661 * Start emergency callback mode for GsmCdmaPhone for testing.
9662 */
9663 @Override
9664 public void startEmergencyCallbackMode() {
9665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9666 "startEmergencyCallbackMode");
9667 enforceModifyPermission();
9668 final long identity = Binder.clearCallingIdentity();
9669 try {
9670 for (Phone phone : PhoneFactory.getPhones()) {
9671 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9672 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9673 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9674 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9675 gsmCdmaPhone.obtainMessage(
9676 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9677 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9678 }
9679 }
9680 } finally {
9681 Binder.restoreCallingIdentity(identity);
9682 }
9683 }
9684
9685 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009686 * Update emergency number list for test mode.
9687 */
9688 @Override
9689 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9691 "updateEmergencyNumberListTestMode");
9692
9693 final long identity = Binder.clearCallingIdentity();
9694 try {
9695 for (Phone phone: PhoneFactory.getPhones()) {
9696 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9697 if (tracker != null) {
9698 tracker.executeEmergencyNumberTestModeCommand(action, num);
9699 }
9700 }
9701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
9705
9706 /**
9707 * Get the full emergency number list for test mode.
9708 */
9709 @Override
9710 public List<String> getEmergencyNumberListTestMode() {
9711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9712 "getEmergencyNumberListTestMode");
9713
9714 final long identity = Binder.clearCallingIdentity();
9715 try {
9716 Set<String> emergencyNumbers = new HashSet<>();
9717 for (Phone phone: PhoneFactory.getPhones()) {
9718 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9719 if (tracker != null) {
9720 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9721 emergencyNumbers.add(num.getNumber());
9722 }
9723 }
9724 }
9725 return new ArrayList<>(emergencyNumbers);
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729 }
9730
chen xud6b45bd2018-10-30 22:27:10 -07009731 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009732 public int getEmergencyNumberDbVersion(int subId) {
9733 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9734
9735 final long identity = Binder.clearCallingIdentity();
9736 try {
9737 final Phone phone = getPhone(subId);
9738 if (phone == null) {
9739 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9740 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9741 }
9742 return phone.getEmergencyNumberDbVersion();
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
9745 }
9746 }
9747
9748 @Override
9749 public void notifyOtaEmergencyNumberDbInstalled() {
9750 enforceModifyPermission();
9751
9752 final long identity = Binder.clearCallingIdentity();
9753 try {
9754 for (Phone phone: PhoneFactory.getPhones()) {
9755 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9756 if (tracker != null) {
9757 tracker.updateOtaEmergencyNumberDatabase();
9758 }
9759 }
9760 } finally {
9761 Binder.restoreCallingIdentity(identity);
9762 }
9763 }
9764
9765 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009766 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009767 enforceActiveEmergencySessionPermission();
9768
9769 final long identity = Binder.clearCallingIdentity();
9770 try {
9771 for (Phone phone: PhoneFactory.getPhones()) {
9772 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9773 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009774 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9775 }
9776 }
9777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
9781
9782 @Override
9783 public void resetOtaEmergencyNumberDbFilePath() {
9784 enforceActiveEmergencySessionPermission();
9785
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
9788 for (Phone phone: PhoneFactory.getPhones()) {
9789 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9790 if (tracker != null) {
9791 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009792 }
9793 }
9794 } finally {
9795 Binder.restoreCallingIdentity(identity);
9796 }
9797 }
9798
9799 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009800 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9801 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9802 Phone phone = getPhone(subId);
9803 if (phone == null) {
9804 return null;
9805 }
9806 final long identity = Binder.clearCallingIdentity();
9807 try {
9808 UiccProfile profile = UiccController.getInstance()
9809 .getUiccProfileForPhone(phone.getPhoneId());
9810 if (profile != null) {
9811 return profile.getCertsFromCarrierPrivilegeAccessRules();
9812 }
9813 } finally {
9814 Binder.restoreCallingIdentity(identity);
9815 }
9816 return null;
9817 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009818
9819 /**
9820 * Enable or disable a modem stack.
9821 */
9822 @Override
9823 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9824 enforceModifyPermission();
9825
9826 final long identity = Binder.clearCallingIdentity();
9827 try {
9828 Phone phone = PhoneFactory.getPhone(slotIndex);
9829 if (phone == null) {
9830 return false;
9831 } else {
9832 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9833 }
9834 } finally {
9835 Binder.restoreCallingIdentity(identity);
9836 }
9837 }
Michelecea4cf22018-12-21 15:00:11 -08009838
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009839 /**
9840 * Whether a modem stack is enabled or not.
9841 */
9842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009843 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9844 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009845 Phone phone = PhoneFactory.getPhone(slotIndex);
9846 if (phone == null) return false;
9847
9848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009849 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9850 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009851 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9852 }
9853
9854 final long identity = Binder.clearCallingIdentity();
9855 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009856 try {
9857 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9858 } catch (NoSuchElementException ex) {
9859 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9860 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
9865
Michelecea4cf22018-12-21 15:00:11 -08009866 @Override
Michele0ea7d782019-03-19 14:58:42 -07009867 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009868 enforceModifyPermission();
9869
9870 final long identity = Binder.clearCallingIdentity();
9871 try {
9872 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009873 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009874 .commit();
9875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 }
9879
9880 @Override
Michele0ea7d782019-03-19 14:58:42 -07009881 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009882 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009884 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9885 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009886 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009887 }
Michelecea4cf22018-12-21 15:00:11 -08009888
9889 final long identity = Binder.clearCallingIdentity();
9890 try {
Michele0ea7d782019-03-19 14:58:42 -07009891 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009896
Michele0ea7d782019-03-19 14:58:42 -07009897 @TelephonyManager.IsMultiSimSupportedResult
9898 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009899 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9900 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9901 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009902 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9903 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009904 }
9905 // Check if the hardware supports multisim functionality. If usage of multisim is not
9906 // supported by the modem, indicate that it is restricted.
9907 PhoneCapability staticCapability =
9908 mPhoneConfigurationManager.getStaticPhoneCapability();
9909 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009910 loge("isMultiSimSupportedInternal: no static configuration available");
9911 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009912 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009913 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009914 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9915 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009916 }
9917 // Check if support of multiple SIMs is restricted by carrier
9918 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009919 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009920 }
9921
Michele0ea7d782019-03-19 14:58:42 -07009922 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009923 }
9924
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009925 /**
9926 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009927 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9928 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9929 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009930 * @param numOfSims number of active sims we want to switch to
9931 */
9932 @Override
9933 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009934 if (numOfSims == 1) {
9935 enforceModifyPermission();
9936 } else {
9937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9938 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9939 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009940 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009941
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009942 try {
Michele30b57b22019-03-01 12:01:14 -08009943 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009944 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009945 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9946 return;
9947 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009948 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 }
9953
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009954 @Override
9955 public boolean isApplicationOnUicc(int subId, int appType) {
9956 enforceReadPrivilegedPermission("isApplicationOnUicc");
9957 Phone phone = getPhone(subId);
9958 if (phone == null) {
9959 return false;
9960 }
9961 final long identity = Binder.clearCallingIdentity();
9962 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009963 UiccPort uiccPort = phone.getUiccPort();
9964 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009965 return false;
9966 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009967 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009968 if (uiccProfile == null) {
9969 return false;
9970 }
9971 if (TelephonyManager.APPTYPE_SIM <= appType
9972 && appType <= TelephonyManager.APPTYPE_ISIM) {
9973 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9974 }
9975 return false;
9976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
9980
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009981 /**
chen xub4baa772019-04-03 10:23:41 -07009982 * Get whether making changes to modem configurations will trigger reboot.
9983 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009984 */
9985 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009986 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9987 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009989 mApp, subId, callingPackage, callingFeatureId,
9990 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009991 return false;
9992 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009993 final long identity = Binder.clearCallingIdentity();
9994 try {
9995 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9996 } finally {
9997 Binder.restoreCallingIdentity(identity);
9998 }
9999 }
10000
Nathan Harold29f5f052019-02-15 13:41:57 -080010001 private void updateModemStateMetrics() {
10002 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10003 // TODO: check the state for each modem if the api is ready.
10004 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10005 }
10006
Pengquan Meng3889a572019-01-23 11:16:29 -080010007 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010008 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010009 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010010 // Verify that the callingPackage belongs to the calling UID
10011 mApp.getSystemService(AppOpsManager.class)
10012 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010013 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010014 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010015 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010016 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10017 if (slotInfos != null) {
10018 for (int i = 0; i < slotInfos.length; i++) {
10019 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10020 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10021 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10022 portInfo.getLogicalSlotIndex()));
10023 }
10024 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010025 }
10026 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010027 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010028 } finally {
10029 Binder.restoreCallingIdentity(identity);
10030 }
10031 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010032
10033 /**
10034 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010035 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010036 */
jimsunf9ec1622022-09-13 21:18:43 +080010037 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010038 @Override
10039 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010040 return getHalVersion(HAL_SERVICE_RADIO);
10041 }
10042
10043 /**
10044 * Get the HAL Version of a specific service
10045 */
10046 @Override
10047 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010048 Phone phone = getDefaultPhone();
10049 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010050 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010051 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10052 return hv.major * 100 + hv.minor;
10053 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010054
10055 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010056 * Get the current calling package name.
10057 * @return the current calling package name
10058 */
10059 @Override
10060 public String getCurrentPackageName() {
10061 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10062 }
10063
10064 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010065 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10066 * corresponding network requests on a subId.
10067 *
10068 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010069 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010070 * 2) APN is un-metered for this subscription, or
10071 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010072 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010073 *
10074 * @return whether data is allowed for a apn type.
10075 *
10076 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010077 */
10078 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010079 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010080 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10081 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010082
10083 // Now that all security checks passes, perform the operation as ourselves.
10084 final long identity = Binder.clearCallingIdentity();
10085 try {
10086 Phone phone = getPhone(subId);
10087 if (phone == null) return false;
10088
Jack Yu27422a52022-03-21 10:38:05 -070010089 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010090 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010091 isMetered = phone.getDataNetworkController().getDataConfigManager()
10092 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10093 phone.getServiceState().getDataRoaming());
10094 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010095 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 }
10100
10101 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010102 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010103 enforceReadPrivilegedPermission("isApnMetered");
10104
10105 // Now that all security checks passes, perform the operation as ourselves.
10106 final long identity = Binder.clearCallingIdentity();
10107 try {
10108 Phone phone = getPhone(subId);
10109 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010110 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10111 DataUtils.apnTypeToNetworkCapability(apnType),
10112 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010113 } finally {
10114 Binder.restoreCallingIdentity(identity);
10115 }
10116 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010117
10118 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010119 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10120 int subscriptionId, IBooleanConsumer resultCallback) {
10121 enforceModifyPermission();
10122 long token = Binder.clearCallingIdentity();
10123 try {
10124 Phone phone = getPhone(subscriptionId);
10125 if (phone == null) {
10126 try {
10127 if (resultCallback != null) {
10128 resultCallback.accept(false);
10129 }
10130 } catch (RemoteException e) {
10131 // ignore
10132 }
10133 return;
10134 }
10135 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10136 Pair.create(specifiers, (x) -> {
10137 try {
10138 if (resultCallback != null) {
10139 resultCallback.accept(x);
10140 }
10141 } catch (RemoteException e) {
10142 // ignore
10143 }
10144 });
10145 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10146 } finally {
10147 Binder.restoreCallingIdentity(token);
10148 }
10149 }
10150
10151 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010152 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10153 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010154 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010155 mApp, subId, "getSystemSelectionChannels");
10156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10157 final long identity = Binder.clearCallingIdentity();
10158 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010159 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10160 if (result instanceof IllegalStateException) {
10161 throw (IllegalStateException) result;
10162 }
10163 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010164 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10165 return specifiers;
10166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010172 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010173 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010174 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010175 }
10176
10177 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010178 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10179 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010180 if (callingPackage == null) {
10181 callingPackage = getCurrentPackageName();
10182 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010183 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10184 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010185 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10186 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010187 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10188 }
10189 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10190 Intent intent = new Intent();
10191 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10192 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10193 // Bring up choose default SMS subscription dialog right now
10194 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10195 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10196 mApp.startActivity(intent);
10197 }
chen xud5ca2d52019-05-28 15:20:57 -070010198
10199 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010200 public void showSwitchToManagedProfileDialog() {
10201 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010202 try {
10203 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10204 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10205 // for work telephony.
10206 Intent intent = new Intent(Intent.ACTION_SENDTO);
10207 intent.setData(Uri.parse("smsto:"));
10208 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10209 mApp.startActivity(intent);
10210 } catch (ActivityNotFoundException e) {
10211 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10212 Intent intent = new Intent();
10213 intent.setClass(mApp, ErrorDialogActivity.class);
10214 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10215 mApp.startActivity(intent);
10216 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010217 }
10218
10219 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010220 public String getMmsUAProfUrl(int subId) {
10221 //TODO investigate if this API should require proper permission check in R b/133791609
10222 final long identity = Binder.clearCallingIdentity();
10223 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010224 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10225 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10226 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10227 return carrierUAProfUrl;
10228 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010229 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10230 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 @Override
10237 public String getMmsUserAgent(int subId) {
10238 //TODO investigate if this API should require proper permission check in R b/133791609
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010241 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10242 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10243 if (!TextUtils.isEmpty(carrierUserAgent)) {
10244 return carrierUserAgent;
10245 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010246 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10247 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
Jack Yub07d4972019-05-28 16:12:25 -070010252
10253 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010254 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10255 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010256
Jack Yub07d4972019-05-28 16:12:25 -070010257 final long identity = Binder.clearCallingIdentity();
10258 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010259 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010260 if (phone == null) return false;
10261
Ling Maf188d502022-09-16 15:22:36 -070010262 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010263 } finally {
10264 Binder.restoreCallingIdentity(identity);
10265 }
10266 }
10267
10268 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010269 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010270 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010271 enforceModifyPermission();
10272
changbettyd5c246e2019-12-24 15:40:37 +080010273 final long identity = Binder.clearCallingIdentity();
10274 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010275 Phone phone = getPhone(subscriptionId);
10276 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010277
Ling Maf188d502022-09-16 15:22:36 -070010278 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010279 } finally {
10280 Binder.restoreCallingIdentity(identity);
10281 }
10282 }
10283
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010284 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010285 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010286 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10287 * otherwise.
10288 */
10289 @Override
10290 public void setCepEnabled(boolean isCepEnabled) {
10291 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10292
10293 final long identity = Binder.clearCallingIdentity();
10294 try {
10295 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10296 for (Phone phone : PhoneFactory.getPhones()) {
10297 Phone defaultPhone = phone.getImsPhone();
10298 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10299 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10300 ImsPhoneCallTracker imsPhoneCallTracker =
10301 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10302 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10303 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10304 + imsPhone.getMsisdn());
10305 }
10306 }
10307 } finally {
10308 Binder.restoreCallingIdentity(identity);
10309 }
10310 }
allenwtsu46dcc572020-01-08 18:24:03 +080010311
10312 /**
10313 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10314 *
10315 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10316 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10317 * before being read.
10318 */
10319 @Override
10320 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10321 isCompressed) {
10322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10323 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010324 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10325 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10326 }
10327 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010328 // ProvisioningManager can not handle ServiceSpecificException.
10329 // Throw the IllegalStateException and annotate ProvisioningManager.
10330 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010331 }
10332
10333 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010334 try {
Hui Wang761a6682020-10-31 05:12:53 +000010335 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10336 } finally {
10337 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010338 }
10339 }
zoey chene02881a2019-12-30 16:11:23 +080010340
10341 @Override
10342 public boolean isIccLockEnabled(int subId) {
10343 enforceReadPrivilegedPermission("isIccLockEnabled");
10344
10345 // Now that all security checks passes, perform the operation as ourselves.
10346 final long identity = Binder.clearCallingIdentity();
10347 try {
10348 Phone phone = getPhone(subId);
10349 if (phone != null && phone.getIccCard() != null) {
10350 return phone.getIccCard().getIccLockEnabled();
10351 } else {
10352 return false;
10353 }
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
10358
10359 /**
10360 * Set the ICC pin lock enabled or disabled.
10361 *
10362 * @return an integer representing the status of IccLock enabled or disabled in the following
10363 * three cases:
10364 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10365 * successfully.
10366 * - Positive number and zero for remaining password attempts.
10367 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10368 *
10369 */
10370 @Override
10371 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10372 enforceModifyPermission();
10373
10374 Phone phone = getPhone(subId);
10375 if (phone == null) {
10376 return 0;
10377 }
10378 // Now that all security checks passes, perform the operation as ourselves.
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10382 new Pair<Boolean, String>(enabled, password), phone, null);
10383 return attemptsRemaining;
10384
10385 } catch (Exception e) {
10386 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10387 } finally {
10388 Binder.restoreCallingIdentity(identity);
10389 }
10390 return 0;
10391 }
10392
10393 /**
10394 * Change the ICC password used in ICC pin lock.
10395 *
10396 * @return an integer representing the status of IccLock changed in the following three cases:
10397 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10398 * - Positive number and zero for remaining password attempts.
10399 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10400 *
10401 */
10402 @Override
10403 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10404 enforceModifyPermission();
10405
10406 Phone phone = getPhone(subId);
10407 if (phone == null) {
10408 return 0;
10409 }
10410 // Now that all security checks passes, perform the operation as ourselves.
10411 final long identity = Binder.clearCallingIdentity();
10412 try {
10413 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10414 new Pair<String, String>(oldPassword, newPassword), phone, null);
10415 return attemptsRemaining;
10416
10417 } catch (Exception e) {
10418 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10419 } finally {
10420 Binder.restoreCallingIdentity(identity);
10421 }
10422 return 0;
10423 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010424
10425 /**
10426 * Request for receiving user activity notification
10427 */
10428 @Override
10429 public void requestUserActivityNotification() {
10430 if (!mNotifyUserActivity.get()
10431 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10432 mNotifyUserActivity.set(true);
10433 }
10434 }
10435
10436 /**
10437 * Called when userActivity is signalled in the power manager.
10438 * This is safe to call from any thread, with any window manager locks held or not.
10439 */
10440 @Override
10441 public void userActivity() {
10442 // ***************************************
10443 // * Inherited from PhoneWindowManager *
10444 // ***************************************
10445 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10446 // WITH ITS LOCKS HELD.
10447 //
10448 // This code must be VERY careful about the locks
10449 // it acquires.
10450 // In fact, the current code acquires way too many,
10451 // and probably has lurking deadlocks.
10452
10453 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10454 throw new SecurityException("Only the OS may call notifyUserActivity()");
10455 }
10456
10457 if (mNotifyUserActivity.getAndSet(false)) {
10458 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10459 USER_ACTIVITY_NOTIFICATION_DELAY);
10460 }
10461 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010462
10463 @Override
10464 public boolean canConnectTo5GInDsdsMode() {
10465 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10466 }
Jack Yud10cdd42020-09-28 20:28:01 -070010467
10468 @Override
10469 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10470 String callingFeatureId) {
10471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10472 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10473 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10474 }
10475
10476 Phone phone = getPhone(subId);
10477 if (phone == null) {
10478 throw new RuntimeException("phone is not available");
10479 }
10480 // Now that all security checks passes, perform the operation as ourselves.
10481 final long identity = Binder.clearCallingIdentity();
10482 try {
10483 return phone.getEquivalentHomePlmns();
10484 } finally {
10485 Binder.restoreCallingIdentity(identity);
10486 }
10487 }
Daniel Bright59e67312020-11-13 11:49:37 -080010488
10489 @Override
10490 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010491 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10492 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010493 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010494 if (radioInterfaceCapabilities == null) {
10495 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010496 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010497 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010498 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010499
Hui Wang641e81c2020-10-12 12:14:23 -070010500 @Override
10501 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10502 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010503 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10504 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10505 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10506 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10507 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010508 if (DBG) {
10509 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10510 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10511 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10512 }
10513
10514 if (!SubscriptionManager.isValidSubscriptionId(subId)
10515 || appType < TelephonyManager.APPTYPE_UNKNOWN
10516 || appType > TelephonyManager.APPTYPE_ISIM
10517 || nafUrl == null || securityProtocol == null || callback == null) {
10518 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10519 if (callback != null) {
10520 try {
10521 callback.onAuthenticationFailure(
10522 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10523 } catch (RemoteException exception) {
10524 log("Fail to notify onAuthenticationFailure due to " + exception);
10525 }
10526 return;
10527 }
10528 }
10529
10530 final long token = Binder.clearCallingIdentity();
10531 try {
10532 getGbaManager(subId).bootstrapAuthenticationRequest(
10533 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010534 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010535 } finally {
10536 Binder.restoreCallingIdentity(token);
10537 }
10538 }
10539
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010540 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010541 * Attempts to set the radio power state for all phones for thermal reason.
10542 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010543 * requested radio power state will actually be set. See {@link
10544 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10545 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010546 * @param enable {@code true} if trying to turn radio on.
10547 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10548 * false}.
10549 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010550 private boolean setRadioPowerForThermal(boolean enable) {
10551 boolean isPhoneAvailable = false;
10552 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10553 Phone phone = PhoneFactory.getPhone(i);
10554 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010555 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010556 isPhoneAvailable = true;
10557 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010559
10560 // return true if successfully informed the phone object about the thermal radio power
10561 // request.
10562 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010563 }
10564
10565 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010566 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010567 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10568 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10569 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10570 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10571 throw new IllegalArgumentException("modem does not support data throttling");
10572 }
10573
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010574 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10575 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010576 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010577 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10578 }
10579
Sarah Chinecc78c42022-03-31 21:16:48 -070010580 setDataEnabledForReason(
10581 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010582
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010583 if (isDataThrottlingSupported) {
10584 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010585 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010586 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10587 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10588 } else if (thermalMitigationResult
10589 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010590 log("Modem likely does not support data throttling on secondary carrier. Data " +
10591 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10592 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010593 }
10594 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010595 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010596
10597 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010598 }
10599
Jack Nudelman644b91a2021-03-12 14:09:48 -080010600 private static List<String> getThermalMitigationAllowlist(Context context) {
10601 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10602 for (String pckg : context.getResources()
10603 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10604 sThermalMitigationAllowlistedPackages.add(pckg);
10605 }
10606 }
10607
10608 return sThermalMitigationAllowlistedPackages;
10609 }
10610
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010611 private boolean isAnyPhoneInEmergencyState() {
10612 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10613 if (tm.isInEmergencyCall()) {
10614 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10615 return true;
10616 }
10617 for (Phone phone : PhoneFactory.getPhones()) {
10618 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10619 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010620 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10621 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010622 return true;
10623 }
10624 }
10625
10626 return false;
10627 }
10628
Jack Nudelman644b91a2021-03-12 14:09:48 -080010629 /**
10630 * Used by shell commands to add an authorized package name for thermal mitigation.
10631 * @param packageName name of package to be allowlisted
10632 * @param context
10633 */
10634 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10635 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10636 sThermalMitigationAllowlistedPackages.add(packageName);
10637 }
10638
10639 /**
10640 * Used by shell commands to remove an authorized package name for thermal mitigation.
10641 * @param packageName name of package to remove from allowlist
10642 * @param context
10643 */
10644 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10645 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10646 sThermalMitigationAllowlistedPackages.remove(packageName);
10647 }
10648
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010649 /**
10650 * Thermal mitigation request to control functionalities at modem.
10651 *
10652 * @param subId the id of the subscription.
10653 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010654 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010655 *
10656 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10657 */
10658 @Override
10659 @ThermalMitigationResult
10660 public int sendThermalMitigationRequest(
10661 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010662 ThermalMitigationRequest thermalMitigationRequest,
10663 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010664 enforceModifyPermission();
10665
Jack Nudelman644b91a2021-03-12 14:09:48 -080010666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10667 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10668 .contains(callingPackage)) {
10669 throw new SecurityException("Calling package must be configured in the device config. "
10670 + "calling package: " + callingPackage);
10671 }
10672
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010673 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10674 final long identity = Binder.clearCallingIdentity();
10675
10676 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10677 try {
10678 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10679 switch (thermalMitigationAction) {
10680 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10681 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010682 handleDataThrottlingRequest(subId,
10683 thermalMitigationRequest.getDataThrottlingRequest(),
10684 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010685 break;
10686 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10687 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10688 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10689 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10690 }
10691
10692 // Ensure that radio is on. If not able to power on due to phone being
10693 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010694 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010695 thermalMitigationResult =
10696 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10697 break;
10698 }
10699
10700 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010701 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010702 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10703 break;
10704 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10705 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10706 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10707 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10708 }
10709
10710 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10711 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010712 Phone phone = getPhone(subId);
10713 if (phone == null) {
10714 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010715 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010716 break;
10717 }
10718
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010719 TelephonyConnectionService service =
10720 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010721 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010722 Log.e(LOG_TAG, "An emergency call is pending");
10723 thermalMitigationResult =
10724 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10725 break;
10726 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010727 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010728 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010729 break;
10730 }
10731 } else {
10732 thermalMitigationResult =
10733 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10734 break;
10735 }
10736
10737 // Turn radio off. If not able to power off due to phone being unavailable,
10738 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010739 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010740 thermalMitigationResult =
10741 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10742 break;
10743 }
10744 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010745 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010746 break;
10747 default:
10748 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10749 + "not exist. Requested action: " + thermalMitigationAction);
10750 }
10751 } catch (IllegalArgumentException e) {
10752 throw e;
10753 } catch (Exception e) {
10754 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10755 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759
10760 if (DBG) {
10761 log("thermalMitigationRequest returning with thermalMitigationResult: "
10762 + thermalMitigationResult);
10763 }
10764
10765 return thermalMitigationResult;
10766 }
Hui Wang641e81c2020-10-12 12:14:23 -070010767
10768 /**
10769 * Set the GbaService Package Name that Telephony will bind to.
10770 *
10771 * @param subId The sim that the GbaService is associated with.
10772 * @param packageName The name of the package to be replaced with.
10773 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10774 */
10775 @Override
10776 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10777 enforceModifyPermission();
10778
10779 final long identity = Binder.clearCallingIdentity();
10780 try {
10781 return getGbaManager(subId).overrideServicePackage(packageName);
10782 } finally {
10783 Binder.restoreCallingIdentity(identity);
10784 }
10785 }
10786
10787 /**
10788 * Return the package name of the currently bound GbaService.
10789 *
10790 * @param subId The sim that the GbaService is associated with.
10791 * @return the package name of the GbaService configuration, null if GBA is not supported.
10792 */
10793 @Override
10794 public String getBoundGbaService(int subId) {
10795 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10796
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return getGbaManager(subId).getServicePackage();
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
10805 /**
10806 * Set the release time for telephony to unbind GbaService.
10807 *
10808 * @param subId The sim that the GbaService is associated with.
10809 * @param interval The release time to unbind GbaService by millisecond.
10810 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10811 */
10812 @Override
10813 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10814 enforceModifyPermission();
10815
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 return getGbaManager(subId).overrideReleaseTime(interval);
10819 } finally {
10820 Binder.restoreCallingIdentity(identity);
10821 }
10822 }
10823
10824 /**
10825 * Return the release time for telephony to unbind GbaService.
10826 *
10827 * @param subId The sim that the GbaService is associated with.
10828 * @return The release time to unbind GbaService by millisecond.
10829 */
10830 @Override
10831 public int getGbaReleaseTime(int subId) {
10832 enforceReadPrivilegedPermission("getGbaReleaseTime");
10833
10834 final long identity = Binder.clearCallingIdentity();
10835 try {
10836 return getGbaManager(subId).getReleaseTime();
10837 } finally {
10838 Binder.restoreCallingIdentity(identity);
10839 }
10840 }
10841
10842 private GbaManager getGbaManager(int subId) {
10843 GbaManager instance = GbaManager.getInstance(subId);
10844 if (instance == null) {
10845 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10846 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10847 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10848 }
10849 return instance;
10850 }
Hui Wang761a6682020-10-31 05:12:53 +000010851
10852 /**
10853 * indicate whether the device and the carrier can support
10854 * RCS VoLTE single registration.
10855 */
10856 @Override
10857 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010858 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10859 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10860 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10861 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010862
10863 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10864 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10865 }
10866
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10870 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010871 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10872 if (isCapable != null) {
10873 return isCapable;
10874 }
Hui Wang761a6682020-10-31 05:12:53 +000010875 }
Hui Wang67af90e2021-06-04 16:57:15 -070010876 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10877 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010878 } finally {
10879 Binder.restoreCallingIdentity(identity);
10880 }
10881 }
10882
10883 /**
10884 * Register RCS provisioning callback.
10885 */
10886 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010887 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010888 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010889 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010890 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010891 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10892 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010893
10894 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10895 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10896 }
10897 if (!isImsAvailableOnDevice()) {
10898 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10899 "IMS not available on device.");
10900 }
10901
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010904 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010905 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010906 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10907 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010908 }
Hui Wang761a6682020-10-31 05:12:53 +000010909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
10913
10914 /**
10915 * Unregister RCS provisioning callback.
10916 */
10917 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010918 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010919 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010920 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010921 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010922 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10923 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010924
10925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10926 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10927 }
10928 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010929 // operation failed silently
10930 Rlog.w(LOG_TAG, "IMS not available on device.");
10931 return;
Hui Wang761a6682020-10-31 05:12:53 +000010932 }
10933
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010936 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010937 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010938 } finally {
10939 Binder.restoreCallingIdentity(identity);
10940 }
10941 }
10942
10943 /**
10944 * trigger RCS reconfiguration.
10945 */
10946 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010947 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10948 "triggerRcsReconfiguration",
10949 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010950
10951 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10952 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10953 }
10954 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010955 // ProvisioningManager can not handle ServiceSpecificException.
10956 // Throw the IllegalStateException and annotate ProvisioningManager.
10957 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010958 }
10959
10960 final long identity = Binder.clearCallingIdentity();
10961 try {
10962 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10963 } finally {
10964 Binder.restoreCallingIdentity(identity);
10965 }
10966 }
10967
10968 /**
10969 * Provide the client configuration parameters of the RCS application.
10970 */
10971 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010972 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10973 "setRcsClientConfiguration",
10974 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010975
10976 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10977 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10978 }
10979 if (!isImsAvailableOnDevice()) {
10980 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10981 "IMS not available on device.");
10982 }
10983
10984 final long identity = Binder.clearCallingIdentity();
10985
10986 try {
10987 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10988 if (configBinder == null) {
10989 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010990 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10991 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010992 } else {
10993 configBinder.setRcsClientConfiguration(rcc);
10994 }
joonhunshin3e154242021-09-17 06:33:39 +000010995
10996 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10997 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010998 } catch (RemoteException e) {
10999 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011000 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11001 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011002 } finally {
11003 Binder.restoreCallingIdentity(identity);
11004 }
11005 }
11006
11007 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011008 * Enables or disables the test mode for RCS VoLTE single registration.
11009 */
11010 @Override
11011 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11013 "setRcsSingleRegistrationTestModeEnabled");
11014
11015 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11016 }
11017
11018 /**
11019 * Gets the test mode for RCS VoLTE single registration.
11020 */
11021 @Override
11022 public boolean getRcsSingleRegistrationTestModeEnabled() {
11023 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11024 "getRcsSingleRegistrationTestModeEnabled");
11025
11026 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11027 }
11028
11029 /**
Hui Wang761a6682020-10-31 05:12:53 +000011030 * Overrides the config of RCS VoLTE single registration enabled for the device.
11031 */
11032 @Override
11033 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11035 "setDeviceSingleRegistrationEnabledOverride");
11036 enforceModifyPermission();
11037
11038 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11039 : Boolean.parseBoolean(enabledStr);
11040 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011041 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011042 }
11043
11044 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011045 * Sends a device to device communication message. Only usable via shell.
11046 * @param message message to send.
11047 * @param value message value.
11048 */
11049 @Override
11050 public void sendDeviceToDeviceMessage(int message, int value) {
11051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011052 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011053 enforceModifyPermission();
11054
11055 final long identity = Binder.clearCallingIdentity();
11056 try {
11057 TelephonyConnectionService service =
11058 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11059 if (service == null) {
11060 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11061 return;
11062 }
11063 service.sendTestDeviceToDeviceMessage(message, value);
11064 } finally {
11065 Binder.restoreCallingIdentity(identity);
11066 }
11067 }
11068
Tyler Gunnbabbda02021-02-10 11:05:02 -080011069 /**
11070 * Sets the specified device to device transport active.
11071 * @param transport The transport to set active.
11072 */
11073 @Override
11074 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11075 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11076 "setActiveDeviceToDeviceTransport");
11077 enforceModifyPermission();
11078
11079 final long identity = Binder.clearCallingIdentity();
11080 try {
11081 TelephonyConnectionService service =
11082 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11083 if (service == null) {
11084 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11085 return;
11086 }
11087 service.setActiveDeviceToDeviceTransport(transport);
11088 } finally {
11089 Binder.restoreCallingIdentity(identity);
11090 }
11091 }
Tyler Gunn92479152021-01-20 16:30:10 -080011092
Tyler Gunnd4339262021-05-03 14:46:49 -070011093 @Override
11094 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11096 "setDeviceToDeviceForceEnabled");
11097
11098 final long identity = Binder.clearCallingIdentity();
11099 try {
11100 Arrays.stream(PhoneFactory.getPhones()).forEach(
11101 p -> {
11102 Phone thePhone = p.getImsPhone();
11103 if (thePhone != null && thePhone instanceof ImsPhone) {
11104 ImsPhone imsPhone = (ImsPhone) thePhone;
11105 CallTracker tracker = imsPhone.getCallTracker();
11106 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11107 ImsPhoneCallTracker imsPhoneCallTracker =
11108 (ImsPhoneCallTracker) tracker;
11109 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11110 }
11111 }
11112 }
11113 );
11114 } finally {
11115 Binder.restoreCallingIdentity(identity);
11116 }
11117 }
11118
Tyler Gunn92479152021-01-20 16:30:10 -080011119 /**
Hui Wang761a6682020-10-31 05:12:53 +000011120 * Gets the config of RCS VoLTE single registration enabled for the device.
11121 */
11122 @Override
11123 public boolean getDeviceSingleRegistrationEnabled() {
11124 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11125 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11126 }
11127
11128 /**
11129 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11130 */
11131 @Override
11132 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11134 "setCarrierSingleRegistrationEnabledOverride");
11135 enforceModifyPermission();
11136
11137 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11138 : Boolean.parseBoolean(enabledStr);
11139 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11140 subId, enabled);
11141 }
11142
11143 /**
11144 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11145 */
11146 @Override
11147 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11148 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11149 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11150 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011151
11152 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011153 * Overrides the ims feature validation result
11154 */
11155 @Override
11156 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11157 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11158 "setImsFeatureValidationOverride");
11159
11160 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11161 : Boolean.parseBoolean(enabledStr);
11162 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11163 subId, enabled);
11164 }
11165
11166 /**
11167 * Gets the ims feature validation override value
11168 */
11169 @Override
11170 public boolean getImsFeatureValidationOverride(int subId) {
11171 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11172 "getImsFeatureValidationOverride");
11173 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11174 }
11175
11176 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011177 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11178 * their mobile plan.
11179 */
11180 @Override
11181 public String getMobileProvisioningUrl() {
11182 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 return getDefaultPhone().getMobileProvisioningUrl();
11186 } finally {
11187 Binder.restoreCallingIdentity(identity);
11188 }
11189 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011190
James.cf Linbcdf8b32021-01-14 16:44:13 +080011191 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011192 * Get the EAB contact from the EAB database.
11193 */
11194 @Override
11195 public String getContactFromEab(String contact) {
11196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11197 enforceModifyPermission();
11198 final long identity = Binder.clearCallingIdentity();
11199 try {
11200 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11201 } finally {
11202 Binder.restoreCallingIdentity(identity);
11203 }
11204 }
11205
11206 /**
Calvin Pana1434322021-07-01 19:27:01 +080011207 * Get the EAB capability from the EAB database.
11208 */
11209 @Override
11210 public String getCapabilityFromEab(String contact) {
11211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11212 enforceModifyPermission();
11213 final long identity = Binder.clearCallingIdentity();
11214 try {
11215 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11216 } finally {
11217 Binder.restoreCallingIdentity(identity);
11218 }
11219 }
11220
11221 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011222 * Remove the EAB contacts from the EAB database.
11223 */
11224 @Override
11225 public int removeContactFromEab(int subId, String contacts) {
11226 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11227 enforceModifyPermission();
11228 final long identity = Binder.clearCallingIdentity();
11229 try {
11230 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11231 } finally {
11232 Binder.restoreCallingIdentity(identity);
11233 }
11234 }
11235
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011236 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011237 public boolean getDeviceUceEnabled() {
11238 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11239 final long identity = Binder.clearCallingIdentity();
11240 try {
11241 return mApp.getDeviceUceEnabled();
11242 } finally {
11243 Binder.restoreCallingIdentity(identity);
11244 }
11245 }
11246
11247 @Override
11248 public void setDeviceUceEnabled(boolean isEnabled) {
11249 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11250 final long identity = Binder.clearCallingIdentity();
11251 try {
11252 mApp.setDeviceUceEnabled(isEnabled);
11253 } finally {
11254 Binder.restoreCallingIdentity(identity);
11255 }
11256 }
11257
Brad Ebinger14d467f2021-02-12 06:18:28 +000011258 /**
11259 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11260 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11261 */
11262 // Used for SHELL command only right now.
11263 @Override
11264 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11265 List<String> featureTags) {
11266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11267 "addUceRegistrationOverrideShell");
11268 final long identity = Binder.clearCallingIdentity();
11269 try {
11270 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11271 new ArraySet<>(featureTags));
11272 } catch (ImsException e) {
11273 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11274 } finally {
11275 Binder.restoreCallingIdentity(identity);
11276 }
11277 }
11278
11279 /**
11280 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11281 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11282 */
11283 // Used for SHELL command only right now.
11284 @Override
11285 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11286 List<String> featureTags) {
11287 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11288 "removeUceRegistrationOverrideShell");
11289 final long identity = Binder.clearCallingIdentity();
11290 try {
11291 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11292 new ArraySet<>(featureTags));
11293 } catch (ImsException e) {
11294 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11295 } finally {
11296 Binder.restoreCallingIdentity(identity);
11297 }
11298 }
11299
11300 /**
11301 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11302 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11303 */
11304 // Used for SHELL command only right now.
11305 @Override
11306 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11307 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11308 "clearUceRegistrationOverrideShell");
11309 final long identity = Binder.clearCallingIdentity();
11310 try {
11311 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11312 } catch (ImsException e) {
11313 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11314 } finally {
11315 Binder.restoreCallingIdentity(identity);
11316 }
11317 }
11318
11319 /**
11320 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11321 */
11322 // Used for SHELL command only right now.
11323 @Override
11324 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11325 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11326 "getLatestRcsContactUceCapabilityShell");
11327 final long identity = Binder.clearCallingIdentity();
11328 try {
11329 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11330 } catch (ImsException e) {
11331 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11332 } finally {
11333 Binder.restoreCallingIdentity(identity);
11334 }
11335 }
11336
11337 /**
11338 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11339 * device does not have an active PUBLISH.
11340 */
11341 // Used for SHELL command only right now.
11342 @Override
11343 public String getLastUcePidfXmlShell(int subId) {
11344 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11345 final long identity = Binder.clearCallingIdentity();
11346 try {
11347 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11348 } catch (ImsException e) {
11349 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11350 } finally {
11351 Binder.restoreCallingIdentity(identity);
11352 }
11353 }
11354
James.cf Line8713a42021-04-29 16:04:26 +080011355 /**
11356 * Remove UCE requests cannot be sent to the network status.
11357 */
11358 // Used for SHELL command only right now.
11359 @Override
11360 public boolean removeUceRequestDisallowedStatus(int subId) {
11361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11362 final long identity = Binder.clearCallingIdentity();
11363 try {
11364 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11365 } catch (ImsException e) {
11366 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11367 } finally {
11368 Binder.restoreCallingIdentity(identity);
11369 }
11370 }
11371
James.cf Lin18bb9002021-05-25 01:37:38 +080011372 /**
11373 * Remove UCE requests cannot be sent to the network status.
11374 */
11375 // Used for SHELL command only.
11376 @Override
11377 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11378 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11379 final long identity = Binder.clearCallingIdentity();
11380 try {
11381 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11382 } catch (ImsException e) {
11383 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11384 } finally {
11385 Binder.restoreCallingIdentity(identity);
11386 }
11387 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011388
James.cf Lin4b784aa2021-01-31 03:25:15 +080011389 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011390 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11391 String callingPackage) {
11392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11393 mApp, subId, "setSignalStrengthUpdateRequest");
11394
11395 final int callingUid = Binder.getCallingUid();
11396 // Verify that tha callingPackage belongs to the calling UID
11397 mApp.getSystemService(AppOpsManager.class)
11398 .checkPackage(callingUid, callingPackage);
11399
Rambo Wang3607f502021-02-01 21:51:40 -080011400 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011401
11402 final long identity = Binder.clearCallingIdentity();
11403 try {
11404 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11405 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11406
11407 if (result instanceof IllegalStateException) {
11408 throw (IllegalStateException) result;
11409 }
11410 } finally {
11411 Binder.restoreCallingIdentity(identity);
11412 }
11413 }
11414
11415 @Override
11416 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11417 String callingPackage) {
11418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11419 mApp, subId, "clearSignalStrengthUpdateRequest");
11420
11421 final int callingUid = Binder.getCallingUid();
11422 // Verify that tha callingPackage belongs to the calling UID
11423 mApp.getSystemService(AppOpsManager.class)
11424 .checkPackage(callingUid, callingPackage);
11425
11426 final long identity = Binder.clearCallingIdentity();
11427 try {
11428 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11429 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11430
11431 if (result instanceof IllegalStateException) {
11432 throw (IllegalStateException) result;
11433 }
11434 } finally {
11435 Binder.restoreCallingIdentity(identity);
11436 }
11437 }
11438
Rambo Wang3607f502021-02-01 21:51:40 -080011439 private static void validateSignalStrengthUpdateRequest(Context context,
11440 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011441 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11442 // phone/system process do not have further restriction on request
11443 return;
11444 }
11445
11446 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011447 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011448 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011449 context.enforceCallingOrSelfPermission(
11450 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11451 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011452 }
11453
11454 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011455 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011456 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011457 || info.isEnabled()) {
11458 throw new IllegalArgumentException(
11459 "Only system can set hide fields in SignalThresholdInfo");
11460 }
11461
11462 // Thresholds length for each RAN need in range. This has been validated in
11463 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11464 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11465 final int[] thresholds = info.getThresholds();
11466 Objects.requireNonNull(thresholds);
11467 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11468 || thresholds.length
11469 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11470 throw new IllegalArgumentException(
11471 "thresholds length is out of range: " + thresholds.length);
11472 }
11473 }
11474 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011475
11476 /**
11477 * Gets the current phone capability.
11478 *
11479 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11480 * @return the PhoneCapability which describes the data connection capability of modem.
11481 * It's used to evaluate possible phone config change, for example from single
11482 * SIM device to multi-SIM device.
11483 */
11484 @Override
11485 public PhoneCapability getPhoneCapability() {
11486 enforceReadPrivilegedPermission("getPhoneCapability");
11487 final long identity = Binder.clearCallingIdentity();
11488 try {
11489 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11490 } finally {
11491 Binder.restoreCallingIdentity(identity);
11492 }
11493 }
Michele Berionne5e411512020-11-13 02:36:59 +000011494
11495 /**
11496 * Prepare TelephonyManager for an unattended reboot. The reboot is
11497 * required to be done shortly after the API is invoked.
11498 */
11499 @Override
11500 @TelephonyManager.PrepareUnattendedRebootResult
11501 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011503 enforceRebootPermission();
11504
11505 final long identity = Binder.clearCallingIdentity();
11506 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011507 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011508 } finally {
11509 Binder.restoreCallingIdentity(identity);
11510 }
11511 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011512
11513 /**
11514 * Request to get the current slicing configuration including URSP rules and
11515 * NSSAIs (configured, allowed and rejected).
11516 *
11517 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11518 */
11519 @Override
11520 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011521 TelephonyPermissions
11522 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11523 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011524
11525 final long identity = Binder.clearCallingIdentity();
11526 try {
11527 Phone phone = getDefaultPhone();
11528 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11529 } finally {
11530 Binder.restoreCallingIdentity(identity);
11531 }
11532 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011533
11534 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011535 * Check whether the given premium capability is available for purchase from the carrier.
11536 *
11537 * @param capability The premium capability to check.
11538 * @param subId The subId to check the premium capability for.
11539 *
11540 * @return Whether the given premium capability is available to purchase.
11541 */
11542 @Override
11543 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11544 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11545 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11546 log("Premium capability "
11547 + TelephonyManager.convertPremiumCapabilityToString(capability)
11548 + " is not available for purchase due to missing permissions.");
11549 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11550 + "permission READ_BASIC_PHONE_STATE.");
11551 }
11552
11553 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011554 if (phone == null) {
11555 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11556 return false;
11557 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011558 final long identity = Binder.clearCallingIdentity();
11559 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011560 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011561 .isPremiumCapabilityAvailableForPurchase(capability);
11562 } finally {
11563 Binder.restoreCallingIdentity(identity);
11564 }
11565 }
11566
11567 /**
11568 * Purchase the given premium capability from the carrier.
11569 *
11570 * @param capability The premium capability to purchase.
11571 * @param callback The result of the purchase request.
11572 * @param subId The subId to purchase the premium capability for.
11573 */
11574 @Override
11575 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11576 log("purchasePremiumCapability: capability="
11577 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11578 + getCurrentPackageName());
11579
11580 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11581 mApp, "purchasePremiumCapability")) {
11582 log("purchasePremiumCapability "
11583 + TelephonyManager.convertPremiumCapabilityToString(capability)
11584 + " failed due to missing permissions.");
11585 throw new SecurityException("purchasePremiumCapability requires permission "
11586 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011587 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11588 mApp, "purchasePremiumCapability")) {
11589 log("purchasePremiumCapability "
11590 + TelephonyManager.convertPremiumCapabilityToString(capability)
11591 + " failed due to missing permissions.");
11592 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011593 }
11594
11595 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011596 if (phone == null) {
11597 try {
11598 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11599 callback.accept(result);
11600 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11601 } catch (RemoteException e) {
11602 String logStr = "Purchase premium capability "
11603 + TelephonyManager.convertPremiumCapabilityToString(capability)
11604 + " failed due to RemoteException handling null phone: " + e;
11605 if (DBG) log(logStr);
11606 AnomalyReporter.reportAnomaly(
11607 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11608 }
11609 return;
11610 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011611
11612 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011613 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011614 callingProcess = mApp.getPackageManager().getApplicationInfo(
11615 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011616 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011617 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011618 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011619
11620 boolean isVisible = false;
11621 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11622 if (am != null) {
11623 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11624 if (processes != null) {
11625 for (ActivityManager.RunningAppProcessInfo process : processes) {
11626 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011627 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011628 if (process.processName.equals(callingProcess) && process.importance
11629 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11630 isVisible = true;
11631 break;
11632 }
11633 }
11634 }
11635 }
11636
11637 if (!isVisible) {
11638 try {
11639 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11640 callback.accept(result);
11641 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11642 } catch (RemoteException e) {
11643 String logStr = "Purchase premium capability "
11644 + TelephonyManager.convertPremiumCapabilityToString(capability)
11645 + " failed due to RemoteException handling background application: " + e;
11646 if (DBG) log(logStr);
11647 AnomalyReporter.reportAnomaly(
11648 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11649 }
11650 return;
11651 }
11652
Sarah Chin71b3a852022-09-28 15:54:19 -070011653 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011654 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011655 }
11656
11657 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011658 * Register an IMS connection state callback
11659 */
11660 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011661 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11662 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011663 if (feature == ImsFeature.FEATURE_MMTEL) {
11664 // ImsMmTelManager
11665 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11666 TelephonyPermissions
11667 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11668 mApp, subId, "registerImsStateCallback");
11669 } else if (feature == ImsFeature.FEATURE_RCS) {
11670 // ImsRcsManager or SipDelegateManager
11671 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11672 Binder.getCallingUid(), "registerImsStateCallback",
11673 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11674 Manifest.permission.READ_PRECISE_PHONE_STATE,
11675 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11676 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11677 }
11678
11679 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11680 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11681 "IMS not available on device.");
11682 }
11683
11684 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11685 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11686 }
11687
11688 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11689 if (controller == null) {
11690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11691 "IMS not available on device.");
11692 }
11693
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011694 if (callingPackage == null) {
11695 callingPackage = getCurrentPackageName();
11696 }
11697
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011698 final long token = Binder.clearCallingIdentity();
11699 try {
11700 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011701 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011702 } catch (ImsException e) {
11703 throw new ServiceSpecificException(e.getCode());
11704 } finally {
11705 Binder.restoreCallingIdentity(token);
11706 }
11707 }
11708
11709 /**
11710 * Unregister an IMS connection state callback
11711 */
11712 @Override
11713 public void unregisterImsStateCallback(IImsStateCallback cb) {
11714 final long token = Binder.clearCallingIdentity();
11715 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11716 if (controller == null) {
11717 return;
11718 }
11719 try {
11720 controller.unregisterImsStateCallback(cb);
11721 } finally {
11722 Binder.restoreCallingIdentity(token);
11723 }
11724 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011725
11726 /**
11727 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11728 *
11729 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11730 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11731 * SecurityException.
11732 * If there is current registered network this value will be same as the registered cell
11733 * identity. If the device goes out of service the previous cell identity is cached and
11734 * will be returned. If the cache age of the Cell identity is more than 24 hours
11735 * it will be cleared and null will be returned.
11736 *
11737 */
11738 @Override
11739 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11740 String callingFeatureId) {
11741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11742 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11743 LocationAccessPolicy.checkLocationPermission(mApp,
11744 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11745 .setCallingPackage(callingPackage)
11746 .setCallingFeatureId(callingFeatureId)
11747 .setCallingPid(Binder.getCallingPid())
11748 .setCallingUid(Binder.getCallingUid())
11749 .setMethod("getLastKnownCellIdentity")
11750 .setLogAsInfo(true)
11751 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11752 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11753 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11754 .build());
11755
11756 boolean hasFinePermission =
11757 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11758 if (!hasFinePermission
11759 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11760 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011761 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011762 }
11763
11764 final long identity = Binder.clearCallingIdentity();
11765 try {
Ling Mac28f0212023-03-24 16:07:15 -070011766 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011767 if (sst == null) return null;
11768 return sst.getLastKnownCellIdentity();
11769 } finally {
11770 Binder.restoreCallingIdentity(identity);
11771 }
11772 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011773
jimsun3b9ccac2021-10-26 15:01:23 +080011774 /**
11775 * Sets the modem service class Name that Telephony will bind to.
11776 *
11777 * @param serviceName The class name of the modem service.
11778 * @return true if the operation is succeed, otherwise false.
11779 */
11780 public boolean setModemService(String serviceName) {
11781 Log.d(LOG_TAG, "setModemService - " + serviceName);
11782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011784 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11785 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011786 return mPhoneConfigurationManager.setModemService(serviceName);
11787 }
11788
11789 /**
11790 * Return the class name of the currently bounded modem service.
11791 *
11792 * @return the class name of the modem service.
11793 */
11794 public String getModemService() {
11795 String result;
11796 Log.d(LOG_TAG, "getModemService");
11797 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11798 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011799 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011800 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11801 "getModemService");
11802 result = mPhoneConfigurationManager.getModemService();
11803 Log.d(LOG_TAG, "result = " + result);
11804 return result;
11805 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011806
11807 @Override
11808 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11809 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11810 mApp.enforceCallingOrSelfPermission(
11811 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11812 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11813
11814 final long identity = Binder.clearCallingIdentity();
11815 try {
11816 Phone phone = getPhone(subId);
11817 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011818 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11819 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011820 phone.setVoiceServiceStateOverride(hasService);
11821 } finally {
11822 Binder.restoreCallingIdentity(identity);
11823 }
11824 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011825
11826 /**
11827 * set removable eSIM as default eUICC.
11828 *
11829 * @hide
11830 */
11831 @Override
11832 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11833 enforceModifyPermission();
11834 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11835
11836 final long identity = Binder.clearCallingIdentity();
11837 try {
11838 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11839 } finally {
11840 Binder.restoreCallingIdentity(identity);
11841 }
11842 }
11843
11844 /**
11845 * Returns whether the removable eSIM is default eUICC or not.
11846 *
11847 * @hide
11848 */
11849 @Override
11850 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11851 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11853
11854 final long identity = Binder.clearCallingIdentity();
11855 try {
11856 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11857 } finally {
11858 Binder.restoreCallingIdentity(identity);
11859 }
11860 }
11861
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011862 /**
11863 * Get the component name of the default app to direct respond-via-message intent for the
11864 * user associated with this subscription, update the cache if there is no respond-via-message
11865 * application currently configured for this user.
11866 * @return component name of the app and class to direct Respond Via Message intent to, or
11867 * {@code null} if the functionality is not supported.
11868 * @hide
11869 */
11870 @Override
11871 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11872 boolean updateIfNeeded) {
11873 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011874
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011875 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11876
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011877 UserHandle userHandle = null;
11878 final long identity = Binder.clearCallingIdentity();
11879 try {
11880 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11881 } finally {
11882 Binder.restoreCallingIdentity(identity);
11883 }
11884 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11885 updateIfNeeded, userHandle);
11886 }
Jack Yuf5badd92022-12-08 00:50:53 -080011887
11888 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011889 * Set whether the device is able to connect with null ciphering or integrity
11890 * algorithms. This is a global setting and will apply to all active subscriptions
11891 * and all new subscriptions after this.
11892 *
11893 * @param enabled when true, null cipher and integrity algorithms are allowed.
11894 * @hide
11895 */
11896 @Override
11897 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11898 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11899 enforceModifyPermission();
11900 checkForNullCipherAndIntegritySupport();
11901
11902 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11903 // for listening to these preference changes and applying them immediately.
11904 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11905 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11906 editor.apply();
11907
11908 for (Phone phone: PhoneFactory.getPhones()) {
11909 phone.handleNullCipherEnabledChange();
11910 }
11911 }
11912
11913
11914 /**
11915 * Get whether the device is able to connect with null ciphering or integrity
11916 * algorithms. Note that this retrieves the phone-global preference and not
11917 * the state of the radio.
11918 *
11919 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11920 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11921 * version for this feature.
11922 * @hide
11923 */
11924 @Override
11925 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11926 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11927 enforceReadPermission();
11928 checkForNullCipherAndIntegritySupport();
11929 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11930 }
11931
11932 private void checkForNullCipherAndIntegritySupport() {
11933 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11934 throw new UnsupportedOperationException(
11935 "Null cipher and integrity operations require HAL 2.1 or above");
11936 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011937 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11938 throw new UnsupportedOperationException(
11939 "Null cipher and integrity operations unsupported by modem");
11940 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011941 }
11942
Gil Cukierman06403e12023-11-29 16:33:03 +000011943 private void checkForIdentifierDisclosureNotificationSupport() {
11944 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
11945 throw new UnsupportedOperationException(
11946 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
11947 + "above");
11948 }
11949 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
11950 throw new UnsupportedOperationException(
11951 "Cellular identifier disclosure transparency operations unsupported by modem");
11952 }
11953 }
11954
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011955 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011956 * Get the SIM state for the slot index.
11957 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11958 *
11959 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11960 */
11961 @Override
11962 @SimState
11963 public int getSimStateForSlotIndex(int slotIndex) {
11964 IccCardConstants.State simState;
11965 if (slotIndex < 0) {
11966 simState = IccCardConstants.State.UNKNOWN;
11967 } else {
11968 Phone phone = null;
11969 try {
11970 phone = PhoneFactory.getPhone(slotIndex);
11971 } catch (IllegalStateException e) {
11972 // ignore
11973 }
11974 if (phone == null) {
11975 simState = IccCardConstants.State.UNKNOWN;
11976 } else {
11977 IccCard icc = phone.getIccCard();
11978 if (icc == null) {
11979 simState = IccCardConstants.State.UNKNOWN;
11980 } else {
11981 simState = icc.getState();
11982 }
11983 }
11984 }
11985 return simState.ordinal();
11986 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011987
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011988 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11989 boolean enableLogcat,
11990 long logcatStartTimestampMillis, boolean enableTelecomDump,
11991 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011992 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11993 TelephonyManager.EmergencyCallDiagnosticParams edp =
11994 new TelephonyManager.EmergencyCallDiagnosticParams();
11995 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11996 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11997 edp.setTelecomDumpSysCollection(enableTelecomDump);
11998 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11999 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12000 Executors.newCachedThreadPool(), db,
12001 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12002 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012003 }
12004
12005 /**
12006 * Request telephony to persist state for debugging emergency call failures.
12007 *
12008 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12009 * @param enableLogcat whether to collect logcat output
12010 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12011 * @param enableTelecomDump whether to collect telecom dumpsys
12012 * @param enableTelephonyDump whether to collect telephony dumpsys
12013 */
12014 @Override
12015 @RequiresPermission(android.Manifest.permission.DUMP)
12016 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12017 long logcatStartTimestampMillis, boolean enableTelecomDump,
12018 boolean enableTelephonyDump) {
12019 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12020 "persistEmergencyCallDiagnosticData");
12021 final long identity = Binder.clearCallingIdentity();
12022 try {
12023 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12024 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12025
12026 } finally {
12027 Binder.restoreCallingIdentity(identity);
12028 }
12029 }
12030
Hui Wang9b5793a2022-12-05 14:38:06 -060012031 /**
12032 * Get current cell broadcast ranges.
12033 */
12034 @Override
12035 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12036 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12037 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12038 "getCellBroadcastIdRanges");
12039 final long identity = Binder.clearCallingIdentity();
12040 try {
12041 return getPhone(subId).getCellBroadcastIdRanges();
12042 } finally {
12043 Binder.restoreCallingIdentity(identity);
12044 }
12045 }
12046
12047 /**
12048 * Set reception of cell broadcast messages with the list of the given ranges
12049 *
12050 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12051 */
12052 @Override
12053 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12054 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12055 @Nullable IIntegerConsumer callback) {
12056 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12057 "setCellBroadcastIdRanges");
12058 final long identity = Binder.clearCallingIdentity();
12059 try {
12060 Phone phone = getPhoneFromSubId(subId);
12061 if (DBG) {
12062 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12063 }
12064 phone.setCellBroadcastIdRanges(ranges, result -> {
12065 if (callback != null) {
12066 try {
12067 callback.accept(result);
12068 } catch (RemoteException e) {
12069 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12070 }
12071 }
12072 });
12073 } finally {
12074 Binder.restoreCallingIdentity(identity);
12075 }
12076 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012077
12078 /**
12079 * Returns whether the device supports the domain selection service.
12080 *
12081 * @return {@code true} if the device supports the domain selection service.
12082 */
12083 @Override
12084 public boolean isDomainSelectionSupported() {
12085 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12086 "isDomainSelectionSupported");
12087
12088 final long identity = Binder.clearCallingIdentity();
12089 try {
12090 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12091 } finally {
12092 Binder.restoreCallingIdentity(identity);
12093 }
12094 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012095
12096 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012097 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12098 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12099 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012100 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012101 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012102 * @param enableSatellite {@code true} to enable the satellite modem and
12103 * {@code false} to disable.
12104 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12105 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012106 *
12107 * @throws SecurityException if the caller doesn't have the required permission.
12108 */
12109 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012110 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12111 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012112 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012113 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12114 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012115 }
12116
12117 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012118 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012119 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012120 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012121 * @param result The result receiver that returns whether the satellite modem is enabled
12122 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012123 *
12124 * @throws SecurityException if the caller doesn't have the required permission.
12125 */
12126 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012127 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12128 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012129 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012130 }
12131
12132 /**
Sarah Chin43457982023-02-15 17:50:38 -080012133 * Request to get whether the satellite service demo mode is enabled.
12134 *
12135 * @param subId The subId of the subscription to check whether the satellite demo mode
12136 * is enabled for.
12137 * @param result The result receiver that returns whether the satellite demo mode is enabled
12138 * if the request is successful or an error code if the request failed.
12139 *
12140 * @throws SecurityException if the caller doesn't have the required permission.
12141 */
12142 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012143 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12144 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12145 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012146 }
12147
12148 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012149 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012150 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012151 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012152 * @param result The result receiver that returns whether the satellite service is supported on
12153 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012154 */
12155 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012156 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012157 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012158 }
12159
12160 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012161 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012162 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012163 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012164 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12165 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012166 *
12167 * @throws SecurityException if the caller doesn't have required permission.
12168 */
12169 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012170 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12171 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012172 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012173 }
12174
12175 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012176 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012177 * This can be called by the pointing UI when the user starts pointing to the satellite.
12178 * Modem should continue to report the pointing input as the device or satellite moves.
12179 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012180 * @param subId The subId of the subscription to start satellite transmission updates for.
12181 * @param resultCallback The callback to get the result of the request.
12182 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012183 *
12184 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012185 */
12186 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012187 public void startSatelliteTransmissionUpdates(int subId,
12188 @NonNull IIntegerConsumer resultCallback,
12189 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12190 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12191 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012192 }
12193
12194 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012195 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012196 * This can be called by the pointing UI when the user stops pointing to the satellite.
12197 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012198 * @param subId The subId of the subscription to stop satellite transmission updates for.
12199 * @param resultCallback The callback to get the result of the request.
12200 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12201 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012202 *
12203 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012204 */
12205 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012206 public void stopSatelliteTransmissionUpdates(int subId,
12207 @NonNull IIntegerConsumer resultCallback,
12208 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12209 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12210 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012211 }
12212
12213 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012214 * Register the subscription with a satellite provider.
12215 * This is needed to register the subscription if the provider allows dynamic registration.
12216 *
12217 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012218 * @param token The token to be used as a unique identifier for provisioning with satellite
12219 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012220 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012221 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012222 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012223 * @return The signal transport used by the caller to cancel the provision request,
12224 * or {@code null} if the request failed.
12225 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012226 * @throws SecurityException if the caller doesn't have the required permission.
12227 */
12228 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012229 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012230 @NonNull String token, @NonNull byte[] provisionData,
12231 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012232 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012233 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12234 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012235 }
12236
12237 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012238 * Unregister the device/subscription with the satellite provider.
12239 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012240 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012241 * should report as deprovisioned.
12242 *
12243 * @param subId The subId of the subscription to be deprovisioned.
12244 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012245 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012246 *
12247 * @throws SecurityException if the caller doesn't have the required permission.
12248 */
12249 @Override
12250 public void deprovisionSatelliteService(int subId,
12251 @NonNull String token, @NonNull IIntegerConsumer callback) {
12252 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012253 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012254 }
12255
12256 /**
Sarah Chin43457982023-02-15 17:50:38 -080012257 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012258 *
Sarah Chin43457982023-02-15 17:50:38 -080012259 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012260 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012261 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012262 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012263 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012264 * @throws SecurityException if the caller doesn't have the required permission.
12265 */
12266 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012267 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12268 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012269 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012270 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012271 }
12272
12273 /**
Sarah Chin43457982023-02-15 17:50:38 -080012274 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012275 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012276 *
Sarah Chin43457982023-02-15 17:50:38 -080012277 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012278 * @param callback The callback that was passed to
12279 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012280 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012281 * @throws SecurityException if the caller doesn't have the required permission.
12282 */
12283 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012284 public void unregisterForSatelliteProvisionStateChanged(
12285 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012286 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012287 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012288 }
12289
12290 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012291 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012292 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012293 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012294 * @param result The result receiver that returns whether the device is provisioned with a
12295 * satellite provider if the request is successful or an error code if the
12296 * request failed.
12297 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012298 * @throws SecurityException if the caller doesn't have the required permission.
12299 */
12300 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012301 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12302 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012303 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012304 }
12305
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012306 /**
Sarah Chin43457982023-02-15 17:50:38 -080012307 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012308 *
Sarah Chin43457982023-02-15 17:50:38 -080012309 * @param subId The subId of the subscription to register for satellite modem state changed.
12310 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012311 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012312 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012313 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012314 * @throws SecurityException if the caller doesn't have the required permission.
12315 */
12316 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012317 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012318 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012319 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012320 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012321 }
12322
12323 /**
Sarah Chin43457982023-02-15 17:50:38 -080012324 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012325 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012326 *
Sarah Chin43457982023-02-15 17:50:38 -080012327 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012328 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012329 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012330 *
12331 * @throws SecurityException if the caller doesn't have the required permission.
12332 */
12333 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012334 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012335 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012336 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012337 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012338 }
12339
12340 /**
12341 * Register to receive incoming datagrams over satellite.
12342 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012343 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012344 * @param callback The callback to handle incoming datagrams over satellite.
12345 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012346 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012347 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012348 * @throws SecurityException if the caller doesn't have the required permission.
12349 */
12350 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012351 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012352 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012353 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012354 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012355 }
12356
12357 /**
12358 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012359 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012360 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012361 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12362 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012363 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012364 *
12365 * @throws SecurityException if the caller doesn't have the required permission.
12366 */
12367 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012368 public void unregisterForSatelliteDatagram(int subId,
12369 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012370 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012371 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012372 }
12373
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012374 /**
12375 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012376 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012377 * This method requests modem to check if there are any pending datagrams to be received over
12378 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012379 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012380 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012381 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012382 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012383 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012384 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012385 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012386 @Override
12387 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012388 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012389 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012390 }
12391
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012392 /**
12393 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012394 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012395 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12396 * input to this method. Datagram received here will be passed down to modem without any
12397 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012398 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012399 * @param subId The subId of the subscription to send satellite datagrams for.
12400 * @param datagramType datagram type indicating whether the datagram is of type
12401 * SOS_SMS or LOCATION_SHARING.
12402 * @param datagram encoded gateway datagram which is encrypted by the caller.
12403 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012404 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12405 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012406 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012407 *
12408 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012409 */
12410 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012411 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12412 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12413 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012414 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012415 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12416 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012417 }
12418
Sarah Chindf715ec2023-02-13 13:46:24 -080012419 /**
12420 * Request to get whether satellite communication is allowed for the current location.
12421 *
12422 * @param subId The subId of the subscription to check whether satellite communication is
12423 * allowed for the current location for.
12424 * @param result The result receiver that returns whether satellite communication is allowed
12425 * for the current location if the request is successful or an error code
12426 * if the request failed.
12427 *
12428 * @throws SecurityException if the caller doesn't have the required permission.
12429 */
12430 @Override
12431 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12432 @NonNull ResultReceiver result) {
12433 enforceSatelliteCommunicationPermission(
12434 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012435 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12436 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012437 }
12438
12439 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012440 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012441 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012442 * @param subId The subId to get the time after which the satellite will be visible for.
12443 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012444 * be visible if the request is successful or an error code if the request failed.
12445 *
12446 * @throws SecurityException if the caller doesn't have the required permission.
12447 */
12448 @Override
12449 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12450 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012451 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012452 }
12453
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012454 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012455 * Inform that Device is aligned to satellite for demo mode.
12456 *
12457 * @param subId The subId to get the time after which the satellite will be visible for.
12458 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12459 * {@code false} Device fails to align with the satellite for demo mode.
12460 *
12461 * @throws SecurityException if the caller doesn't have required permission.
12462 */
12463 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12464
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012465 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012466 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012467 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012468 }
12469
12470 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012471 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12472 * by modem.
12473 *
12474 * @param subId The subId of the subscription to request for.
12475 * @param reason Reason for disallowing satellite communication for carrier.
12476 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12477 * operation.
12478 *
12479 * @throws SecurityException if the caller doesn't have required permission.
12480 */
12481 public void addSatelliteAttachRestrictionForCarrier(int subId,
12482 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12483 @NonNull IIntegerConsumer callback) {
12484 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12485 final long identity = Binder.clearCallingIdentity();
12486 try {
12487 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12488 } finally {
12489 Binder.restoreCallingIdentity(identity);
12490 }
12491 }
12492
12493 /**
12494 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12495 * by modem.
12496 *
12497 * @param subId The subId of the subscription to request for.
12498 * @param reason Reason for disallowing satellite communication.
12499 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12500 * operation.
12501 *
12502 * @throws SecurityException if the caller doesn't have required permission.
12503 */
12504 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12505 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12506 @NonNull IIntegerConsumer callback) {
12507 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12508 final long identity = Binder.clearCallingIdentity();
12509 try {
12510 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12511 callback);
12512 } finally {
12513 Binder.restoreCallingIdentity(identity);
12514 }
12515 }
12516
12517 /**
12518 * Get reasons for disallowing satellite communication, as requested by
12519 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12520 *
12521 * @param subId The subId of the subscription to request for.
12522 *
12523 * @return Integer array of reasons for disallowing satellite communication.
12524 *
12525 * @throws SecurityException if the caller doesn't have the required permission.
12526 */
12527 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12528 int subId) {
12529 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12530 final long identity = Binder.clearCallingIdentity();
12531 try {
12532 Set<Integer> reasonSet =
12533 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12534 return reasonSet.stream().mapToInt(i->i).toArray();
12535 } finally {
12536 Binder.restoreCallingIdentity(identity);
12537 }
12538 }
12539
12540 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012541 * Request to get the signal strength of the satellite connection.
12542 *
12543 * @param subId The subId of the subscription to request for.
12544 * @param result Result receiver to get the error code of the request and the current signal
12545 * strength of the satellite connection.
12546 *
12547 * @throws SecurityException if the caller doesn't have required permission.
12548 */
12549 @Override
12550 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12551 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12552 final long identity = Binder.clearCallingIdentity();
12553 try {
12554 mSatelliteController.requestNtnSignalStrength(subId, result);
12555 } finally {
12556 Binder.restoreCallingIdentity(identity);
12557 }
12558 }
12559
12560 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012561 * Registers for NTN signal strength changed from satellite modem. If the registration operation
12562 * is not successful, a {@link ServiceSpecificException} that contains
12563 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012564 *
12565 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012566 * @param callback The callback to handle the NTN signal strength changed event. If the
12567 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
12568 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
12569 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
12570 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012571 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012572 * @throws SecurityException If the caller doesn't have the required permission.
12573 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012574 */
12575 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012576 public void registerForNtnSignalStrengthChanged(int subId,
12577 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000012578 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12579 final long identity = Binder.clearCallingIdentity();
12580 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012581 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000012582 } finally {
12583 Binder.restoreCallingIdentity(identity);
12584 }
12585 }
12586
12587 /**
12588 * Unregisters for NTN signal strength changed from satellite modem.
12589 * If callback was not registered before, the request will be ignored.
12590 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000012591 * @param subId The subId of the subscription to unregister for listening NTN signal strength
12592 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012593 * @param callback The callback that was passed to
12594 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12595 *
12596 * @throws SecurityException if the caller doesn't have the required permission.
12597 */
12598 @Override
12599 public void unregisterForNtnSignalStrengthChanged(
12600 int subId, @NonNull INtnSignalStrengthCallback callback) {
12601 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12602 final long identity = Binder.clearCallingIdentity();
12603 try {
12604 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12605 } finally {
12606 Binder.restoreCallingIdentity(identity);
12607 }
12608 }
12609
12610 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000012611 * Registers for satellite capabilities change event from the satellite service.
12612 *
12613 * @param subId The subId of the subscription to request for.
12614 * @param callback The callback to handle the satellite capabilities changed event.
12615 *
12616 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12617 *
12618 * @throws SecurityException if the caller doesn't have required permission.
12619 */
12620 @Override
12621 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
12622 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12623 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
12624 final long identity = Binder.clearCallingIdentity();
12625 try {
12626 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
12627 } finally {
12628 Binder.restoreCallingIdentity(identity);
12629 }
12630 }
12631
12632 /**
12633 * Unregisters for satellite capabilities change event from the satellite service.
12634 * If callback was not registered before, the request will be ignored.
12635 *
12636 * @param subId The subId of the subscription to unregister for satellite capabilities change.
12637 * @param callback The callback that was passed to.
12638 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
12639 *
12640 * @throws SecurityException if the caller doesn't have required permission.
12641 */
12642 @Override
12643 public void unregisterForSatelliteCapabilitiesChanged(
12644 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12645 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
12646 final long identity = Binder.clearCallingIdentity();
12647 try {
12648 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
12649 } finally {
12650 Binder.restoreCallingIdentity(identity);
12651 }
12652 }
12653
12654 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012655 * This API can be used by only CTS to update satellite vendor service package name.
12656 *
12657 * @param servicePackageName The package name of the satellite vendor service.
12658 * @return {@code true} if the satellite vendor service is set successfully,
12659 * {@code false} otherwise.
12660 */
12661 public boolean setSatelliteServicePackageName(String servicePackageName) {
12662 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12663 TelephonyPermissions.enforceShellOnly(
12664 Binder.getCallingUid(), "setSatelliteServicePackageName");
12665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12666 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12667 "setSatelliteServicePackageName");
12668 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12669 }
12670
12671 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012672 * This API can be used by only CTS to update satellite gateway service package name.
12673 *
12674 * @param servicePackageName The package name of the satellite gateway service.
12675 * @return {@code true} if the satellite gateway service is set successfully,
12676 * {@code false} otherwise.
12677 */
12678 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12679 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12680 TelephonyPermissions.enforceShellOnly(
12681 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12683 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12684 "setSatelliteGatewayServicePackageName");
12685 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12686 }
12687
12688 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012689 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12690 *
12691 * @param packageName The package name of the satellite pointing UI app.
12692 * @param className The class name of the satellite pointing UI app.
12693 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12694 * {@code false} otherwise.
12695 */
12696 public boolean setSatellitePointingUiClassName(
12697 @Nullable String packageName, @Nullable String className) {
12698 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12699 + ", className=" + className);
12700 TelephonyPermissions.enforceShellOnly(
12701 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12703 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12704 "setSatelliteGatewayServicePackageName");
12705 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12706 }
12707
12708 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012709 * This API can be used by only CTS to update the timeout duration in milliseconds that
12710 * satellite should stay at listening mode to wait for the next incoming page before disabling
12711 * listening mode.
12712 *
12713 * @param timeoutMillis The timeout duration in millisecond.
12714 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12715 */
12716 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12717 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12718 TelephonyPermissions.enforceShellOnly(
12719 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12721 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12722 "setSatelliteListeningTimeoutDuration");
12723 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12724 }
12725
12726 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012727 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12728 * the device is aligned with the satellite for demo mode
12729 *
12730 * @param timeoutMillis The timeout duration in millisecond.
12731 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12732 */
12733 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12734 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12735 TelephonyPermissions.enforceShellOnly(
12736 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12738 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12739 "setDeviceAlignedTimeoutDuration");
12740 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12741 }
12742
12743 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070012744 * This API can be used in only testing to override connectivity status in monitoring emergency
12745 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
12746 *
12747 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
12748 * of the following values to enable the override:
12749 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
12750 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
12751 * To disable the override, use -1 for handoverType.
12752 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
12753 * delaySeconds after the emergency call starts.
12754 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
12755 */
12756 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
12757 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
12758 TelephonyPermissions.enforceShellOnly(
12759 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
12760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12761 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12762 "setEmergencyCallToSatelliteHandoverType");
12763 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
12764 handoverType, delaySeconds);
12765 }
12766
12767 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000012768 * This API can be used by only CTS to override the cached value for the device overlay config
12769 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
12770 * outgoing satellite datagrams should be sent to modem in demo mode.
12771 *
12772 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
12773 * satellite modem or not.
12774 *
12775 * @return {@code true} if the operation is successful, {@code false} otherwise.
12776 */
12777 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
12778 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
12779 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
12780 + "disabled");
12781 return false;
12782 }
12783 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
12784 TelephonyPermissions.enforceShellOnly(
12785 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
12786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12787 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12788 "setShouldSendDatagramToModemInDemoMode");
12789 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
12790 shouldSendToModemInDemoMode);
12791 }
12792
12793 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000012794 * Enable or disable notifications sent for cellular identifier disclosure events.
12795 *
12796 * Disclosure events are defined as instances where a device has sent a cellular identifier
12797 * on the Non-access stratum (NAS) before a security context is established. As a result the
12798 * identifier is sent in the clear, which has privacy implications for the user.
12799 *
12800 * @param enable if notifications about disclosure events should be enabled
12801 * @throws SecurityException if the caller does not have the required privileges
12802 * @throws UnsupportedOperationException if the modem does not support this feature.
12803 */
12804 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000012805 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000012806 enforceModifyPermission();
12807 checkForIdentifierDisclosureNotificationSupport();
12808
12809 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12810 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
12811 editor.apply();
12812
12813 // Each phone instance is responsible for updating its respective modem immediately
12814 // after we've made a preference change.
12815 for (Phone phone : PhoneFactory.getPhones()) {
12816 phone.handleIdentifierDisclosureNotificationPreferenceChange();
12817 }
12818 }
12819
12820 /**
12821 * Get whether or not cellular identifier disclosure notifications are enabled.
12822 *
12823 * @throws SecurityException if the caller does not have the required privileges
12824 * @throws UnsupportedOperationException if the modem does not support this feature.
12825 */
12826 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000012827 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000012828 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
12829 checkForIdentifierDisclosureNotificationSupport();
12830 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
12831 }
12832
12833 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012834 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12835 *
12836 * <p>This method behaves in one of the following ways:
12837 * <ul>
12838 * <li>return true : if the calling package has the appop permission {@link
12839 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12840 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12841 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12842 * Owner device identifier access check, or the calling package has carrier privileges</>
12843 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12844 * </ul>
12845 */
12846 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12847 String callingPackage, @Nullable String callingFeatureId, String message) {
12848 for (Phone phone : PhoneFactory.getPhones()) {
12849 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12850 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12851 return true;
12852 }
12853 }
12854 return false;
12855 }
arunvoddud7401012022-12-15 16:08:12 +000012856
12857 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012858 * @return The subscription manager service instance.
12859 */
12860 public SubscriptionManagerService getSubscriptionManagerService() {
12861 return SubscriptionManagerService.getInstance();
12862 }
12863
12864 /**
arunvoddud7401012022-12-15 16:08:12 +000012865 * Class binds the consumer[callback] and carrierId.
12866 */
12867 private static class CallerCallbackInfo {
12868 private final Consumer<Integer> mConsumer;
12869 private final int mCarrierId;
12870
12871 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12872 mConsumer = consumer;
12873 mCarrierId = carrierId;
12874 }
12875
12876 public Consumer<Integer> getConsumer() {
12877 return mConsumer;
12878 }
12879
12880 public int getCarrierId() {
12881 return mCarrierId;
12882 }
12883 }
Jack Yufa8ed012023-02-11 15:42:28 -080012884}