blob: 8f3281c82311d68f2424a179eb49e7732546ebb2 [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 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004394 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4395 * @param subId The subscription to use to check the configuration.
4396 * @param c The callback that will be used to send the result.
4397 */
4398 @Override
4399 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4400 throws RemoteException {
4401 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4402 mApp, subId, "registerImsEmergencyRegistrationCallback");
4403
4404 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4405 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4406 "IMS not available on device.");
4407 }
4408 final long token = Binder.clearCallingIdentity();
4409 try {
4410 int slotId = getSlotIndexOrException(subId);
4411 verifyImsMmTelConfiguredOrThrow(slotId);
4412
4413 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4414 if (controller != null) {
4415 ImsManager imsManager = controller.getImsManager(subId);
4416 if (imsManager != null) {
4417 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4418 } else {
4419 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4420 }
4421 } else {
4422 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4423 }
4424 } catch (ImsException e) {
4425 throw new ServiceSpecificException(e.getCode());
4426 } finally {
4427 Binder.restoreCallingIdentity(token);
4428 }
4429 }
4430
4431 /**
4432 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4433 * @param subId The subscription to use to check the configuration.
4434 * @param c The callback that will be used to send the result.
4435 */
4436 @Override
4437 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4438 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4439 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4440 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4441 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4442 }
4443 final long token = Binder.clearCallingIdentity();
4444
4445 try {
4446 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4447 if (controller != null) {
4448 ImsManager imsManager = controller.getImsManager(subId);
4449 if (imsManager != null) {
4450 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4451 } else {
4452 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4453 + "is inactive, ignoring unregister.");
4454 // If the ImsManager is not valid, just return, since the callback
4455 // will already have been removed internally.
4456 }
4457 }
4458 } finally {
4459 Binder.restoreCallingIdentity(token);
4460 }
4461 }
4462
4463 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004464 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4465 */
4466 @Override
4467 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4468 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4469 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4470 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4471 "IMS not available on device.");
4472 }
4473 final long token = Binder.clearCallingIdentity();
4474 try {
4475 Phone phone = getPhone(subId);
4476 if (phone == null) {
4477 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4478 + subId + "'");
4479 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4480 }
4481 phone.getImsRegistrationState(regState -> {
4482 try {
4483 consumer.accept((regState == null)
4484 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4485 } catch (RemoteException e) {
4486 // Ignore if the remote process is no longer available to call back.
4487 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4488 }
4489 });
4490 } finally {
4491 Binder.restoreCallingIdentity(token);
4492 }
4493 }
4494
4495 /**
4496 * Get the transport type for the IMS service registration state.
4497 */
4498 @Override
4499 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004501 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004502 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4503 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4504 "IMS not available on device.");
4505 }
4506 final long token = Binder.clearCallingIdentity();
4507 try {
4508 Phone phone = getPhone(subId);
4509 if (phone == null) {
4510 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4511 + subId + "'");
4512 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4513 }
4514 phone.getImsRegistrationTech(regTech -> {
4515 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4516 int regTechConverted = (regTech == null)
4517 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4518 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4519 regTechConverted);
4520 try {
4521 consumer.accept(regTechConverted);
4522 } catch (RemoteException e) {
4523 // Ignore if the remote process is no longer available to call back.
4524 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4525 }
4526 });
4527 } finally {
4528 Binder.restoreCallingIdentity(token);
4529 }
4530 }
4531
shilu366312e2019-12-17 09:28:10 -08004532 /**
4533 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4534 * @param subId The subscription to use to check the configuration.
4535 * @param c The callback that will be used to send the result.
4536 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004538 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4539 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004540 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004541 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004542 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4543 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4544 "IMS not available on device.");
4545 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 final long token = Binder.clearCallingIdentity();
4547 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004548 int slotId = getSlotIndexOrException(subId);
4549 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004550
4551 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4552 if (controller != null) {
4553 ImsManager imsManager = controller.getImsManager(subId);
4554 if (imsManager != null) {
4555 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4556 } else {
4557 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4558 }
4559 } else {
4560 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4561 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004562 } catch (ImsException e) {
4563 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004564 } finally {
4565 Binder.restoreCallingIdentity(token);
4566 }
4567 }
4568
shilu366312e2019-12-17 09:28:10 -08004569 /**
4570 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4571 * @param subId The subscription to use to check the configuration.
4572 * @param c The callback that will be used to send the result.
4573 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004574 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004575 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004576 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004577 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004578 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4579 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4580 }
Meng Wangafbc5852019-09-19 17:37:13 -07004581
4582 final long token = Binder.clearCallingIdentity();
4583 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004584 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4585 if (controller != null) {
4586 ImsManager imsManager = controller.getImsManager(subId);
4587 if (imsManager != null) {
4588 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4589 } else {
4590 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4591 + " is inactive, ignoring unregister.");
4592 // If the ImsManager is not valid, just return, since the callback
4593 // will already have been removed internally.
4594 }
4595 }
Meng Wangafbc5852019-09-19 17:37:13 -07004596 } finally {
4597 Binder.restoreCallingIdentity(token);
4598 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 }
4600
4601 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004602 public boolean isCapable(int subId, int capability, int regTech) {
4603 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004604 final long token = Binder.clearCallingIdentity();
4605 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004606 int slotId = getSlotIndexOrException(subId);
4607 verifyImsMmTelConfiguredOrThrow(slotId);
4608 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4609 } catch (com.android.ims.ImsException e) {
4610 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4611 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004612 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004613 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4614 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 } finally {
4616 Binder.restoreCallingIdentity(token);
4617 }
4618 }
4619
4620 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004621 public boolean isAvailable(int subId, int capability, int regTech) {
4622 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 final long token = Binder.clearCallingIdentity();
4624 try {
4625 Phone phone = getPhone(subId);
4626 if (phone == null) return false;
4627 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004628 } catch (com.android.ims.ImsException e) {
4629 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4630 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004631 } finally {
4632 Binder.restoreCallingIdentity(token);
4633 }
4634 }
4635
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004636 /**
4637 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4638 * subscription.
4639 * @param subId The subscription to use to check the configuration.
4640 * @param callback The callback that will be used to send the result.
4641 * @param capability The MmTelFeature capability that will be used to send the result.
4642 * @param transportType The transport type of the MmTelFeature capability.
4643 */
4644 @Override
4645 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4646 int transportType) {
4647 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004648 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4650 "IMS not available on device.");
4651 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004652 final long token = Binder.clearCallingIdentity();
4653 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004654 int slotId = getSlotIndex(subId);
4655 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4656 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4657 + subId + "'");
4658 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4659 }
4660 verifyImsMmTelConfiguredOrThrow(slotId);
4661 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4662 transportType, aBoolean -> {
4663 try {
4664 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4665 } catch (RemoteException e) {
4666 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4667 + "running. Ignore");
4668 }
4669 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 } catch (ImsException e) {
4671 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004672 } finally {
4673 Binder.restoreCallingIdentity(token);
4674 }
4675 }
4676
shilu366312e2019-12-17 09:28:10 -08004677 /**
4678 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4679 * @param subId The subscription to use to check the configuration.
4680 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004681 @Override
4682 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004683 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004684 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004685
Brad Ebinger35c841c2018-10-01 10:40:55 -07004686 final long token = Binder.clearCallingIdentity();
4687 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004689 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004691 } catch (ImsException e) {
4692 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004693 } finally {
4694 Binder.restoreCallingIdentity(token);
4695 }
4696 }
4697
4698 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004699 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004701 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004702 final long identity = Binder.clearCallingIdentity();
4703 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004704 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004705 // This setting doesn't require an active ImsService connection, so do not verify. The
4706 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004707 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004708 } catch (ImsException e) {
4709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
4713 }
4714
shilu366312e2019-12-17 09:28:10 -08004715 /**
4716 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4717 * @param subId The subscription to use to check the configuration.
4718 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004720 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004721 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004722 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004723 final long identity = Binder.clearCallingIdentity();
4724 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004725 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004726 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004727 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004728 } catch (ImsException e) {
4729 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
4733 }
4734
4735 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004736 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004738 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 final long identity = Binder.clearCallingIdentity();
4740 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004741 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004742 // This setting doesn't require an active ImsService connection, so do not verify. The
4743 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004744 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004745 } catch (ImsException e) {
4746 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
4750 }
4751
shilu366312e2019-12-17 09:28:10 -08004752 /**
4753 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4754 * @param subId The subscription to use to check the configuration.
4755 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004756 @Override
4757 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004758 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004759 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 final long identity = Binder.clearCallingIdentity();
4761 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004762 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004763 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004764 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004765 } catch (ImsException e) {
4766 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 } finally {
4768 Binder.restoreCallingIdentity(identity);
4769 }
4770 }
4771
4772 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004773 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004775 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 final long identity = Binder.clearCallingIdentity();
4777 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004778 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004779 // This setting doesn't require an active ImsService connection, so do not verify. The
4780 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004781 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004782 } catch (ImsException e) {
4783 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
4787 }
4788
shilu366312e2019-12-17 09:28:10 -08004789 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004790 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4791 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4792 * @param subId The subscription to use to check the configuration.
4793 */
4794 @Override
4795 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004796 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004797 mApp, subId, "isCrossSimCallingEnabledByUser");
4798 final long identity = Binder.clearCallingIdentity();
4799 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004800 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004801 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004802 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004803 } catch (ImsException e) {
4804 throw new ServiceSpecificException(e.getCode());
4805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
4808 }
4809
4810 /**
4811 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4812 * Requires MODIFY_PHONE_STATE permission.
4813 * @param subId The subscription to use to check the configuration.
4814 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4815 * false otherwise
4816 */
4817 @Override
4818 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4820 "setCrossSimCallingEnabled");
4821 final long identity = Binder.clearCallingIdentity();
4822 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004823 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004824 // This setting doesn't require an active ImsService connection, so do not verify. The
4825 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004826 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004827 } catch (ImsException e) {
4828 throw new ServiceSpecificException(e.getCode());
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
4832 }
4833
4834 /**
shilu366312e2019-12-17 09:28:10 -08004835 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4836 * @param subId The subscription to use to check the configuration.
4837 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004839
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004841 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004842 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004843 final long identity = Binder.clearCallingIdentity();
4844 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004845 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004846 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004847 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
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
Brad Ebinger1c162042019-02-21 14:49:10 -08004856 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004858 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004859 final long identity = Binder.clearCallingIdentity();
4860 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004861 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004862 // This setting doesn't require an active ImsService connection, so do not verify. The
4863 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004864 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004865 } catch (ImsException e) {
4866 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
4870 }
4871
4872 @Override
4873 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4875 "setVoWiFiNonPersistent");
4876 final long identity = Binder.clearCallingIdentity();
4877 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004878 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004879 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004880 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004881 } catch (ImsException e) {
4882 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
4886 }
4887
shilu366312e2019-12-17 09:28:10 -08004888 /**
4889 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4890 * @param subId The subscription to use to check the configuration.
4891 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004892 @Override
4893 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004894 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004895 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004896 final long identity = Binder.clearCallingIdentity();
4897 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004898 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004899 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004900 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004901 } catch (ImsException e) {
4902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907
4908 @Override
4909 public void setVoWiFiModeSetting(int subId, int mode) {
4910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4911 "setVoWiFiModeSetting");
4912 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. The
4916 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004917 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004918 } catch (ImsException e) {
4919 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
4925 @Override
4926 public int getVoWiFiRoamingModeSetting(int subId) {
4927 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4928 final long identity = Binder.clearCallingIdentity();
4929 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004930 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004931 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004932 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004933 } catch (ImsException e) {
4934 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
4938 }
4939
4940 @Override
4941 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4943 "setVoWiFiRoamingModeSetting");
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004946 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004947 // This setting doesn't require an active ImsService connection, so do not verify. The
4948 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004949 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004950 } catch (ImsException e) {
4951 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
4955 }
4956
4957 @Override
4958 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4960 "setRttCapabilityEnabled");
4961 final long identity = Binder.clearCallingIdentity();
4962 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004964 // This setting doesn't require an active ImsService connection, so do not verify. The
4965 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004966 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004967 } catch (ImsException e) {
4968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
4972 }
4973
shilu366312e2019-12-17 09:28:10 -08004974 /**
4975 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4976 * @param subId The subscription to use to check the configuration.
4977 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004978 @Override
4979 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004980 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004981 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 final long identity = Binder.clearCallingIdentity();
4983 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004985 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004986 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004987 } catch (ImsException e) {
4988 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
4992 }
4993
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004994 @Override
4995 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4996 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004997
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004998 final long identity = Binder.clearCallingIdentity();
4999 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005000 if (!isImsAvailableOnDevice()) {
5001 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5002 "IMS not available on device.");
5003 }
5004 int slotId = getSlotIndexOrException(subId);
5005 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005006
5007 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5008 if (controller != null) {
5009 ImsManager imsManager = controller.getImsManager(subId);
5010 if (imsManager != null) {
5011 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5012 } else {
5013 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5014 }
5015 } else {
5016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5017 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005018 } catch (ImsException e) {
5019 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
5023 }
5024
5025 @Override
5026 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5027 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005028
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005029 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005030 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5031 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5032 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005033 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005034 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5035 if (controller != null) {
5036 ImsManager imsManager = controller.getImsManager(subId);
5037 if (imsManager != null) {
5038 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5039 } else {
5040 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5041 + " is inactive, ignoring unregister.");
5042 // If the ImsManager is not valid, just return, since the callback will already
5043 // have been removed internally.
5044 }
5045 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
5049 }
5050
joonhunshincffb7fc2021-11-28 07:32:01 +00005051 @Override
5052 public void registerFeatureProvisioningChangedCallback(int subId,
5053 IFeatureProvisioningCallback callback) {
5054 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5055 mApp, subId, "registerFeatureProvisioningChangedCallback");
5056
5057 final long identity = Binder.clearCallingIdentity();
5058 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5059 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5060 }
5061
joonhunshin91bc1952022-04-29 08:47:15 +00005062 try {
5063 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5064 if (controller == null) {
5065 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5066 "Device does not support IMS");
5067 }
5068 controller.addFeatureProvisioningChangedCallback(subId, callback);
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005072 }
5073
5074 @Override
5075 public void unregisterFeatureProvisioningChangedCallback(int subId,
5076 IFeatureProvisioningCallback callback) {
5077 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5078 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5079
5080 final long identity = Binder.clearCallingIdentity();
5081 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5082 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5083 }
5084
joonhunshin91bc1952022-04-29 08:47:15 +00005085 try {
5086 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5087 if (controller == null) {
5088 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5089 return;
5090 }
5091 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005095 }
allenwtsu99c623b2020-01-03 18:24:23 +08005096
5097 private void checkModifyPhoneStatePermission(int subId, String message) {
5098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5099 message);
5100 }
5101
allenwtsu99c623b2020-01-03 18:24:23 +08005102 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005103 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005104 boolean isProvisioned) {
5105 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5106
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005109 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5110 if (controller == null) {
5111 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5112 return;
5113 }
5114 controller.setRcsProvisioningStatusForCapability(
5115 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
allenwtsu99c623b2020-01-03 18:24:23 +08005119 }
5120
5121
5122 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005123 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5124 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5125 mApp, subId, "getRcsProvisioningStatusForCapability");
5126
allenwtsu99c623b2020-01-03 18:24:23 +08005127 final long identity = Binder.clearCallingIdentity();
5128 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005129 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5130 if (controller == null) {
5131 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5132
5133 // device does not support IMS, this method will return true always.
5134 return true;
5135 }
5136 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005137 } finally {
5138 Binder.restoreCallingIdentity(identity);
5139 }
5140 }
5141
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005142 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005143 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5144 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005145 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005146
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005149 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5150 if (controller == null) {
5151 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5152 return;
5153 }
5154 controller.setImsProvisioningStatusForCapability(
5155 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
5159 }
5160
5161 @Override
5162 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005163 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5164 mApp, subId, "getProvisioningStatusForCapability");
5165
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005166 final long identity = Binder.clearCallingIdentity();
5167 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005168 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5169 if (controller == null) {
5170 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005171
joonhunshin91bc1952022-04-29 08:47:15 +00005172 // device does not support IMS, this method will return true always.
5173 return true;
5174 }
5175 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005182 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5183 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5184 mApp, subId, "isProvisioningRequiredForCapability");
5185
5186 final long identity = Binder.clearCallingIdentity();
5187 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005188 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5189 if (controller == null) {
5190 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5191
5192 // device does not support IMS, this method will return false
5193 return false;
5194 }
5195 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005196 } finally {
5197 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005198 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005199 }
5200
5201 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005202 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5203 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5204 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005205
joonhunshincffb7fc2021-11-28 07:32:01 +00005206 final long identity = Binder.clearCallingIdentity();
5207 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005208 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5209 if (controller == null) {
5210 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5211
5212 // device does not support IMS, this method will return false
5213 return false;
5214 }
5215 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005219 }
5220
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005221 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005222 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005223 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5224 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5225 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005226 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5227 mApp, subId, "getImsProvisioningInt");
5228
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005232 int slotId = getSlotIndex(subId);
5233 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5234 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5235 + subId + "' for key:" + key);
5236 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5237 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005238
joonhunshin91bc1952022-04-29 08:47:15 +00005239 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5240 if (controller == null) {
5241 loge("getImsProvisioningInt: Device does not support IMS");
5242
5243 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5244 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5245 }
5246 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005247 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5248 return retVal;
5249 }
5250
calvinpanb5a34062021-02-08 19:59:36 +08005251 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005252 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005253 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5254 + subId + "' for key:" + key);
5255 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
5259 }
5260
5261 @Override
5262 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005263 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5264 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5265 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005266 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5267 mApp, subId, "getImsProvisioningString");
5268
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005272 int slotId = getSlotIndex(subId);
5273 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5274 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5275 + subId + "' for key:" + key);
5276 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5277 }
calvinpanb5a34062021-02-08 19:59:36 +08005278 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005279 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005280 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5281 + subId + "' for key:" + key);
5282 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
5288 @Override
5289 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005290 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5291 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5292 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5294 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005295
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005299 int slotId = getSlotIndex(subId);
5300 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5301 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5302 + subId + "' for key:" + key);
5303 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5304 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005305
joonhunshin91bc1952022-04-29 08:47:15 +00005306 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5307 if (controller == null) {
5308 loge("setImsProvisioningInt: Device does not support IMS");
5309
5310 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5311 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5312 }
5313 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005314 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5315 return retVal;
5316 }
5317
calvinpanb5a34062021-02-08 19:59:36 +08005318 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5319 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005320 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005321 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005322 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
5327
5328 @Override
5329 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005330 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5331 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5332 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5334 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005335 final long identity = Binder.clearCallingIdentity();
5336 try {
5337 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005338 int slotId = getSlotIndex(subId);
5339 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5340 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5341 + subId + "' for key:" + key);
5342 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5343 }
calvinpanb5a34062021-02-08 19:59:36 +08005344 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5345 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005346 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005347 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005348 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
5352 }
5353
Brad Ebinger919631e2021-06-02 17:46:35 -07005354 /**
5355 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5356 * for the given slot ID or no ImsResolver instance has been created.
5357 * @param slotId The slot ID that the IMS service is created for.
5358 * @throws ImsException If there is no ImsService configured for this slot.
5359 */
5360 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5361 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5362 ImsFeature.FEATURE_MMTEL)) {
5363 throw new ImsException("This subscription does not support MMTEL over IMS",
5364 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5365 }
5366 }
5367
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005368 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005369 int slotId = SubscriptionManager.getSlotIndex(subId);
5370 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005371 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5372 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005373 }
5374 return slotId;
5375 }
5376
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005377 private int getSlotIndex(int subId) {
5378 int slotId = SubscriptionManager.getSlotIndex(subId);
5379 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5380 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5381 }
5382 return slotId;
5383 }
5384
Wink Saville36469e72014-06-11 15:17:00 -07005385 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005386 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005387 */
5388 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005389 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5390 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005391 try {
5392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5393 } catch (SecurityException se) {
5394 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5395 throw new SecurityException("Package " + callingPackage + " does not belong to "
5396 + Binder.getCallingUid());
5397 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005398 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005399 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005400 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005401 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005402 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005403 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005404 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005405 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5406 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 final Phone phone = getPhone(subId);
5411 if (phone != null) {
5412 return phone.getServiceState().getDataNetworkType();
5413 } else {
5414 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5415 }
5416 } finally {
5417 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005419 }
5420
5421 /**
5422 * Returns the data network type
5423 */
5424 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005425 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005426 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005427 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005428 }
5429
5430 /**
5431 * Returns the data network type for a subId
5432 */
5433 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005434 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5435 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005436 String functionName = "getDataNetworkTypeForSubscriber";
5437 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5438 mApp, functionName)) {
5439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5440 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5441 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5442 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005443 }
5444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
5447 final Phone phone = getPhone(subId);
5448 if (phone != null) {
5449 return phone.getServiceState().getDataNetworkType();
5450 } else {
5451 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5452 }
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005456 }
5457
5458 /**
Wink Saville36469e72014-06-11 15:17:00 -07005459 * Returns the Voice network type for a subId
5460 */
5461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005462 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5463 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005464 String functionName = "getVoiceNetworkTypeForSubscriber";
5465 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5466 mApp, functionName)) {
5467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5468 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5469 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5470 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005471 }
5472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 final long identity = Binder.clearCallingIdentity();
5474 try {
5475 final Phone phone = getPhone(subId);
5476 if (phone != null) {
5477 return phone.getServiceState().getVoiceNetworkType();
5478 } else {
5479 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5480 }
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005484 }
5485
5486 /**
5487 * @return true if a ICC card is present
5488 */
5489 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005490 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005491 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005492 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005493 }
5494
5495 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005496 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005497 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005498 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005499 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 final Phone phone = PhoneFactory.getPhone(slotIndex);
5503 if (phone != null) {
5504 return phone.getIccCard().hasIccCard();
5505 } else {
5506 return false;
5507 }
5508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005511 }
5512
5513 /**
5514 * Return if the current radio is LTE on CDMA. This
5515 * is a tri-state return value as for a period of time
5516 * the mode may be unknown.
5517 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005518 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005519 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005520 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005523 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5524 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5525 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005526 }
5527
Sanket Padawe356d7632015-06-22 14:03:32 -07005528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005529 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5530 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005531 try {
5532 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5533 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005534 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5535 }
5536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 final Phone phone = getPhone(subId);
5540 if (phone == null) {
5541 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5542 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005543 return TelephonyProperties.lte_on_cdma_device()
5544 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 }
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005548 }
Wink Saville36469e72014-06-11 15:17:00 -07005549 }
5550
Wink Saville36469e72014-06-11 15:17:00 -07005551 /**
5552 * {@hide}
5553 * Returns Default subId, 0 in the case of single standby.
5554 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005555 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005556 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005557 }
5558
Shishir Agrawala9f32182016-04-12 12:00:16 -07005559 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005560 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005561 }
5562
Wink Savilleb564aae2014-10-23 10:18:09 -07005563 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005564 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005565 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005566
Pengquan Menge92a50d2018-09-21 15:54:48 -07005567 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005568 return getSubscriptionManagerService().isActiveSubId(subId,
5569 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005570 }
5571
Ihab Awadf2177b72013-11-25 13:33:23 -08005572 /**
5573 * @see android.telephony.TelephonyManager.WifiCallingChoices
5574 */
5575 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 final long identity = Binder.clearCallingIdentity();
5577 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005578 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5580 getWhenToMakeWifiCallsDefaultPreference());
5581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005584 }
5585
5586 /**
5587 * @see android.telephony.TelephonyManager.WifiCallingChoices
5588 */
5589 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 final long identity = Binder.clearCallingIdentity();
5591 try {
5592 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005593 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005598 }
5599
Sailesh Nepald1e68152013-12-12 19:08:02 -08005600 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005601 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005602 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005603 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005604
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005605 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5606 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5607 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005608 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005609 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005610 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005611 }
5612 return PhoneFactory.getPhone(phoneId);
5613 }
5614
Shishir Agrawal566b7612013-10-28 14:41:00 -07005615 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005616 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005617 @NonNull IccLogicalChannelRequest request) {
5618 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5619 /*message=*/ "iccOpenLogicalChannel");
5620
5621 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5622 // Verify that the callingPackage in the request belongs to the calling UID
5623 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5624
5625 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005626 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005627
Rambo Wanga1782702021-11-10 20:15:19 -08005628 private Phone getPhoneFromValidIccLogicalChannelRequest(
5629 @NonNull IccLogicalChannelRequest request, String message) {
5630 Phone phone;
5631 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5633 mApp, request.subId, message);
5634 phone = getPhoneFromSubId(request.subId);
5635 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5636 enforceModifyPermission();
5637 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5638 } else {
5639 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005640 }
Rambo Wanga1782702021-11-10 20:15:19 -08005641 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005642 }
5643
5644 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005645 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 final long identity = Binder.clearCallingIdentity();
5647 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005648 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005650 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5651 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005652 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5653 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 loge("The calling package is not allowed to access ISD-R.");
5655 throw new SecurityException(
5656 "The calling package is not allowed to access ISD-R.");
5657 }
Derek Tan740e1672017-06-27 14:56:27 -07005658 }
Derek Tan740e1672017-06-27 14:56:27 -07005659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005661 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5662 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 return response;
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005667 }
5668
5669 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005670 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5671 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5672 /*message=*/"iccCloseLogicalChannel");
5673
5674 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5675
5676 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005678
Rambo Wanga1782702021-11-10 20:15:19 -08005679 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5680 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005681 // before this feature is enabled, this API should only return false if
5682 // the operation fails instead of throwing runtime exception for
5683 // backward-compatibility.
5684 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5685 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 final long identity = Binder.clearCallingIdentity();
5687 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005688 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005689 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 }
Chen Xue9d737e2022-01-01 23:41:31 -08005691 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005692 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005693 Boolean success = false;
5694 if (result instanceof RuntimeException) {
5695 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005696 if (shouldThrowExceptionOnFailure) {
5697 throw (RuntimeException) result;
5698 } else {
5699 return false;
5700 }
Chen Xue9d737e2022-01-01 23:41:31 -08005701 } else if (result instanceof Boolean) {
5702 success = (Boolean) result;
5703 } else {
5704 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5705 }
Rambo Wanga1782702021-11-10 20:15:19 -08005706 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 return success;
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005710 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005711 }
5712
5713 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005714 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005715 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5717 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005718 if (DBG) {
5719 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5720 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5721 + p3 + " data=" + data);
5722 }
5723 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5724 command, p1, p2, p3, data);
5725 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005726
Jordan Liu4c733742019-02-28 12:03:40 -08005727 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005728 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005729 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005730 enforceModifyPermission();
5731 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005732 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005733 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5734 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005735 }
5736 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005737 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5738 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005739 }
5740
5741 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5742 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 final long identity = Binder.clearCallingIdentity();
5744 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005745 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 return "";
5747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005750 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5751 null /* workSource */);
5752 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 // Append the returned status code to the end of the response payload.
5755 String s = Integer.toHexString(
5756 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5757 if (response.payload != null) {
5758 s = IccUtils.bytesToHexString(response.payload) + s;
5759 }
5760 return s;
5761 } finally {
5762 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005763 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005764 }
Jake Hambye994d462014-02-03 13:10:13 -08005765
Evan Charltonc66da362014-05-16 14:06:40 -07005766 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005767 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5768 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5770 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005772 if (DBG) {
5773 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5774 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5775 }
5776 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5777 cla, command, p1, p2, p3, data);
5778 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005779
Jordan Liu4c733742019-02-28 12:03:40 -08005780 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005781 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005782 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005783 enforceModifyPermission();
5784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5785 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005786 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005787 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5788 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005789 }
5790
5791 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005792 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5793 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005794 }
5795
5796 // open APDU basic channel assuming the caller has sufficient permissions
5797 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5798 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5802 && TextUtils.equals(ISDR_AID, data)) {
5803 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005804 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5805 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 if (bestComponent == null
5807 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5808 loge("The calling package is not allowed to select ISD-R.");
5809 throw new SecurityException(
5810 "The calling package is not allowed to select ISD-R.");
5811 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005812 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005815 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5816 null /* workSource */);
5817 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 // Append the returned status code to the end of the response payload.
5820 String s = Integer.toHexString(
5821 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5822 if (response.payload != null) {
5823 s = IccUtils.bytesToHexString(response.payload) + s;
5824 }
5825 return s;
5826 } finally {
5827 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005828 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005829 }
5830
5831 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005832 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005833 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5835 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 final long identity = Binder.clearCallingIdentity();
5838 try {
5839 if (DBG) {
5840 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5841 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5842 }
5843
5844 IccIoResult response =
5845 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5846 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5847 subId);
5848
5849 if (DBG) {
5850 log("Exchange SIM_IO [R]" + response);
5851 }
5852
5853 byte[] result = null;
5854 int length = 2;
5855 if (response.payload != null) {
5856 length = 2 + response.payload.length;
5857 result = new byte[length];
5858 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5859 } else {
5860 result = new byte[length];
5861 }
5862
5863 result[length - 1] = (byte) response.sw2;
5864 result[length - 2] = (byte) response.sw1;
5865 return result;
5866 } finally {
5867 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005868 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005869 }
5870
Nathan Haroldb3014052017-01-25 15:57:32 -08005871 /**
5872 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5873 * on a particular subscription
5874 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005875 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5876 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005878 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005879 return null;
5880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 if (appType != TelephonyManager.APPTYPE_USIM
5885 && appType != TelephonyManager.APPTYPE_SIM) {
5886 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5887 return null;
5888 }
5889 Object response = sendRequest(
5890 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5891 if (response instanceof String[]) {
5892 return (String[]) response;
5893 }
yincheng zhao2737e882019-09-06 17:06:54 -07005894 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005896 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 } finally {
5898 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005899 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005900 }
5901
yincheng zhao2737e882019-09-06 17:06:54 -07005902 /**
5903 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5904 * subscription.
5905 *
5906 * @param subId the id of the subscription.
5907 * @param appType the uicc app type, must be USIM or SIM.
5908 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5909 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005910 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005911 * @return number of fplmns that is successfully written to the SIM.
5912 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005913 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5914 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5916 mApp, subId, "setForbiddenPlmns");
5917
yincheng zhao2737e882019-09-06 17:06:54 -07005918 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5919 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5920 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5921 }
5922 if (fplmns == null) {
5923 throw new IllegalArgumentException("Fplmn List provided is null");
5924 }
5925 for (String fplmn : fplmns) {
5926 if (!CellIdentity.isValidPlmn(fplmn)) {
5927 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5928 }
5929 }
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 Object response = sendRequest(
5933 CMD_SET_FORBIDDEN_PLMNS,
5934 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5935 subId);
5936 return (int) response;
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
5940 }
5941
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005942 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005943 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5945 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5950 if (response.payload == null) {
5951 return "";
5952 }
Evan Charltonc66da362014-05-16 14:06:40 -07005953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 // Append the returned status code to the end of the response payload.
5955 String s = Integer.toHexString(
5956 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5957 s = IccUtils.bytesToHexString(response.payload) + s;
5958 return s;
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
Evan Charltonc66da362014-05-16 14:06:40 -07005962 }
5963
Jake Hambye994d462014-02-03 13:10:13 -08005964 /**
5965 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5966 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5967 *
5968 * @param itemID the ID of the item to read
5969 * @return the NV item as a String, or null on error.
5970 */
5971 @Override
5972 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5975 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976
5977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005980 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5982 return value;
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Jake Hambye994d462014-02-03 13:10:13 -08005986 }
5987
5988 /**
5989 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5990 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5991 *
5992 * @param itemID the ID of the item to read
5993 * @param itemValue the value to write, as a String
5994 * @return true on success; false on any failure
5995 */
5996 @Override
5997 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005998 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
6004 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6005 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006006 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6008 return success;
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
Jake Hambye994d462014-02-03 13:10:13 -08006012 }
6013
6014 /**
6015 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6016 * Used for device configuration by some CDMA operators.
6017 *
6018 * @param preferredRoamingList byte array containing the new PRL
6019 * @return true on success; false on any failure
6020 */
6021 @Override
6022 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6024 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6029 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6030 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6031 return success;
6032 } finally {
6033 Binder.restoreCallingIdentity(identity);
6034 }
Jake Hambye994d462014-02-03 13:10:13 -08006035 }
6036
6037 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006038 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006039 * Used for device configuration by some CDMA operators.
6040 *
chen xu6dac5ab2018-10-26 17:39:23 -07006041 * @param slotIndex - device slot.
6042 *
Jake Hambye994d462014-02-03 13:10:13 -08006043 * @return true on success; false on any failure
6044 */
6045 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006046 public boolean resetModemConfig(int slotIndex) {
6047 Phone phone = PhoneFactory.getPhone(slotIndex);
6048 if (phone != null) {
6049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6050 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051
chen xu6dac5ab2018-10-26 17:39:23 -07006052 final long identity = Binder.clearCallingIdentity();
6053 try {
6054 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6055 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6056 return success;
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 }
chen xu6dac5ab2018-10-26 17:39:23 -07006061 return false;
6062 }
6063
6064 /**
6065 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6066 *
6067 * @param slotIndex - device slot.
6068 *
6069 * @return true on success; false on any failure
6070 */
6071 @Override
6072 public boolean rebootModem(int slotIndex) {
6073 Phone phone = PhoneFactory.getPhone(slotIndex);
6074 if (phone != null) {
6075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6076 mApp, phone.getSubId(), "rebootModem");
6077
6078 final long identity = Binder.clearCallingIdentity();
6079 try {
6080 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6081 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6082 return success;
6083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
6086 }
6087 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006088 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006089
Brad Ebinger51f743a2017-01-23 13:50:20 -08006090 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006091 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6092 * {@link #disableIms(int)}.
6093 * @param slotIndex device slot.
6094 */
6095 public void resetIms(int slotIndex) {
6096 enforceModifyPermission();
6097
6098 final long identity = Binder.clearCallingIdentity();
6099 try {
6100 if (mImsResolver == null) {
6101 // may happen if the does not support IMS.
6102 return;
6103 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006104 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
6108 }
6109
6110 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006111 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6112 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006113 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006114 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006115 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116
6117 final long identity = Binder.clearCallingIdentity();
6118 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006119 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006120 // may happen if the device does not support IMS.
6121 return;
6122 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006123 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006127 }
6128
6129 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006130 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6131 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006132 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006133 public void disableIms(int slotId) {
6134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135
6136 final long identity = Binder.clearCallingIdentity();
6137 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006138 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006139 // may happen if the device does not support IMS.
6140 return;
6141 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006142 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006146 }
6147
6148 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006149 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6150 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006151 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006152 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006153 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155
6156 final long identity = Binder.clearCallingIdentity();
6157 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006158 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006159 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6160 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006161 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006162 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006166 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006167 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006168 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6169 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006170 @Override
6171 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006172 enforceModifyPermission();
6173
6174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006177 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
6181 }
6182
6183 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006184 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006185 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006186 */
6187 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6188 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189
6190 final long identity = Binder.clearCallingIdentity();
6191 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006192 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006193 // may happen if the device does not support IMS.
6194 return null;
6195 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006196 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 } finally {
6198 Binder.restoreCallingIdentity(identity);
6199 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006200 }
6201
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006202 /**
6203 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006204 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006205 */
6206 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6207 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208
6209 final long identity = Binder.clearCallingIdentity();
6210 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006211 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006212 // may happen if the device does not support IMS.
6213 return null;
6214 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006215 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 } finally {
6217 Binder.restoreCallingIdentity(identity);
6218 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006219 }
6220
Brad Ebinger884c07b2018-02-15 16:17:40 -08006221 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006222 * Sets the ImsService Package Name that Telephony will bind to.
6223 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006224 * @param slotIndex the slot ID that the ImsService should bind for.
6225 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006226 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006227 * @param featureTypes An integer array of feature types associated with a packageName.
6228 * @param packageName The name of the package that the current configuration will be replaced
6229 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006230 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006231 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006232 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6233 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006234 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006236 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006240 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006241 // may happen if the device does not support IMS.
6242 return false;
6243 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006244 Map<Integer, String> featureConfig = new HashMap<>();
6245 for (int featureType : featureTypes) {
6246 featureConfig.put(featureType, packageName);
6247 }
6248 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6249 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006253 }
6254
6255 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006256 * Clears any carrier ImsService overrides for the slot index specified that were previously
6257 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6258 *
6259 * This should only be used for testing.
6260 *
6261 * @param slotIndex the slot ID that the ImsService should bind for.
6262 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6263 */
6264 @Override
6265 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6267 "clearCarrierImsServiceOverride");
6268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006269 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006270
6271 final long identity = Binder.clearCallingIdentity();
6272 try {
6273 if (mImsResolver == null) {
6274 // may happen if the device does not support IMS.
6275 return false;
6276 }
6277 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
6281 }
6282
6283 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006284 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006285 *
6286 * @param slotId The slot that the ImsService is associated with.
6287 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6288 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006289 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006290 * @return the package name of the ImsService configuration.
6291 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006292 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6293 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006294 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006295 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6296 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 final long identity = Binder.clearCallingIdentity();
6299 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006300 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006301 // may happen if the device does not support IMS.
6302 return "";
6303 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006304 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006305 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6306 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006310 }
6311
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006312 /**
6313 * Get the MmTelFeature state associated with the requested subscription id.
6314 * @param subId The subscription that the MmTelFeature is associated with.
6315 * @param callback A callback with an integer containing the
6316 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6317 */
6318 @Override
6319 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6320 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006321 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6322 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6323 "IMS not available on device.");
6324 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006325 final long token = Binder.clearCallingIdentity();
6326 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006327 int slotId = getSlotIndex(subId);
6328 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6329 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6330 + subId + "'");
6331 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6332 }
6333 verifyImsMmTelConfiguredOrThrow(slotId);
6334 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6335 try {
6336 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6337 } catch (RemoteException e) {
6338 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6339 + "Ignore");
6340 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006341 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006342 } catch (ImsException e) {
6343 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006344 } finally {
6345 Binder.restoreCallingIdentity(token);
6346 }
6347 }
6348
Daniel Brightbb5840b2021-01-12 15:48:18 -08006349 /**
6350 * Sets the ims registration state on all valid {@link Phone}s.
6351 */
6352 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006357 // NOTE: Before S, this method only set the default phone.
6358 for (final Phone phone : PhoneFactory.getPhones()) {
6359 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6360 phone.setImsRegistrationState(registered);
6361 }
6362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
Wink Saville36469e72014-06-11 15:17:00 -07006366 }
6367
6368 /**
Stuart Scott54788802015-03-30 13:18:01 -07006369 * Set the network selection mode to automatic.
6370 *
6371 */
6372 @Override
6373 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6375 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376
6377 final long identity = Binder.clearCallingIdentity();
6378 try {
shilufc958392020-01-20 11:36:01 -08006379 if (!isActiveSubscription(subId)) {
6380 return;
6381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006383 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6384 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
Stuart Scott54788802015-03-30 13:18:01 -07006388 }
6389
Jack Yud10cdd42020-09-28 20:28:01 -07006390 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006391 * Ask the radio to connect to the input network and change selection mode to manual.
6392 *
6393 * @param subId the id of the subscription.
6394 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6395 * the operator to attach to.
6396 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6397 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6398 * normal network selection next time.
6399 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006400 */
6401 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006402 public boolean setNetworkSelectionModeManual(
6403 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6405 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006406
Jack Yu285100e2022-12-02 22:48:35 -08006407 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006408 if (!isActiveSubscription(subId)) {
6409 return false;
6410 }
6411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006413 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006415 if (DBG) {
6416 log("setNetworkSelectionModeManual: subId: " + subId
6417 + " operator: " + operatorInfo);
6418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006423 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006424 /**
shilu84f6e8b2019-12-19 13:58:01 -08006425 * Get the manual network selection
6426 *
6427 * @param subId the id of the subscription.
6428 *
6429 * @return the previously saved user selected PLMN
6430 */
6431 @Override
6432 public String getManualNetworkSelectionPlmn(int subId) {
6433 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006434 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6435 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006436
6437 final long identity = Binder.clearCallingIdentity();
6438 try {
6439 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006440 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006441 }
6442
6443 final Phone phone = getPhone(subId);
6444 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006445 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006446 }
6447 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6448 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006449 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006454
6455 /**
6456 * Scans for available networks.
6457 */
6458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006459 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6460 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6462 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006463 LocationAccessPolicy.LocationPermissionResult locationResult =
6464 LocationAccessPolicy.checkLocationPermission(mApp,
6465 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6466 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006467 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006468 .setCallingPid(Binder.getCallingPid())
6469 .setCallingUid(Binder.getCallingUid())
6470 .setMethod("getCellNetworkScanResults")
6471 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006472 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6473 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006474 .build());
6475 switch (locationResult) {
6476 case DENIED_HARD:
6477 throw new SecurityException("Not allowed to access scan results -- location");
6478 case DENIED_SOFT:
6479 return null;
6480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481
Pengquan Menga1bb6272018-09-06 09:59:22 -07006482 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483 try {
6484 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006485 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006490 }
6491
6492 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006493 * Get the call forwarding info, given the call forwarding reason.
6494 */
6495 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006496 public void getCallForwarding(int subId, int callForwardingReason,
6497 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006498 enforceReadPrivilegedPermission("getCallForwarding");
6499 long identity = Binder.clearCallingIdentity();
6500 try {
6501 if (DBG) {
6502 log("getCallForwarding: subId " + subId
6503 + " callForwardingReason" + callForwardingReason);
6504 }
Hall Liu27d24262020-09-18 19:04:59 -07006505
6506 Phone phone = getPhone(subId);
6507 if (phone == null) {
6508 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006509 callback.onError(
6510 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006511 } catch (RemoteException e) {
6512 // ignore
6513 }
6514 return;
6515 }
6516
6517 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6518 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6519 @Override
6520 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6521 try {
6522 callback.onCallForwardingInfoAvailable(info);
6523 } catch (RemoteException e) {
6524 // ignore
6525 }
6526 }
6527
6528 @Override
6529 public void onError(int error) {
6530 try {
6531 callback.onError(error);
6532 } catch (RemoteException e) {
6533 // ignore
6534 }
6535 }
6536 });
6537 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
6541 }
6542
6543 /**
6544 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6545 * reason, the number to forward, and the timeout before the forwarding is attempted.
6546 */
6547 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006548 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6549 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006550 enforceModifyPermission();
6551 long identity = Binder.clearCallingIdentity();
6552 try {
6553 if (DBG) {
6554 log("setCallForwarding: subId " + subId
6555 + " callForwardingInfo" + callForwardingInfo);
6556 }
Hall Liu27d24262020-09-18 19:04:59 -07006557
6558 Phone phone = getPhone(subId);
6559 if (phone == null) {
6560 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006561 callback.accept(
6562 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006563 } catch (RemoteException e) {
6564 // ignore
6565 }
6566 return;
6567 }
6568
6569 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6570 FunctionalUtils.ignoreRemoteException(callback::accept));
6571
6572 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006573 } finally {
6574 Binder.restoreCallingIdentity(identity);
6575 }
6576 }
6577
6578 /**
Hall Liu27d24262020-09-18 19:04:59 -07006579 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006580 */
6581 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006582 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006583 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006584 long identity = Binder.clearCallingIdentity();
6585 try {
Hall Liu27d24262020-09-18 19:04:59 -07006586 Phone phone = getPhone(subId);
6587 if (phone == null) {
6588 try {
6589 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6590 } catch (RemoteException e) {
6591 // ignore
6592 }
6593 return;
6594 }
SongFerngWang0e767992021-03-31 22:08:45 +08006595 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6596 PersistableBundle c = configManager.getConfigForSubId(subId);
6597 boolean requireUssd = c.getBoolean(
6598 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006599
Shuo Qian4a594052020-01-23 11:59:30 -08006600 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006601 if (requireUssd) {
6602 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6603 getSubscriptionCarrierId(subId));
6604 String newUssdCommand = "";
6605 try {
6606 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006607 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006608 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6609 } catch (NullPointerException e) {
6610 loge("Failed to generate USSD number" + e);
6611 }
6612 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6613 mMainThreadHandler, callback, carrierXmlParser,
6614 CarrierXmlParser.SsEntry.SSAction.QUERY);
6615 final String ussdCommand = newUssdCommand;
6616 Executors.newSingleThreadExecutor().execute(() -> {
6617 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6618 });
6619 } else {
6620 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6621 callback::accept);
6622 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6623 }
Shuo Qian4a594052020-01-23 11:59:30 -08006624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
6627 }
6628
6629 /**
Hall Liu27d24262020-09-18 19:04:59 -07006630 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006631 */
6632 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006633 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006634 enforceModifyPermission();
6635 long identity = Binder.clearCallingIdentity();
6636 try {
Hall Liu27d24262020-09-18 19:04:59 -07006637 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6638
6639 Phone phone = getPhone(subId);
6640 if (phone == null) {
6641 try {
6642 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6643 } catch (RemoteException e) {
6644 // ignore
6645 }
6646 return;
6647 }
6648
SongFerngWang0e767992021-03-31 22:08:45 +08006649 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6650 PersistableBundle c = configManager.getConfigForSubId(subId);
6651 boolean requireUssd = c.getBoolean(
6652 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006653
SongFerngWang0e767992021-03-31 22:08:45 +08006654 if (DBG) log("getCallWaitingStatus: subId " + subId);
6655 if (requireUssd) {
6656 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6657 getSubscriptionCarrierId(subId));
6658 CarrierXmlParser.SsEntry.SSAction ssAction =
6659 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6660 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6661 String newUssdCommand = "";
6662 try {
6663 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006664 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006665 .makeCommand(ssAction, null);
6666 } catch (NullPointerException e) {
6667 loge("Failed to generate USSD number" + e);
6668 }
6669 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6670 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6671 final String ussdCommand = newUssdCommand;
6672 Executors.newSingleThreadExecutor().execute(() -> {
6673 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6674 });
6675 } else {
6676 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6677 FunctionalUtils.ignoreRemoteException(callback::accept));
6678
6679 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6680 }
Shuo Qian4a594052020-01-23 11:59:30 -08006681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
6684 }
6685
6686 /**
yinxub1bed742017-04-17 11:45:04 -07006687 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006688 *
yinxub1bed742017-04-17 11:45:04 -07006689 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006690 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6691 * location related information which will be sent if the caller already possess
6692 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006693 * @param request contains the radio access networks with bands/channels to scan
6694 * @param messenger callback messenger for scan results or errors
6695 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006696 * @return the id of the requested scan which can be used to stop the scan.
6697 */
6698 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006699 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6700 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006701 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6703 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006704 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006705 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6706 if (!renounceFineLocationAccess) {
6707 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006708 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6709 .setCallingPackage(callingPackage)
6710 .setCallingFeatureId(callingFeatureId)
6711 .setCallingPid(Binder.getCallingPid())
6712 .setCallingUid(Binder.getCallingUid())
6713 .setMethod("requestNetworkScan")
6714 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6715 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6716 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6717 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006718 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006719 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006720 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6721 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006722 if (e != null) {
6723 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6724 throw e;
6725 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006726 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006727 return TelephonyScanManager.INVALID_SCAN_ID;
6728 }
6729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 }
Hall Liu912dfd32019-04-25 14:02:26 -07006731 int callingUid = Binder.getCallingUid();
6732 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006736 renounceFineLocationAccess, request, messenger, binder,
6737 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006738 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
yinxu504e1392017-04-12 16:03:22 -07006742 }
6743
Hall Liub2ac8ef2019-02-28 15:56:23 -08006744 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006745 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006746 boolean hasCarrierPriv;
6747 final long identity = Binder.clearCallingIdentity();
6748 try {
6749 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6750 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
Hall Liu558027f2019-05-15 19:14:05 -07006754 boolean hasNetworkScanPermission =
6755 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006756 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006757
6758 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6759 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6760 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006761 }
6762
6763 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6764 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006765 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6766 return new SecurityException("Specific channels must not be"
6767 + " scanned without location access.");
6768 }
6769 }
6770 }
6771
Hall Liub2ac8ef2019-02-28 15:56:23 -08006772 return null;
6773 }
6774
yinxu504e1392017-04-12 16:03:22 -07006775 /**
6776 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006777 *
6778 * @param subId id of the subscription
6779 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006780 */
6781 @Override
6782 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6784 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785
Hall Liu912dfd32019-04-25 14:02:26 -07006786 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 final long identity = Binder.clearCallingIdentity();
6788 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006789 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
yinxu504e1392017-04-12 16:03:22 -07006793 }
6794
6795 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006796 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006797 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006798 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006799 */
6800 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006801 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006802 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006803 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006804 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006808 if (DBG) log("getAllowedNetworkTypesBitmask");
6809 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6810 int networkTypesBitmask = (result != null ? result[0] : -1);
6811 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6812 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 } finally {
6814 Binder.restoreCallingIdentity(identity);
6815 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006816 }
6817
6818 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006819 * Get the allowed network types for certain reason.
6820 *
6821 * @param subId the id of the subscription.
6822 * @param reason the reason the allowed network type change is taking place
6823 * @return the allowed network types.
6824 */
6825 @Override
6826 public long getAllowedNetworkTypesForReason(int subId,
6827 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006828 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006829 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006830 final long identity = Binder.clearCallingIdentity();
6831 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006832 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006833 } finally {
6834 Binder.restoreCallingIdentity(identity);
6835 }
6836 }
6837
6838 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006839 * Enable/Disable E-UTRA-NR Dual Connectivity
6840 * @param subId subscription id of the sim card
6841 * @param nrDualConnectivityState expected NR dual connectivity state
6842 * This can be passed following states
6843 * <ol>
6844 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6845 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6846 * <li>Disable NR dual connectivity and force secondary cell to be released
6847 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6848 * </ol>
6849 * @return operation result.
6850 */
6851 @Override
6852 public int setNrDualConnectivityState(int subId,
6853 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6855 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006856 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006857 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6858 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6859 }
6860
Sooraj Sasindran37444802020-08-11 10:40:43 -07006861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6862 final long identity = Binder.clearCallingIdentity();
6863 try {
6864 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6865 nrDualConnectivityState, subId,
6866 workSource);
6867 if (DBG) log("enableNRDualConnectivity result: " + result);
6868 return result;
6869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
6872 }
6873
6874 /**
6875 * Is E-UTRA-NR Dual Connectivity enabled
6876 * @return true if dual connectivity is enabled else false
6877 */
6878 @Override
6879 public boolean isNrDualConnectivityEnabled(int subId) {
6880 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006881 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006882 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006883 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006884 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6885 return false;
6886 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6891 null, subId, workSource);
6892 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6893 return isEnabled;
6894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
6897 }
6898
6899 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006900 * Set the allowed network types of the device and
6901 * provide the reason triggering the allowed network change.
6902 *
6903 * @param subId the id of the subscription.
6904 * @param reason the reason the allowed network type change is taking place
6905 * @param allowedNetworkTypes the allowed network types.
6906 * @return true on success; false on any failure.
6907 */
6908 @Override
6909 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006910 @TelephonyManager.AllowedNetworkTypesReason int reason,
6911 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6913 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006914 // If the caller only has carrier privileges, then they should not be able to override
6915 // any network types which were set for security reasons.
6916 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6917 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006918 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006919 throw new SecurityException(
6920 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006921 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006922 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006923 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006924 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006925 return false;
6926 }
6927 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6928 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006929 return false;
6930 }
6931
Jack Yu5b494332023-01-23 18:18:04 +00006932 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6933 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006934
Jack Yue37dd262022-12-16 11:53:37 -08006935 Phone phone = getPhone(subId);
6936 if (phone == null) {
6937 return false;
6938 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006939
Jack Yue37dd262022-12-16 11:53:37 -08006940 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006941 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006942 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006943 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006944
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006945 final long identity = Binder.clearCallingIdentity();
6946 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006947 Boolean success = (Boolean) sendRequest(
6948 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6949 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6950
6951 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6952 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006953 } finally {
6954 Binder.restoreCallingIdentity(identity);
6955 }
6956 }
6957
6958 /**
Miaoa84611c2019-03-15 09:21:10 +08006959 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006960 *
Miaoa84611c2019-03-15 09:21:10 +08006961 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006962 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006963 * @hide
6964 */
6965 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006966 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006969 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 try {
Miaoa84611c2019-03-15 09:21:10 +08006971 if (phone != null) {
6972 return phone.hasMatchedTetherApnSetting();
6973 } else {
6974 return false;
6975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976 } finally {
6977 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006978 }
Junda Liu475951f2014-11-07 16:45:03 -08006979 }
6980
6981 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006982 * Get the user enabled state of Mobile Data.
6983 *
6984 * TODO: remove and use isUserDataEnabled.
6985 * This can't be removed now because some vendor codes
6986 * calls through ITelephony directly while they should
6987 * use TelephonyManager.
6988 *
6989 * @return true on enabled
6990 */
6991 @Override
6992 public boolean getDataEnabled(int subId) {
6993 return isUserDataEnabled(subId);
6994 }
6995
6996 /**
6997 * Get whether mobile data is enabled per user setting.
6998 *
6999 * There are other factors deciding whether mobile data is actually enabled, but they are
7000 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007001 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007002 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7003 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007004 *
7005 * @return {@code true} if data is enabled else {@code false}
7006 */
7007 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007008 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007009 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007010 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007011 try {
7012 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7013 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007014 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007015 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7016 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007017 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007019 mApp, subId, functionName);
7020
Robert Greenwalt646120a2014-05-23 11:54:03 -07007021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
Jack Yu285100e2022-12-02 22:48:35 -08007025 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7027 Phone phone = PhoneFactory.getPhone(phoneId);
7028 if (phone != null) {
7029 boolean retVal = phone.isUserDataEnabled();
7030 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7031 return retVal;
7032 } else {
7033 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7034 return false;
7035 }
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007038 }
7039 }
7040
7041 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007042 * Checks if the device is capable of mobile data by considering whether whether the
7043 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7044 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007045 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007046 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007047 */
7048 @Override
7049 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007050 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007051 try {
7052 try {
7053 mApp.enforceCallingOrSelfPermission(
7054 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007055 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007056 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007057 try {
7058 mApp.enforceCallingOrSelfPermission(
7059 android.Manifest.permission.READ_PHONE_STATE,
7060 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007061 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007062 mApp.enforceCallingOrSelfPermission(
7063 permission.READ_BASIC_PHONE_STATE, functionName);
7064 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007065 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007066 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007067 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069
7070 final long identity = Binder.clearCallingIdentity();
7071 try {
Jack Yu285100e2022-12-02 22:48:35 -08007072 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 Phone phone = PhoneFactory.getPhone(phoneId);
7074 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007075 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007076 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 return retVal;
7078 } else {
7079 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7080 return false;
7081 }
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007084 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007085 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007086
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007087 /**
7088 * Check if data is enabled for a specific reason
7089 * @param subId Subscription index
7090 * @param reason the reason the data enable change is taking place
7091 * @return {@code true} if the overall data is enabled; {@code false} if not.
7092 */
7093 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007094 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007095 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007096 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007097 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007098 try {
7099 mApp.enforceCallingOrSelfPermission(
7100 android.Manifest.permission.ACCESS_NETWORK_STATE,
7101 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007102 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007103 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7104 functionName);
7105 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007106 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007107 try {
7108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007109 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007110 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007112 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007113 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007114 }
7115
7116
7117 final long identity = Binder.clearCallingIdentity();
7118 try {
Jack Yu285100e2022-12-02 22:48:35 -08007119 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007120 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007121 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007122 + " reason=" + reason);
7123 }
7124 Phone phone = PhoneFactory.getPhone(phoneId);
7125 if (phone != null) {
7126 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007127 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007128 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007129 return retVal;
7130 } else {
7131 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007132 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007133 + subId + " retVal=false");
7134 }
7135 return false;
7136 }
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
7140 }
7141
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007142 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007143 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007144 // No permission needed; this only lets the caller inspect their own status.
7145 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007146 }
Junda Liu29340342014-07-10 15:23:27 -07007147
7148 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007149 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007150 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007151 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7152 }
7153
7154 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7155 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007156 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007157 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007158 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7159 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007160 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7161 if (cpt == null) {
7162 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007163 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7164 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007165 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007166 }
7167
7168 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007169 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007170 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007171 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007172 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007173 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007174 Phone phone = getPhone(subId);
7175 if (phone == null) {
7176 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7178 }
7179 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7180 if (cpt == null) {
7181 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007182 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7183 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007184 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007185 }
7186
7187 @Override
7188 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007189 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007190 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7191 }
7192
7193 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007194 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007195 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007196 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007197 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007198 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7199 Phone phone = PhoneFactory.getPhone(phoneId);
7200 if (phone == null) {
7201 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007202 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007203 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7204 if (cpt == null) {
7205 continue;
7206 }
7207 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007208 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7209 break;
7210 }
7211 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007212 return result;
Junda Liu29340342014-07-10 15:23:27 -07007213 }
Derek Tan89e89d42014-07-08 17:00:10 -07007214
7215 @Override
Junda Liue64de782015-04-16 17:19:16 -07007216 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007217 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007218 Phone phone = PhoneFactory.getPhone(phoneId);
7219 if (phone == null) {
7220 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007221 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007222 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7223 if (cpt == null) {
7224 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007225 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007226 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007227 }
7228
Amith Yamasani6e118872016-02-19 12:53:51 -08007229 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007230 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007231 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007232 Phone phone = PhoneFactory.getPhone(phoneId);
7233 if (phone == null) {
7234 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007235 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007236 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7237 if (cpt == null) {
7238 return Collections.emptyList();
7239 }
7240 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007241 }
7242
chen xuf7e9fe82019-05-09 19:31:02 -07007243 @Override
7244 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007245 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007246 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007247 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007248 try {
7249 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7250 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7251 }
7252 } finally {
7253 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007254 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007255 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007256 }
7257
Rambo Wang6812ffb2022-03-15 16:54:17 -07007258 @Override
7259 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7260 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7261
7262 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7263 if (phone == null) {
7264 return null;
7265 }
7266 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7267 if (cpt == null) {
7268 return null;
7269 }
7270 return cpt.getCarrierServicePackageName();
7271 }
7272
Wink Savilleb564aae2014-10-23 10:18:09 -07007273 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007274 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007275 UiccPort port = phone == null ? null : phone.getUiccPort();
7276 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007277 return null;
7278 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007279 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007280 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007281 return null;
7282 }
7283 return iccId;
7284 }
7285
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007286 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007287 public void setCallComposerStatus(int subId, int status) {
7288 enforceModifyPermission();
7289
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 Phone phone = getPhone(subId);
7293 if (phone != null) {
7294 Phone defaultPhone = phone.getImsPhone();
7295 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7296 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7297 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007298 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7299 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007300 }
7301 }
Shuo Qian284ae752020-12-22 19:10:14 -08007302 } catch (ImsException e) {
7303 throw new ServiceSpecificException(e.getCode());
7304 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007305 Binder.restoreCallingIdentity(identity);
7306 }
7307 }
7308
7309 @Override
7310 public int getCallComposerStatus(int subId) {
7311 enforceReadPrivilegedPermission("getCallComposerStatus");
7312
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 Phone phone = getPhone(subId);
7316 if (phone != null) {
7317 Phone defaultPhone = phone.getImsPhone();
7318 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7319 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7320 return imsPhone.getCallComposerStatus();
7321 }
7322 }
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7327 }
7328
7329 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007330 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7331 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007332 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007333 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 final String iccId = getIccId(subId);
7338 final Phone phone = getPhone(subId);
7339 if (phone == null) {
7340 return false;
7341 }
7342 final String subscriberId = phone.getSubscriberId();
7343
7344 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007345 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 + subscriberId + " to " + number);
7347 }
7348
7349 if (TextUtils.isEmpty(iccId)) {
7350 return false;
7351 }
7352
7353 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7354
7355 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7356 if (alphaTag == null) {
7357 editor.remove(alphaTagPrefKey);
7358 } else {
7359 editor.putString(alphaTagPrefKey, alphaTag);
7360 }
7361
7362 // Record both the line number and IMSI for this ICCID, since we need to
7363 // track all merged IMSIs based on line number
7364 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7365 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7366 if (number == null) {
7367 editor.remove(numberPrefKey);
7368 editor.remove(subscriberPrefKey);
7369 } else {
7370 editor.putString(numberPrefKey, number);
7371 editor.putString(subscriberPrefKey, subscriberId);
7372 }
7373
7374 editor.commit();
7375 return true;
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007378 }
Derek Tan7226c842014-07-02 17:42:23 -07007379 }
7380
7381 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007382 public String getLine1NumberForDisplay(int subId, String callingPackage,
7383 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007384 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007386 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007387 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007388 return null;
7389 }
Derek Tan97ebb422014-09-05 16:55:38 -07007390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 final long identity = Binder.clearCallingIdentity();
7392 try {
7393 String iccId = getIccId(subId);
7394 if (iccId != null) {
7395 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7396 if (DBG_MERGE) {
7397 log("getLine1NumberForDisplay returning "
7398 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7399 }
7400 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7403 return null;
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007406 }
Derek Tan7226c842014-07-02 17:42:23 -07007407 }
7408
7409 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007410 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7411 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007413 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007414 return null;
7415 }
Derek Tan97ebb422014-09-05 16:55:38 -07007416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 String iccId = getIccId(subId);
7420 if (iccId != null) {
7421 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7422 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7423 }
7424 return null;
7425 } finally {
7426 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007427 }
Derek Tan7226c842014-07-02 17:42:23 -07007428 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007429
7430 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007431 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7432 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007433 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7434 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007435 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007436 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007438 return null;
7439 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007440
Jordan Liub49b04b2019-05-06 14:45:15 -07007441 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7442 // the process, where TelephonyManager was instantiated.
7443 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007444 final long identity = Binder.clearCallingIdentity();
7445 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 final TelephonyManager tele = TelephonyManager.from(context);
7448 final SubscriptionManager sub = SubscriptionManager.from(context);
7449
7450 // Figure out what subscribers are currently active
7451 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452
Jordan Liub49b04b2019-05-06 14:45:15 -07007453 // Only consider subs which match the current subId
7454 // This logic can be simplified. See b/131189269 for progress.
7455 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007456 activeSubscriberIds.add(tele.getSubscriberId(subId));
7457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458
7459 // First pass, find a number override for an active subscriber
7460 String mergeNumber = null;
7461 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7462 for (String key : prefs.keySet()) {
7463 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7464 final String subscriberId = (String) prefs.get(key);
7465 if (activeSubscriberIds.contains(subscriberId)) {
7466 final String iccId = key.substring(
7467 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7468 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7469 mergeNumber = (String) prefs.get(numberKey);
7470 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007471 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 + " for active subscriber " + subscriberId);
7473 }
7474 if (!TextUtils.isEmpty(mergeNumber)) {
7475 break;
7476 }
7477 }
7478 }
7479 }
7480
7481 // Shortcut when no active merged subscribers
7482 if (TextUtils.isEmpty(mergeNumber)) {
7483 return null;
7484 }
7485
7486 // Second pass, find all subscribers under that line override
7487 final ArraySet<String> result = new ArraySet<>();
7488 for (String key : prefs.keySet()) {
7489 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7490 final String number = (String) prefs.get(key);
7491 if (mergeNumber.equals(number)) {
7492 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7493 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7494 final String subscriberId = (String) prefs.get(subscriberKey);
7495 if (!TextUtils.isEmpty(subscriberId)) {
7496 result.add(subscriberId);
7497 }
7498 }
7499 }
7500 }
7501
7502 final String[] resultArray = result.toArray(new String[result.size()]);
7503 Arrays.sort(resultArray);
7504 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007505 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7507 }
7508 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007509 } finally {
7510 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007511 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007512 }
7513
7514 @Override
zoey chen38003472019-12-13 17:16:31 +08007515 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7516 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007517
7518 final long identity = Binder.clearCallingIdentity();
7519 try {
7520 final TelephonyManager telephonyManager = mApp.getSystemService(
7521 TelephonyManager.class);
7522 String subscriberId = telephonyManager.getSubscriberId(subId);
7523 if (subscriberId == null) {
7524 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007525 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007526 + subId);
7527 }
7528 return null;
7529 }
7530
Jack Yu3beaf9d2023-04-14 09:17:27 -07007531 final SubscriptionInfo info = getSubscriptionManagerService()
7532 .getSubscriptionInfo(subId);
7533 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007534 // If it doesn't belong to any group, return just subscriberId of itself.
7535 if (groupUuid == null) {
7536 return new String[]{subscriberId};
7537 }
7538
7539 // Get all subscriberIds from the group.
7540 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007541 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7542 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7543 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007544 for (SubscriptionInfo subInfo : groupInfos) {
7545 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7546 if (subscriberId != null) {
7547 mergedSubscriberIds.add(subscriberId);
7548 }
7549 }
7550
7551 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554
7555 }
7556 }
7557
7558 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007559 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007560 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007561 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562
7563 final long identity = Binder.clearCallingIdentity();
7564 try {
7565 final Phone phone = getPhone(subId);
7566 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007570 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007571
7572 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007573 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007574 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7575 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007576 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7577 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578
7579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 final Phone phone = getPhone(subId);
7582 if (phone == null) {
7583 return false;
7584 }
7585 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7586 cdmaNonRoamingList);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007589 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007590 }
7591
7592 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007593 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007594 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007595 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007596 if (phone == null) {
7597 return raf;
7598 }
7599
Shuo Qiandee53402020-05-29 14:08:15 -07007600 try {
7601 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007602 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007603 mApp, phone.getSubId(), "getRadioAccessFamily");
7604 } catch (SecurityException e) {
7605 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7606 throw e;
7607 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 final long identity = Binder.clearCallingIdentity();
7610 try {
chen xub97461a2018-10-26 14:17:57 -07007611 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
chen xub97461a2018-10-26 14:17:57 -07007615 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007616 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007617
7618 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007619 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007620 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007621 try {
7622 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7623 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007624 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007625 }
7626 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007627 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007628 }
7629 RoleManager rm = mApp.getSystemService(RoleManager.class);
7630 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7631 if (!dialerRoleHolders.contains(callingPackage)) {
7632 throw new SecurityException("App must be the dialer role holder to"
7633 + " upload a call composer pic");
7634 }
7635
7636 Executors.newSingleThreadExecutor().execute(() -> {
7637 ByteArrayOutputStream output = new ByteArrayOutputStream(
7638 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7639 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7640 boolean readUntilEnd = false;
7641 int totalBytesRead = 0;
7642 byte[] buffer = new byte[16 * 1024];
7643 while (true) {
7644 int numRead;
7645 try {
7646 numRead = input.read(buffer);
7647 } catch (IOException e) {
7648 try {
7649 fd.checkError();
7650 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7651 null);
7652 } catch (IOException e1) {
7653 // This means that the other side closed explicitly with an error. If this
7654 // happens, log and ignore.
7655 loge("Remote end of call composer picture pipe closed: " + e1);
7656 }
7657 break;
7658 }
7659 if (numRead == -1) {
7660 readUntilEnd = true;
7661 break;
7662 }
7663 totalBytesRead += numRead;
7664 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7665 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7666 try {
7667 input.close();
7668 } catch (IOException e) {
7669 // ignore
7670 }
7671 break;
7672 }
7673 output.write(buffer, 0, numRead);
7674 }
7675 // Generally, the remote end will close the file descriptors. The only case where we
7676 // close is above, where the picture size is too big.
7677
7678 try {
7679 fd.checkError();
7680 } catch (IOException e) {
7681 loge("Remote end for call composer closed with an error: " + e);
7682 return;
7683 }
7684
Hall Liuaa4211e2021-01-20 15:43:39 -08007685 if (!readUntilEnd) {
7686 loge("Did not finish reading entire image; aborting");
7687 return;
7688 }
Hall Liu82694d52020-12-11 18:22:04 -08007689
Hall Liuaa4211e2021-01-20 15:43:39 -08007690 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7691 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7692 new CallComposerPictureTransfer.Factory() {},
7693 imageData,
7694 (result) -> {
7695 if (result.first != null) {
7696 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7697 Bundle outputResult = new Bundle();
7698 outputResult.putParcelable(
7699 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7700 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7701 outputResult);
7702 } else {
7703 callback.send(result.second, null);
7704 }
7705 }
7706 );
Hall Liu82694d52020-12-11 18:22:04 -08007707 });
7708 }
7709
7710 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007711 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007712 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714
7715 final long identity = Binder.clearCallingIdentity();
7716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007717 ImsManager.getInstance(defaultPhone.getContext(),
7718 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 } finally {
7720 Binder.restoreCallingIdentity(identity);
7721 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007722 }
7723
7724 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007725 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7728 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007729 return false;
7730 }
Svet Ganovb320e182015-04-16 12:30:10 -07007731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 final long identity = Binder.clearCallingIdentity();
7733 try {
7734 // Check the user preference and the system-level IMS setting. Even if the user has
7735 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7736 // In the long run, we may instead need to check if there exists a connection service
7737 // which can support video calling.
7738 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 return imsManager.isVtEnabledByPlatform()
7741 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7742 && imsManager.isVtEnabledByUser();
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007746 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007747
Andrew Leea1239f22015-03-02 17:44:07 -08007748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007749 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7750 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007752 mApp, subId, callingPackage, callingFeatureId,
7753 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 return false;
7755 }
7756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 CarrierConfigManager configManager =
7760 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007761 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7763 } finally {
7764 Binder.restoreCallingIdentity(identity);
7765 }
Andrew Leea1239f22015-03-02 17:44:07 -08007766 }
7767
7768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007769 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007771 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772 return false;
7773 }
7774
7775 final long identity = Binder.clearCallingIdentity();
7776 try {
7777 CarrierConfigManager configManager =
7778 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007779 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
Andrew Leea1239f22015-03-02 17:44:07 -08007784 }
7785
Andrew Lee9431b832015-03-09 18:46:45 -07007786 @Override
7787 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007788 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007789 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007790 }
7791
7792 @Override
7793 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 final long identity = Binder.clearCallingIdentity();
7795 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007796 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 } finally {
7798 Binder.restoreCallingIdentity(identity);
7799 }
Andrew Lee9431b832015-03-09 18:46:45 -07007800 }
7801
Hall Liuf6668912018-10-31 17:05:23 -07007802 /**
7803 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7804 * support for the feature and device firmware support.
7805 *
7806 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7807 */
7808 @Override
7809 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007811 final Phone phone = getPhone(subscriptionId);
7812 if (phone == null) {
7813 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7814 return false;
7815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007817 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7819 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007820 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 return isCarrierSupported && isDeviceSupported;
7822 } finally {
7823 Binder.restoreCallingIdentity(identity);
7824 }
Hall Liu98187582018-01-22 19:15:32 -08007825 }
7826
Hall Liuf6668912018-10-31 17:05:23 -07007827 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007828 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7829 * RTT setting, will return true if the device and carrier both support RTT.
7830 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007831 */
7832 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833 final long identity = Binder.clearCallingIdentity();
7834 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007835 boolean isRttSupported = isRttSupported(subscriptionId);
7836 boolean isUserRttSettingOn = Settings.Secure.getInt(
7837 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7838 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7839 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7840 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007844 }
7845
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007846 @Deprecated
7847 @Override
7848 public String getDeviceId(String callingPackage) {
7849 return getDeviceIdWithFeature(callingPackage, null);
7850 }
7851
Sanket Padawe7310cc72015-01-14 09:53:20 -08007852 /**
7853 * Returns the unique device ID of phone, for example, the IMEI for
7854 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7855 *
7856 * <p>Requires Permission:
7857 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7858 */
7859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007860 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007861 try {
7862 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7863 } catch (SecurityException se) {
7864 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7865 throw new SecurityException("Package " + callingPackage + " does not belong to "
7866 + Binder.getCallingUid());
7867 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007868 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007869 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007870 return null;
7871 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007872 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007873 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007874 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007875 return null;
7876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877
7878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 return phone.getDeviceId();
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007884 }
7885
Ping Sunc67b7c22016-03-02 19:16:45 +08007886 /**
7887 * {@hide}
7888 * Returns the IMS Registration Status on a particular subid
7889 *
7890 * @param subId
7891 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007892 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007893 Phone phone = getPhone(subId);
7894 if (phone != null) {
7895 return phone.isImsRegistered();
7896 } else {
7897 return false;
7898 }
7899 }
7900
Santos Cordon7a1885b2015-02-03 11:15:19 -08007901 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007902 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007903 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007905 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007906 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7907 }
7908 final long identity = Binder.clearCallingIdentity();
7909 try {
7910 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
7913 }
7914 }
7915
7916 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007917 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007918 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007919 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007920 mApp,
7921 subscriptionId,
7922 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7923 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007924 final long identity = Binder.clearCallingIdentity();
7925 try {
7926 Phone phone = getPhone(subscriptionId);
7927 if (phone == null) {
7928 return null;
7929 }
7930 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
7934 }
7935
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007936 /**
7937 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007938 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007939 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 Phone phone = getPhone(subId);
7943 if (phone != null) {
7944 return phone.isWifiCallingEnabled();
7945 } else {
7946 return false;
7947 }
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007950 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007951 }
7952
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007953 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007954 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007955 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007956 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 Phone phone = getPhone(subId);
7960 if (phone != null) {
7961 return phone.isVideoEnabled();
7962 } else {
7963 return false;
7964 }
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007967 }
7968 }
7969
7970 /**
7971 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7972 * defined in {@link ImsRegistrationImplBase}.
7973 */
7974 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 Phone phone = getPhone(subId);
7978 if (phone != null) {
7979 return phone.getImsRegistrationTech();
7980 } else {
7981 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7982 }
7983 } finally {
7984 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007985 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007986 }
7987
Stuart Scott8eef64f2015-04-08 15:13:54 -07007988 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007989 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007990 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007991 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7992 return;
7993 }
Kai Shif70f46f2021-03-03 13:59:46 -08007994 Phone defaultPhone = getDefaultPhone();
7995 if (defaultPhone != null) {
7996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7997 mApp, getDefaultPhone().getSubId(), "factoryReset");
7998 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007999 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000
Svet Ganovcc087f82015-05-12 20:35:54 -07008001 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008002 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8003 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008004 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008005 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008006 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008007 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008008 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008009 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008010 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008011 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008012 // There has been issues when Sms raw table somehow stores orphan
8013 // fragments. They lead to garbled message when new fragments come
8014 // in and combined with those stale ones. In case this happens again,
8015 // user can reset all network settings which will clean up this table.
8016 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008017 // Clean up IMS settings as well here.
8018 int slotId = getSlotIndex(subId);
8019 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8020 ImsManager.getInstance(mApp, slotId).factoryReset();
8021 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008022
Kai Shif70f46f2021-03-03 13:59:46 -08008023 if (defaultPhone == null) {
8024 return;
8025 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008026 // Erase modem config if erase modem on network setting is enabled.
8027 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8028 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8029 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008030 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008031 }
Kai Shif70f46f2021-03-03 13:59:46 -08008032
8033 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008034 } finally {
8035 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008036 }
8037 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008038
SongFerngWangfd89b102021-05-27 22:44:54 +08008039 @VisibleForTesting
8040 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8041 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8042 return;
8043 }
8044 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8045 RILConstants.PREFERRED_NETWORK_MODE);
8046 SubscriptionManager.setSubscriptionProperty(subId,
8047 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8048 "user=" + defaultNetworkType);
8049 phone.loadAllowedNetworksFromSubscriptionDatabase();
8050 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8051 defaultNetworkType, null);
8052 }
8053
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008054 private void cleanUpSmsRawTable(Context context) {
8055 ContentResolver resolver = context.getContentResolver();
8056 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8057 resolver.delete(uri, null, null);
8058 }
8059
Narayan Kamath1c496c22015-04-16 14:40:19 +01008060 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008061 public String getSimLocaleForSubscriber(int subId) {
8062 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8063 final Phone phone = getPhone(subId);
8064 if (phone == null) {
8065 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008066 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 final long identity = Binder.clearCallingIdentity();
8069 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008070 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8071 phone.getContext().getOpPackageName(),
8072 phone.getContext().getAttributionTag());
8073 if (info == null) {
8074 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8075 return null;
chen xu6291c472019-02-04 12:55:53 -08008076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008077 // Try and fetch the locale from the carrier properties or from the SIM language
8078 // preferences (EF-PL and EF-LI)...
8079 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008081 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8082 if (localeFromDefaultSim != null) {
8083 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8084 if (DBG) log("Using locale from subId: " + subId + " locale: "
8085 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008086 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008087 } else {
8088 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 }
8090 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 // The SIM language preferences only store a language (e.g. fr = French), not an
8093 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8094 // the SIM and carrier preferences does not include a country we add the country
8095 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008096 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008098 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008099 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100 }
8101
8102 if (DBG) log("No locale found - returning null");
8103 return null;
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
8106 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008107 }
8108
tom hsu0b59d292022-09-29 23:49:21 +08008109 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008110 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008111 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008112 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008113 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008114 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8115 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008116 Locale.forLanguageTag(localeTag).getCountry())) {
8117 return localeTag;
8118 }
8119 }
8120 return inputLocale.toLanguageTag();
8121 }
8122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 /**
8124 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8125 */
8126 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008127 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008128 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008129 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008130
Gary Jian3aa9a762022-01-24 16:41:19 +08008131 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8132 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008133
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008134 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008135 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8136 * representing the state of the modem.
8137 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008138 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8139 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008140 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008141 */
8142 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008143 public void requestModemActivityInfo(ResultReceiver result) {
8144 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008145 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146
8147 final long identity = Binder.clearCallingIdentity();
8148 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008149 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 } finally {
8151 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008152 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008153 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008154
Gary Jian76280a42022-12-07 16:18:33 +08008155 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008156 // less than total activity duration.
8157 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8158 if (info == null) {
8159 return false;
8160 }
8161 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008162 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008163 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8164
Hall Liu49656c02020-10-09 19:00:11 -07008165 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8166
Siddharth Rayb8114062018-06-17 15:02:38 -07008167 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008168 && (info.getSleepTimeMillis() <= activityDurationMs)
8169 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008170 }
8171
Gary Jian3aa9a762022-01-24 16:41:19 +08008172 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8173 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8174 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8175 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8176
8177 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8178 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8179 }
8180
8181 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8182 mLastModemActivityInfo.setReceiveTimeMillis(
8183 rat,
8184 freq,
8185 info.getReceiveTimeMillis(rat, freq)
8186 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8187 }
8188
8189 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8190 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8191 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8192 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8193
8194 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8195 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8196 }
8197 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8198 mLastModemActivityInfo.setReceiveTimeMillis(
8199 rat,
8200 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8201 }
8202
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008203 /**
8204 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8205 * @param info recent ModemActivityInfo
8206 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008207 private void mergeModemActivityInfo(ModemActivityInfo info) {
8208 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008209 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008210 boolean matched;
8211 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8212 matched = false;
8213 int rat = info.getSpecificInfoRat(i);
8214 int freq = info.getSpecificInfoFrequencyRange(i);
8215 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8216 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8217 //if it already exists
8218 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8219 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8220 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8221 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8222 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8223 updateLastModemActivityInfo(info, rat, freq);
8224 matched = true;
8225 }
8226 } else {
8227 updateLastModemActivityInfo(info, rat);
8228 matched = true;
8229 }
8230 }
8231 }
8232
8233 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008234 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008235 new ActivityStatsTechSpecificInfo(
8236 rat,
8237 freq,
8238 info.getTransmitTimeMillis(rat, freq),
8239 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008240 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008241 }
8242 }
8243 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8244 mLastModemActivitySpecificInfo =
8245 new ActivityStatsTechSpecificInfo[merged.size()];
8246 merged.toArray(mLastModemActivitySpecificInfo);
8247
8248 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8249 mLastModemActivityInfo.setSleepTimeMillis(
8250 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008251 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008252 mLastModemActivityInfo.setIdleTimeMillis(
8253 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008254 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008255
8256 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008257 new ModemActivityInfo(
8258 mLastModemActivityInfo.getTimestampMillis(),
8259 mLastModemActivityInfo.getSleepTimeMillis(),
8260 mLastModemActivityInfo.getIdleTimeMillis(),
8261 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008262 }
8263
8264 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8265 ActivityStatsTechSpecificInfo[] info) {
8266 int infoSize = info.length;
8267 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8268 for (int i = 0; i < infoSize; i++) {
8269 ret[i] = new ActivityStatsTechSpecificInfo(
8270 info[i].getRat(), info[i].getFrequencyRange(),
8271 info[i].getTransmitTimeMillis(),
8272 (int) info[i].getReceiveTimeMillis());
8273 }
8274 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008275 }
8276
Jack Yu85bd38a2015-11-09 11:34:32 -08008277 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008278 * Returns the service state information on specified subscription.
8279 */
8280 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008281 public ServiceState getServiceStateForSubscriber(int subId,
8282 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8283 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008286 return null;
8287 }
8288
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008289 boolean hasFinePermission = false;
8290 boolean hasCoarsePermission = false;
8291 if (!renounceFineLocationAccess) {
8292 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8293 LocationAccessPolicy.checkLocationPermission(mApp,
8294 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8295 .setCallingPackage(callingPackage)
8296 .setCallingFeatureId(callingFeatureId)
8297 .setCallingPid(Binder.getCallingPid())
8298 .setCallingUid(Binder.getCallingUid())
8299 .setMethod("getServiceStateForSubscriber")
8300 .setLogAsInfo(true)
8301 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8302 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8303 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8304 .build());
8305 hasFinePermission =
8306 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8307 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008308
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008309 if (!renounceCoarseLocationAccess) {
8310 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8311 LocationAccessPolicy.checkLocationPermission(mApp,
8312 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8313 .setCallingPackage(callingPackage)
8314 .setCallingFeatureId(callingFeatureId)
8315 .setCallingPid(Binder.getCallingPid())
8316 .setCallingUid(Binder.getCallingUid())
8317 .setMethod("getServiceStateForSubscriber")
8318 .setLogAsInfo(true)
8319 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8320 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8321 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8322 .build());
8323 hasCoarsePermission =
8324 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8325 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008326
Jack Yu479f40e2020-10-27 21:29:25 -07008327 final Phone phone = getPhone(subId);
8328 if (phone == null) {
8329 return null;
8330 }
8331
Jordan Liu0f2bc442020-11-18 16:47:37 -08008332 final long identity = Binder.clearCallingIdentity();
8333
Jack Yu479f40e2020-10-27 21:29:25 -07008334 boolean isCallingPackageDataService = phone.getDataServicePackages()
8335 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008337 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008338 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8339 .getSubscriptionInfoInternal(subId);
8340 if (subInfo == null || !subInfo.isActive()) {
8341 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8342 + "subId=" + subId);
8343 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008344 }
8345
Hall Liuf19c44f2018-11-27 14:38:17 -08008346 ServiceState ss = phone.getServiceState();
8347
8348 // Scrub out the location info in ServiceState depending on what level of access
8349 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008350 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008351 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8352 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008356 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008357
8358 /**
8359 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8360 *
8361 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8362 * voicemail ringtone.
8363 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8364 * PhoneAccount.
8365 */
8366 @Override
8367 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8371 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008372 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008379 }
8380
8381 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008382 * Sets the per-account voicemail ringtone.
8383 *
8384 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8385 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8386 *
8387 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8388 * voicemail ringtone.
8389 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8390 * PhoneAccount.
8391 */
8392 @Override
8393 public void setVoicemailRingtoneUri(String callingPackage,
8394 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008395 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008397 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8398 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8400 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8401 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008403
8404 final long identity = Binder.clearCallingIdentity();
8405 try {
8406 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8407 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008408 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409 }
8410 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008413 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008414 }
8415
8416 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008417 * Returns whether vibration is set for voicemail notification in Phone settings.
8418 *
8419 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8420 * voicemail vibration setting.
8421 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8422 */
8423 @Override
8424 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008425 final long identity = Binder.clearCallingIdentity();
8426 try {
8427 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8428 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008429 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8433 } finally {
8434 Binder.restoreCallingIdentity(identity);
8435 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008436 }
8437
Youhan Wange64578a2016-05-02 15:32:42 -07008438 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008439 * Sets the per-account voicemail vibration.
8440 *
8441 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8442 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8443 *
8444 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8445 * voicemail vibration setting.
8446 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8447 * specific PhoneAccount.
8448 */
8449 @Override
8450 public void setVoicemailVibrationEnabled(String callingPackage,
8451 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008452 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008454 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8455 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8457 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8458 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008459 }
8460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8464 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008465 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 }
8467 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008470 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008471 }
8472
8473 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008474 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8475 *
8476 * @throws SecurityException if the caller does not have the required permission
8477 */
arunvoddud7401012022-12-15 16:08:12 +00008478 @VisibleForTesting
8479 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008480 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008481 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008482 }
8483
8484 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008485 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8486 * permission.
8487 *
8488 * @throws SecurityException if the caller does not have the required permission
8489 */
8490 private void enforceSendSmsPermission() {
8491 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8492 }
8493
8494 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008495 * Make sure either called from same process as self (phone) or IPC caller has interact across
8496 * users permission.
8497 *
8498 * @throws SecurityException if the caller does not have the required permission
8499 */
8500 private void enforceInteractAcrossUsersPermission(String message) {
8501 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8502 }
8503
8504 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008505 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008506 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008507 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008508 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008509 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008513 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008514 if (componentName == null) {
8515 throw new SecurityException(
8516 "Caller not current active visual voicemail package[null]");
8517 }
8518 String vvmPackage = componentName.getPackageName();
8519 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008520 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521 }
8522 } finally {
8523 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008524 }
8525 }
8526
8527 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008528 * Return the application ID for the app type.
8529 *
8530 * @param subId the subscription ID that this request applies to.
8531 * @param appType the uicc app type.
8532 * @return Application ID for specificied app type, or null if no uicc.
8533 */
8534 @Override
8535 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008536 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008537 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538
8539 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008540 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 if (phone == null) {
8542 return null;
8543 }
8544 String aid = null;
8545 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008546 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 .getApplicationByType(appType).getAid();
8548 } catch (Exception e) {
8549 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8550 }
8551 return aid;
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008554 }
Youhan Wange64578a2016-05-02 15:32:42 -07008555 }
8556
Youhan Wang4001d252016-05-11 10:29:41 -07008557 /**
8558 * Return the Electronic Serial Number.
8559 *
8560 * @param subId the subscription ID that this request applies to.
8561 * @return ESN or null if error.
8562 */
8563 @Override
8564 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008565 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008566 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567
8568 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008569 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570 if (phone == null) {
8571 return null;
8572 }
8573 String esn = null;
8574 try {
8575 esn = phone.getEsn();
8576 } catch (Exception e) {
8577 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8578 }
8579 return esn;
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008582 }
Youhan Wang4001d252016-05-11 10:29:41 -07008583 }
8584
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008585 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008586 * Return the Preferred Roaming List Version.
8587 *
8588 * @param subId the subscription ID that this request applies to.
8589 * @return PRLVersion or null if error.
8590 */
8591 @Override
8592 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008593 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008594 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008595
8596 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008597 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 if (phone == null) {
8599 return null;
8600 }
8601 String cdmaPrlVersion = null;
8602 try {
8603 cdmaPrlVersion = phone.getCdmaPrlVersion();
8604 } catch (Exception e) {
8605 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8606 }
8607 return cdmaPrlVersion;
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008610 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008611 }
8612
8613 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008614 * Get snapshot of Telephony histograms
8615 * @return List of Telephony histograms
8616 * @hide
8617 */
8618 @Override
8619 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8621 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622
8623 final long identity = Binder.clearCallingIdentity();
8624 try {
8625 return RIL.getTelephonyRILTimingHistograms();
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008629 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008630
8631 /**
8632 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008633 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8634 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008635 * Require system privileges. In the future we may add this to carrier APIs.
8636 *
Michele Berionne482f8202018-11-27 18:57:59 -08008637 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008638 */
8639 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008640 @TelephonyManager.SetCarrierRestrictionResult
8641 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008642 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008643 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008644
Michele Berionne482f8202018-11-27 18:57:59 -08008645 if (carrierRestrictionRules == null) {
8646 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008647 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008649 final long identity = Binder.clearCallingIdentity();
8650 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008651 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008652 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 } finally {
8654 Binder.restoreCallingIdentity(identity);
8655 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008656 }
8657
8658 /**
8659 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008660 * Get the allowed carrier list and the excluded carrier list, including the priority between
8661 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008662 * Require system privileges. In the future we may add this to carrier APIs.
8663 *
Michele Berionne482f8202018-11-27 18:57:59 -08008664 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008665 */
8666 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008667 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008668 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670
8671 final long identity = Binder.clearCallingIdentity();
8672 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008673 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8674 if (response instanceof CarrierRestrictionRules) {
8675 return (CarrierRestrictionRules) response;
8676 }
8677 // Response is an Exception of some kind,
8678 // which is signalled to the user as a NULL retval
8679 return null;
8680 } catch (Exception e) {
8681 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8682 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 } finally {
8684 Binder.restoreCallingIdentity(identity);
8685 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008686 }
8687
fionaxu59545b42016-05-25 15:53:37 -07008688 /**
arunvoddud7401012022-12-15 16:08:12 +00008689 * Fetches the carrier restriction status of the device and sends the status to the caller
8690 * through the callback.
8691 *
8692 * @param callback The callback that will be used to send the result.
8693 * @throws SecurityException if the caller does not have the required permission/privileges or
8694 * the caller is not allowlisted.
8695 */
8696 @Override
8697 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8698 enforceReadPermission("getCarrierRestrictionStatus");
8699 int carrierId = validateCallerAndGetCarrierId(packageName);
8700 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8701 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8702 throw new SecurityException("Not an authorized caller");
8703 }
8704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8707 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8708 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 }
8713
arunvoddu567f2b42023-04-25 17:22:00 +00008714 @Override
8715 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8716 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8717 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8718 return allowListInfo.getShaIdList(pkgName, carrierId);
8719 }
8720
arunvoddud7401012022-12-15 16:08:12 +00008721 @VisibleForTesting
8722 public int validateCallerAndGetCarrierId(String packageName) {
8723 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8724 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8725 }
8726
8727 /**
fionaxu59545b42016-05-25 15:53:37 -07008728 * Action set from carrier signalling broadcast receivers to enable/disable radio
8729 * @param subId the subscription ID that this action applies to.
8730 * @param enabled control enable or disable radio.
8731 * {@hide}
8732 */
8733 @Override
8734 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8735 enforceModifyPermission();
8736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008737
8738 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008739 if (phone == null) {
8740 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8741 return;
8742 }
8743 try {
8744 phone.carrierActionSetRadioEnabled(enabled);
8745 } catch (Exception e) {
8746 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008747 } finally {
8748 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008749 }
8750 }
8751
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008752 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008753 * Enable or disable Voice over NR (VoNR)
8754 * @param subId the subscription ID that this action applies to.
8755 * @param enabled enable or disable VoNR.
8756 * @return operation result.
8757 */
8758 @Override
8759 public int setVoNrEnabled(int subId, boolean enabled) {
8760 enforceModifyPermission();
8761 final Phone phone = getPhone(subId);
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 if (phone == null) {
8765 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8766 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8767 }
8768
8769 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8770 try {
8771 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8772 workSource);
8773 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008774
8775 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8776 if (DBG) {
8777 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8778 }
8779 SubscriptionManager.setSubscriptionProperty(
8780 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8781 (enabled ? "1" : "0"));
8782 }
8783
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008784 return result;
8785 } finally {
8786 Binder.restoreCallingIdentity(identity);
8787 }
8788 }
8789
8790 /**
8791 * Is voice over NR enabled
8792 * @return true if VoNR is enabled else false
8793 */
8794 @Override
8795 public boolean isVoNrEnabled(int subId) {
8796 enforceReadPrivilegedPermission("isVoNrEnabled");
8797 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8798 final long identity = Binder.clearCallingIdentity();
8799 try {
8800 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8801 null, subId, workSource);
8802 if (DBG) log("isVoNrEnabled: " + isEnabled);
8803 return isEnabled;
8804 } finally {
8805 Binder.restoreCallingIdentity(identity);
8806 }
8807 }
8808
8809 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008810 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8811 * network status based on which carrier apps could apply actions accordingly,
8812 * enable/disable default url handler for example.
8813 *
8814 * @param subId the subscription ID that this action applies to.
8815 * @param report control start/stop reporting the default network status.
8816 * {@hide}
8817 */
8818 @Override
8819 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8820 enforceModifyPermission();
8821 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008822
8823 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008824 if (phone == null) {
8825 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8826 return;
8827 }
8828 try {
8829 phone.carrierActionReportDefaultNetworkStatus(report);
8830 } catch (Exception e) {
8831 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008832 } finally {
8833 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008834 }
8835 }
8836
8837 /**
fionaxud9622282017-07-17 17:51:30 -07008838 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8839 * @param subId the subscription ID that this action applies to.
8840 * {@hide}
8841 */
8842 @Override
8843 public void carrierActionResetAll(int subId) {
8844 enforceModifyPermission();
8845 final Phone phone = getPhone(subId);
8846 if (phone == null) {
8847 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8848 return;
8849 }
8850 try {
8851 phone.carrierActionResetAll();
8852 } catch (Exception e) {
8853 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8854 }
8855 }
8856
8857 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008858 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8859 * bug report is being generated.
8860 */
8861 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008862 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008863 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8864 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008865 writer.println("Permission Denial: can't dump Phone from pid="
8866 + Binder.getCallingPid()
8867 + ", uid=" + Binder.getCallingUid()
8868 + "without permission "
8869 + android.Manifest.permission.DUMP);
8870 return;
8871 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008872 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008873 }
Jack Yueb89b242016-06-22 13:27:47 -07008874
Brad Ebingerdac2f002018-04-03 15:17:52 -07008875 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008876 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8877 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8878 @NonNull String[] args) {
8879 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8880 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008881 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008882 }
8883
Jack Yueb89b242016-06-22 13:27:47 -07008884 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008885 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008886 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008887 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008888 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008889 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008890 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008891 */
8892 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008893 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008894 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008895 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8896 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8897 try {
8898 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008899 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008900 } catch (SecurityException se) {
8901 enforceModifyPermission();
8902 }
8903 } else {
8904 enforceModifyPermission();
8905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906
Nate Myrenae97d192023-06-09 15:22:31 -07008907 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
8908 && null != callingPackage && opEnableMobileDataByUser()) {
8909 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
8910 callingPackage, null, null);
8911 }
8912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913 final long identity = Binder.clearCallingIdentity();
8914 try {
8915 Phone phone = getPhone(subId);
8916 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008917 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8918 phone.carrierActionSetMeteredApnsEnabled(enabled);
8919 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008920 phone.getDataSettingsManager().setDataEnabled(
8921 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 }
8924 } finally {
8925 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008926 }
8927 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008928
8929 /**
8930 * Get Client request stats
8931 * @return List of Client Request Stats
8932 * @hide
8933 */
8934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008935 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8936 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008938 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008939 return null;
8940 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008941 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 if (phone != null) {
8946 return phone.getClientRequestStats();
8947 }
8948
8949 return null;
8950 } finally {
8951 Binder.restoreCallingIdentity(identity);
8952 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008953 }
8954
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008955 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008956 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008957 if (uid == Process.ROOT_UID && packageName == null) {
8958 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8959 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8960 // exception. ROOT_UID seems not to have a valid package name returned by
8961 // PackageManager, so just fake it here to avoid issues when running telephony shell
8962 // commands that plumb through the RIL as root, like so:
8963 // $ adb root
8964 // $ adb shell cmd phone ...
8965 packageName = "root";
8966 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008967 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008968 }
Jack Yueb4124c2017-02-16 15:32:43 -08008969
8970 /**
Grace Chen70990072017-03-24 17:21:30 -07008971 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008972 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008973 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008974 * @param state State of SIM (power down, power up, pass through)
8975 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8976 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8977 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008978 *
8979 **/
8980 @Override
Grace Chen70990072017-03-24 17:21:30 -07008981 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008982 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008983 Phone phone = PhoneFactory.getPhone(slotIndex);
8984
vagdeviaf9a5b92018-08-15 16:01:53 -07008985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008990 phone.setSimPowerState(state, null, workSource);
8991 }
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
8994 }
8995 }
8996
8997 /**
8998 * Set SIM card power state.
8999 *
9000 * @param slotIndex SIM slot id.
9001 * @param state State of SIM (power down, power up, pass through)
9002 * @param callback callback to trigger after success or failure
9003 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9004 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9005 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9006 *
9007 **/
9008 @Override
9009 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9010 IIntegerConsumer callback) {
9011 enforceModifyPermission();
9012 Phone phone = PhoneFactory.getPhone(slotIndex);
9013
9014 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9015
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 if (phone != null) {
9019 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9020 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009021 }
9022 } finally {
9023 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009024 }
9025 }
Shuo Qiandd210312017-04-12 22:11:33 +00009026
Tyler Gunn65d45c22017-06-05 11:22:26 -07009027 private boolean isUssdApiAllowed(int subId) {
9028 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009029 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009030 if (configManager == null) {
9031 return false;
9032 }
9033 PersistableBundle pb = configManager.getConfigForSubId(subId);
9034 if (pb == null) {
9035 return false;
9036 }
9037 return pb.getBoolean(
9038 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9039 }
9040
Shuo Qiandd210312017-04-12 22:11:33 +00009041 /**
Ling Mac28f0212023-03-24 16:07:15 -07009042 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009043 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009044 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009045 */
goneil9c5f4872017-12-05 14:07:56 -08009046 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009047 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009048 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 final long identity = Binder.clearCallingIdentity();
9050 try {
Ling Mac28f0212023-03-24 16:07:15 -07009051 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009052 } finally {
9053 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009054 }
9055 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009056
9057 /**
9058 * Get the current signal strength information for the given subscription.
9059 * Because this information is not updated when the device is in a low power state
9060 * it should not be relied-upon to be current.
9061 * @param subId Subscription index
9062 * @return the most recent cached signal strength info from the modem
9063 */
9064 @Override
9065 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 Phone p = getPhone(subId);
9069 if (p == null) {
9070 return null;
9071 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073 return p.getSignalStrength();
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009077 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009078
Pengquan Meng77b7f132018-08-22 14:49:57 -07009079 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009080 * Get the current modem radio state for the given slot.
9081 * @param slotIndex slot index.
9082 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009084 * @return the current radio power state from the modem
9085 */
9086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009087 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009088 Phone phone = PhoneFactory.getPhone(slotIndex);
9089 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9091 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009092 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9093 }
9094
9095 final long identity = Binder.clearCallingIdentity();
9096 try {
9097 return phone.getRadioPowerState();
9098 } finally {
9099 Binder.restoreCallingIdentity(identity);
9100 }
9101 }
9102 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9103 }
9104
9105 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009106 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9107 *
9108 * <p>Requires one of the following permissions:
9109 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009110 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009111 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9112 * privileges.
9113 *
9114 * @param subId subscription id
9115 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9116 * {@code false}.
9117 */
9118 @Override
9119 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009120 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009121 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009122 try {
9123 mApp.enforceCallingOrSelfPermission(
9124 android.Manifest.permission.ACCESS_NETWORK_STATE,
9125 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009126 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009127 mApp.enforceCallingOrSelfPermission(
9128 permission.READ_BASIC_PHONE_STATE, functionName);
9129 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009130 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009131 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009132 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009133 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009134
Pengquan Menga1bb6272018-09-06 09:59:22 -07009135 boolean isEnabled = false;
9136 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009137 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009138 Phone phone = getPhone(subId);
9139 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009140 } finally {
9141 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009143 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009144 }
9145
9146
9147 /**
9148 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9149 *
9150 * <p> Requires permission:
9151 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9152 * privileges.
9153 *
9154 * @param subId subscription id
9155 * @param isEnabled {@code true} means enable, {@code false} means disable.
9156 */
9157 @Override
9158 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9160 mApp, subId, "setDataRoamingEnabled");
9161
Pengquan Menga1bb6272018-09-06 09:59:22 -07009162 final long identity = Binder.clearCallingIdentity();
9163 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009164 Phone phone = getPhone(subId);
9165 if (phone != null) {
9166 phone.setDataRoamingEnabled(isEnabled);
9167 }
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009170 }
9171 }
9172
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009173 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009174 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009175 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009176 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009177 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009178
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009179 boolean isAllowed = true;
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009182 Phone phone = getPhone(subId);
9183 if (phone != null) {
9184 isAllowed = phone.isCspPlmnEnabled();
9185 }
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 return isAllowed;
9190 }
9191
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009192 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9193 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009194 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009195 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009196 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009197 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9198 if (phone == null) {
9199 return false;
9200 }
9201 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9202 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9203 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009204 }
9205
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009206 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009207 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009208 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009209 mApp.getSystemService(AppOpsManager.class)
9210 .checkPackage(Binder.getCallingUid(), callingPackage);
9211
Jordan Liu1e142fc2019-04-22 15:10:43 -07009212 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009213 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009214 try {
9215 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009216 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009217 } catch (SecurityException e) {
9218 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9219 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009220 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009221 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009222 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009223 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009224 }
sandeepjsb6c87872021-09-27 15:34:44 +00009225 // checking compatibility, if calling app's target SDK is T and beyond.
9226 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9227 Binder.getCallingUid())) {
9228 isIccIdAccessRestricted = true;
9229 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009230 final long identity = Binder.clearCallingIdentity();
9231 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009232 UiccController uiccController = UiccController.getInstance();
9233 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009234 if (hasReadPermission) {
9235 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009236 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009237
9238 // Remove private info if the caller doesn't have access
9239 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9240 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009241 //setting the value after compatibility check
9242 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009243 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9244 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009245 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009246 if (card == null) {
9247 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009248 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009249 continue;
9250 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009251 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9252 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009253 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009254 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009255 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009256 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9257 for (UiccPortInfo portInfo : portInfos) {
9258 UiccPort port = uiccController.getUiccPortForSlot(
9259 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9260 if (port == null) {
9261 // assume no access if port is null
9262 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9263 continue;
9264 }
9265 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9266 uiccPortInfos.add(portInfo);
9267 } else {
9268 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9269 }
9270 }
9271 filteredInfos.add(new UiccCardInfo(
9272 cardInfo.isEuicc(),
9273 cardInfo.getCardId(),
9274 null,
9275 cardInfo.getPhysicalSlotIndex(),
9276 cardInfo.isRemovable(),
9277 cardInfo.isMultipleEnabledProfilesSupported(),
9278 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009279 }
9280 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
9285
sandeepjsb6c87872021-09-27 15:34:44 +00009286 /**
9287 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9288 * generally private and require carrier privileges to view.
9289 *
9290 * @hide
9291 */
9292 @NonNull
9293 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9294 List<UiccPortInfo> portinfo = new ArrayList<>();
9295 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9296 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9297 }
9298 return new UiccCardInfo(
9299 cardInfo.isEuicc(),
9300 cardInfo.getCardId(),
9301 null,
9302 cardInfo.getPhysicalSlotIndex(),
9303 cardInfo.isRemovable(),
9304 cardInfo.isMultipleEnabledProfilesSupported(),
9305 portinfo
9306 );
9307 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009308
sandeepjsb6c87872021-09-27 15:34:44 +00009309 /**
9310 * @hide
9311 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9312 * These values are generally private and require carrier privileges to view.
9313 */
9314 @NonNull
9315 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9316 return new UiccPortInfo(
9317 UiccPortInfo.ICCID_REDACTED,
9318 portInfo.getPortIndex(),
9319 portInfo.getLogicalSlotIndex(),
9320 portInfo.isActive()
9321 );
9322 }
9323 @Override
9324 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009325 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009326 mApp.getSystemService(AppOpsManager.class)
9327 .checkPackage(Binder.getCallingUid(), callingPackage);
9328
sandeepjsb6c87872021-09-27 15:34:44 +00009329 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009330
Aman Guptaf3c90b32022-03-17 04:54:16 +00009331 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9332 // we are reading iccId which is PII data.
9333 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009334
9335 // checking compatibility, if calling app's target SDK is T and beyond.
9336 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9337 Binder.getCallingUid())) {
9338 isLogicalSlotAccessRestricted = true;
9339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009343 if (slots == null || slots.length == 0) {
9344 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009345 return null;
9346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009347 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9348 for (int i = 0; i < slots.length; i++) {
9349 UiccSlot slot = slots[i];
9350 if (slot == null) {
9351 continue;
9352 }
9353
Jordan Liu7be7e652019-05-06 18:55:02 +00009354 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009355 UiccCard card = slot.getUiccCard();
9356 if (card != null) {
9357 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009358 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009359 cardId = slot.getEid();
9360 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009361 // If cardId is null, use iccId of default port as cardId.
9362 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009364 }
9365
Jordan Liu857451f2019-05-09 16:35:35 -07009366 if (cardId != null) {
9367 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9368 // if cardId is an EID, it's all digits so this is fine
9369 cardId = IccUtils.stripTrailingFs(cardId);
9370 }
9371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009372 int cardState = 0;
9373 switch (slot.getCardState()) {
9374 case CARDSTATE_ABSENT:
9375 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9376 break;
9377 case CARDSTATE_PRESENT:
9378 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9379 break;
9380 case CARDSTATE_ERROR:
9381 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9382 break;
9383 case CARDSTATE_RESTRICTED:
9384 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9385 break;
9386 default:
9387 break;
9388
9389 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009390 List<UiccPortInfo> portInfos = new ArrayList<>();
9391 int[] portIndexes = slot.getPortList();
9392 for (int portIdx : portIndexes) {
9393 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009394 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009395 portInfos.add(new UiccPortInfo(iccId, portIdx,
9396 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009398 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009399 slot.isEuicc(),
9400 cardId,
9401 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009402 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009403 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009404 //setting the value after compatibility check
9405 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009406 }
9407 return infos;
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009410 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009411 }
9412
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009413 /* Returns null if doesn't have read permission or carrier privilege access. */
9414 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9415 boolean hasReadPermission) {
9416 String iccId = slot.getIccId(portIndex);
9417 if (hasReadPermission) { // if has read permission
9418 return iccId;
9419 } else {
9420 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9421 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9422 // if no read permission, checking carrier privilege access
9423 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9424 return iccId;
9425 }
9426 }
9427 }
9428 // No read permission or carrier privilege access.
9429 return UiccPortInfo.ICCID_REDACTED;
9430 }
9431
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009432 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009433 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009434 public boolean switchSlots(int[] physicalSlots) {
9435 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009436
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009439 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9440 for (int i = 0; i < physicalSlots.length; i++) {
9441 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9442 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9443 physicalSlots[i], i));
9444 }
9445 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009449 }
Jack Yu4c988042018-02-27 15:30:01 -08009450
9451 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009452 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9453 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9454 enforceModifyPermission();
9455
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009458 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009459 } finally {
9460 Binder.restoreCallingIdentity(identity);
9461 }
9462 }
9463
9464 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009465 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009466 final long identity = Binder.clearCallingIdentity();
9467 try {
9468 return UiccController.getInstance().getCardIdForDefaultEuicc();
9469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
Pengquan Meng85728fb2018-03-12 16:31:21 -07009474 /**
goneil47ffb6e2018-04-06 15:40:58 -07009475 * A test API to reload the UICC profile.
9476 *
9477 * <p>Requires that the calling app has permission
9478 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9479 * @hide
9480 */
9481 @Override
9482 public void refreshUiccProfile(int subId) {
9483 enforceModifyPermission();
9484
9485 final long identity = Binder.clearCallingIdentity();
9486 try {
9487 Phone phone = getPhone(subId);
9488 if (phone == null) {
9489 return;
9490 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009491 UiccPort uiccPort = phone.getUiccPort();
9492 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009493 return;
9494 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009495 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009496 if (uiccProfile == null) {
9497 return;
9498 }
9499 uiccProfile.refresh();
9500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 }
9504
9505 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009506 * Returns false if the mobile data is disabled by default, otherwise return true.
9507 */
9508 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009509 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009510 }
9511
9512 /**
9513 * Returns true if the data roaming is enabled by default, i.e the system property
9514 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9515 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9516 */
9517 private boolean getDefaultDataRoamingEnabled(int subId) {
9518 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009519 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009520 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009521 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9522 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9523 return isDataRoamingEnabled;
9524 }
9525
9526 /**
9527 * Returns the default network type for the given {@code subId}, if the default network type is
9528 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9529 */
9530 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009531 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009532 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009533 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9534 return list.get(phoneId);
9535 }
9536 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009537 }
fionaxua13278b2018-03-21 00:08:13 -07009538
9539 @Override
9540 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009541 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009543
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 final Phone phone = getPhone(subId);
9547 if (phone == null) {
9548 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9549 return;
9550 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009551 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9552 if (cpt != null) {
9553 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9554 }
9555 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009556 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9557 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009558 if (carrierPrivilegeRules == null) {
9559 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9560 } else {
9561 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009563 } finally {
9564 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009565 }
fionaxua13278b2018-03-21 00:08:13 -07009566 }
9567
9568 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009569 public void setCarrierServicePackageOverride(
9570 int subId, String carrierServicePackage, String callingPackage) {
9571 TelephonyPermissions.enforceShellOnly(
9572 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9573
Benedict Wong66477622023-02-03 23:30:57 +00009574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 final Phone phone = getPhone(subId);
9577 if (phone == null || phone.getSubId() != subId) {
9578 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9579 throw new IllegalArgumentException("No phone for subid");
9580 }
9581 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9582 if (cpt == null) {
9583 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9584 throw new IllegalStateException("No CPT for phone");
9585 }
9586 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
9589 }
9590 }
9591
9592 @Override
fionaxua13278b2018-03-21 00:08:13 -07009593 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009594 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009595
9596 final long identity = Binder.clearCallingIdentity();
9597 try {
9598 final Phone phone = getPhone(subId);
9599 if (phone == null) {
9600 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9601 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9602 }
9603 return phone.getCarrierIdListVersion();
9604 } finally {
9605 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009606 }
fionaxua13278b2018-03-21 00:08:13 -07009607 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009608
9609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009610 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9611 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009613 mApp, subId, callingPackage, callingFeatureId,
9614 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009615 return -1;
9616 }
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009625
9626 @Override
9627 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009628 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009629 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009630 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009631
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
9638 }
9639
9640 @Override
9641 public boolean setCdmaRoamingMode(int subId, int mode) {
9642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9643 mApp, subId, "setCdmaRoamingMode");
9644
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
9647 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9648 } finally {
9649 Binder.restoreCallingIdentity(identity);
9650 }
9651 }
9652
9653 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009654 public int getCdmaSubscriptionMode(int subId) {
9655 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009656 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009657 mApp, subId, "getCdmaSubscriptionMode");
9658
9659 final long identity = Binder.clearCallingIdentity();
9660 try {
9661 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009668 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9670 mApp, subId, "setCdmaSubscriptionMode");
9671
9672 final long identity = Binder.clearCallingIdentity();
9673 try {
9674 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009679
sqianc5eccab2018-10-19 18:46:41 -07009680 @Override
sqian8c685422019-02-22 15:55:18 -08009681 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009682 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009684 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9685 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009686 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9687 }
9688 final long identity = Binder.clearCallingIdentity();
9689 try {
sqian854d44b2018-12-12 16:48:18 -08009690 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9691 for (Phone phone: PhoneFactory.getPhones()) {
9692 if (phone.getEmergencyNumberTracker() != null
9693 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9694 emergencyNumberListInternal.put(
9695 phone.getSubId(),
9696 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9697 }
sqian11b7a0e2018-12-05 18:48:28 -08009698 }
sqian854d44b2018-12-12 16:48:18 -08009699 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
sqianc5eccab2018-10-19 18:46:41 -07009703 }
9704
9705 @Override
sqian8c685422019-02-22 15:55:18 -08009706 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009707 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009708 if (!exactMatch) {
9709 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009710 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009711 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009712 }
9713 final long identity = Binder.clearCallingIdentity();
9714 try {
sqian854d44b2018-12-12 16:48:18 -08009715 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009716 //Note: we ignore passed in param exactMatch. We can remove it once
9717 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009718 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009719 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009720 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009721 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009722 }
sqian11b7a0e2018-12-05 18:48:28 -08009723 }
9724 return false;
9725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
9729
sqianf4ca7ed2019-01-15 18:32:07 -08009730 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009731 * Start emergency callback mode for GsmCdmaPhone for testing.
9732 */
9733 @Override
9734 public void startEmergencyCallbackMode() {
9735 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9736 "startEmergencyCallbackMode");
9737 enforceModifyPermission();
9738 final long identity = Binder.clearCallingIdentity();
9739 try {
9740 for (Phone phone : PhoneFactory.getPhones()) {
9741 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9742 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9743 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9744 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9745 gsmCdmaPhone.obtainMessage(
9746 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9747 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9748 }
9749 }
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009756 * Update emergency number list for test mode.
9757 */
9758 @Override
9759 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9761 "updateEmergencyNumberListTestMode");
9762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 for (Phone phone: PhoneFactory.getPhones()) {
9766 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9767 if (tracker != null) {
9768 tracker.executeEmergencyNumberTestModeCommand(action, num);
9769 }
9770 }
9771 } finally {
9772 Binder.restoreCallingIdentity(identity);
9773 }
9774 }
9775
9776 /**
9777 * Get the full emergency number list for test mode.
9778 */
9779 @Override
9780 public List<String> getEmergencyNumberListTestMode() {
9781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9782 "getEmergencyNumberListTestMode");
9783
9784 final long identity = Binder.clearCallingIdentity();
9785 try {
9786 Set<String> emergencyNumbers = new HashSet<>();
9787 for (Phone phone: PhoneFactory.getPhones()) {
9788 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9789 if (tracker != null) {
9790 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9791 emergencyNumbers.add(num.getNumber());
9792 }
9793 }
9794 }
9795 return new ArrayList<>(emergencyNumbers);
9796 } finally {
9797 Binder.restoreCallingIdentity(identity);
9798 }
9799 }
9800
chen xud6b45bd2018-10-30 22:27:10 -07009801 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009802 public int getEmergencyNumberDbVersion(int subId) {
9803 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9804
9805 final long identity = Binder.clearCallingIdentity();
9806 try {
9807 final Phone phone = getPhone(subId);
9808 if (phone == null) {
9809 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9810 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9811 }
9812 return phone.getEmergencyNumberDbVersion();
9813 } finally {
9814 Binder.restoreCallingIdentity(identity);
9815 }
9816 }
9817
9818 @Override
9819 public void notifyOtaEmergencyNumberDbInstalled() {
9820 enforceModifyPermission();
9821
9822 final long identity = Binder.clearCallingIdentity();
9823 try {
9824 for (Phone phone: PhoneFactory.getPhones()) {
9825 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9826 if (tracker != null) {
9827 tracker.updateOtaEmergencyNumberDatabase();
9828 }
9829 }
9830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
9834
9835 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009836 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009837 enforceActiveEmergencySessionPermission();
9838
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
9841 for (Phone phone: PhoneFactory.getPhones()) {
9842 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9843 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009844 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9845 }
9846 }
9847 } finally {
9848 Binder.restoreCallingIdentity(identity);
9849 }
9850 }
9851
9852 @Override
9853 public void resetOtaEmergencyNumberDbFilePath() {
9854 enforceActiveEmergencySessionPermission();
9855
9856 final long identity = Binder.clearCallingIdentity();
9857 try {
9858 for (Phone phone: PhoneFactory.getPhones()) {
9859 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9860 if (tracker != null) {
9861 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009862 }
9863 }
9864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
9868
9869 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009870 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9871 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9872 Phone phone = getPhone(subId);
9873 if (phone == null) {
9874 return null;
9875 }
9876 final long identity = Binder.clearCallingIdentity();
9877 try {
9878 UiccProfile profile = UiccController.getInstance()
9879 .getUiccProfileForPhone(phone.getPhoneId());
9880 if (profile != null) {
9881 return profile.getCertsFromCarrierPrivilegeAccessRules();
9882 }
9883 } finally {
9884 Binder.restoreCallingIdentity(identity);
9885 }
9886 return null;
9887 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009888
9889 /**
9890 * Enable or disable a modem stack.
9891 */
9892 @Override
9893 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9894 enforceModifyPermission();
9895
9896 final long identity = Binder.clearCallingIdentity();
9897 try {
9898 Phone phone = PhoneFactory.getPhone(slotIndex);
9899 if (phone == null) {
9900 return false;
9901 } else {
9902 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9903 }
9904 } finally {
9905 Binder.restoreCallingIdentity(identity);
9906 }
9907 }
Michelecea4cf22018-12-21 15:00:11 -08009908
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009909 /**
9910 * Whether a modem stack is enabled or not.
9911 */
9912 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009913 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9914 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009915 Phone phone = PhoneFactory.getPhone(slotIndex);
9916 if (phone == null) return false;
9917
9918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009919 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9920 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009921 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9922 }
9923
9924 final long identity = Binder.clearCallingIdentity();
9925 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009926 try {
9927 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9928 } catch (NoSuchElementException ex) {
9929 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9930 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009931 } finally {
9932 Binder.restoreCallingIdentity(identity);
9933 }
9934 }
9935
Michelecea4cf22018-12-21 15:00:11 -08009936 @Override
Michele0ea7d782019-03-19 14:58:42 -07009937 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009938 enforceModifyPermission();
9939
9940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009943 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009944 .commit();
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
9949
9950 @Override
Michele0ea7d782019-03-19 14:58:42 -07009951 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009952 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009954 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9955 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009956 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009957 }
Michelecea4cf22018-12-21 15:00:11 -08009958
9959 final long identity = Binder.clearCallingIdentity();
9960 try {
Michele0ea7d782019-03-19 14:58:42 -07009961 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009962 } finally {
9963 Binder.restoreCallingIdentity(identity);
9964 }
9965 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009966
Michele0ea7d782019-03-19 14:58:42 -07009967 @TelephonyManager.IsMultiSimSupportedResult
9968 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009969 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9970 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9971 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009972 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9973 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009974 }
9975 // Check if the hardware supports multisim functionality. If usage of multisim is not
9976 // supported by the modem, indicate that it is restricted.
9977 PhoneCapability staticCapability =
9978 mPhoneConfigurationManager.getStaticPhoneCapability();
9979 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009980 loge("isMultiSimSupportedInternal: no static configuration available");
9981 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009982 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009983 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009984 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9985 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009986 }
9987 // Check if support of multiple SIMs is restricted by carrier
9988 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009989 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009990 }
9991
Michele0ea7d782019-03-19 14:58:42 -07009992 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009993 }
9994
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009995 /**
9996 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009997 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9998 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9999 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010000 * @param numOfSims number of active sims we want to switch to
10001 */
10002 @Override
10003 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010004 if (numOfSims == 1) {
10005 enforceModifyPermission();
10006 } else {
10007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10008 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10009 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010010 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010011
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010012 try {
Michele30b57b22019-03-01 12:01:14 -080010013 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010014 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010015 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10016 return;
10017 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010018 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10019 } finally {
10020 Binder.restoreCallingIdentity(identity);
10021 }
10022 }
10023
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010024 @Override
10025 public boolean isApplicationOnUicc(int subId, int appType) {
10026 enforceReadPrivilegedPermission("isApplicationOnUicc");
10027 Phone phone = getPhone(subId);
10028 if (phone == null) {
10029 return false;
10030 }
10031 final long identity = Binder.clearCallingIdentity();
10032 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010033 UiccPort uiccPort = phone.getUiccPort();
10034 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010035 return false;
10036 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010037 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010038 if (uiccProfile == null) {
10039 return false;
10040 }
10041 if (TelephonyManager.APPTYPE_SIM <= appType
10042 && appType <= TelephonyManager.APPTYPE_ISIM) {
10043 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10044 }
10045 return false;
10046 } finally {
10047 Binder.restoreCallingIdentity(identity);
10048 }
10049 }
10050
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010051 /**
chen xub4baa772019-04-03 10:23:41 -070010052 * Get whether making changes to modem configurations will trigger reboot.
10053 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010054 */
10055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010056 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10057 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010059 mApp, subId, callingPackage, callingFeatureId,
10060 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010061 return false;
10062 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010063 final long identity = Binder.clearCallingIdentity();
10064 try {
10065 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10066 } finally {
10067 Binder.restoreCallingIdentity(identity);
10068 }
10069 }
10070
Nathan Harold29f5f052019-02-15 13:41:57 -080010071 private void updateModemStateMetrics() {
10072 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10073 // TODO: check the state for each modem if the api is ready.
10074 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10075 }
10076
Pengquan Meng3889a572019-01-23 11:16:29 -080010077 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010078 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010079 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010080 // Verify that the callingPackage belongs to the calling UID
10081 mApp.getSystemService(AppOpsManager.class)
10082 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010083 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010084 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010085 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010086 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10087 if (slotInfos != null) {
10088 for (int i = 0; i < slotInfos.length; i++) {
10089 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10090 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10091 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10092 portInfo.getLogicalSlotIndex()));
10093 }
10094 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010095 }
10096 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010097 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010102
10103 /**
10104 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010105 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010106 */
jimsunf9ec1622022-09-13 21:18:43 +080010107 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010108 @Override
10109 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010110 return getHalVersion(HAL_SERVICE_RADIO);
10111 }
10112
10113 /**
10114 * Get the HAL Version of a specific service
10115 */
10116 @Override
10117 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010118 Phone phone = getDefaultPhone();
10119 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010120 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010121 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10122 return hv.major * 100 + hv.minor;
10123 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010124
10125 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010126 * Get the current calling package name.
10127 * @return the current calling package name
10128 */
10129 @Override
10130 public String getCurrentPackageName() {
10131 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10132 }
10133
10134 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010135 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10136 * corresponding network requests on a subId.
10137 *
10138 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010139 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010140 * 2) APN is un-metered for this subscription, or
10141 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010142 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010143 *
10144 * @return whether data is allowed for a apn type.
10145 *
10146 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010147 */
10148 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010149 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010150 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10151 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010152
10153 // Now that all security checks passes, perform the operation as ourselves.
10154 final long identity = Binder.clearCallingIdentity();
10155 try {
10156 Phone phone = getPhone(subId);
10157 if (phone == null) return false;
10158
Jack Yu27422a52022-03-21 10:38:05 -070010159 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010160 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010161 isMetered = phone.getDataNetworkController().getDataConfigManager()
10162 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10163 phone.getServiceState().getDataRoaming());
10164 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010165 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010172 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010173 enforceReadPrivilegedPermission("isApnMetered");
10174
10175 // Now that all security checks passes, perform the operation as ourselves.
10176 final long identity = Binder.clearCallingIdentity();
10177 try {
10178 Phone phone = getPhone(subId);
10179 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010180 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10181 DataUtils.apnTypeToNetworkCapability(apnType),
10182 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010183 } finally {
10184 Binder.restoreCallingIdentity(identity);
10185 }
10186 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010187
10188 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010189 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10190 int subscriptionId, IBooleanConsumer resultCallback) {
10191 enforceModifyPermission();
10192 long token = Binder.clearCallingIdentity();
10193 try {
10194 Phone phone = getPhone(subscriptionId);
10195 if (phone == null) {
10196 try {
10197 if (resultCallback != null) {
10198 resultCallback.accept(false);
10199 }
10200 } catch (RemoteException e) {
10201 // ignore
10202 }
10203 return;
10204 }
10205 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10206 Pair.create(specifiers, (x) -> {
10207 try {
10208 if (resultCallback != null) {
10209 resultCallback.accept(x);
10210 }
10211 } catch (RemoteException e) {
10212 // ignore
10213 }
10214 });
10215 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10216 } finally {
10217 Binder.restoreCallingIdentity(token);
10218 }
10219 }
10220
10221 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010222 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10223 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010224 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010225 mApp, subId, "getSystemSelectionChannels");
10226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10227 final long identity = Binder.clearCallingIdentity();
10228 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010229 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10230 if (result instanceof IllegalStateException) {
10231 throw (IllegalStateException) result;
10232 }
10233 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010234 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10235 return specifiers;
10236 } finally {
10237 Binder.restoreCallingIdentity(identity);
10238 }
10239 }
10240
10241 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010242 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010243 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010244 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010245 }
10246
10247 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010248 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10249 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010250 if (callingPackage == null) {
10251 callingPackage = getCurrentPackageName();
10252 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010253 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10254 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010255 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10256 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010257 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10258 }
10259 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10260 Intent intent = new Intent();
10261 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10262 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10263 // Bring up choose default SMS subscription dialog right now
10264 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10265 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10266 mApp.startActivity(intent);
10267 }
chen xud5ca2d52019-05-28 15:20:57 -070010268
10269 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010270 public void showSwitchToManagedProfileDialog() {
10271 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010272 try {
10273 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10274 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10275 // for work telephony.
10276 Intent intent = new Intent(Intent.ACTION_SENDTO);
10277 intent.setData(Uri.parse("smsto:"));
10278 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10279 mApp.startActivity(intent);
10280 } catch (ActivityNotFoundException e) {
10281 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10282 Intent intent = new Intent();
10283 intent.setClass(mApp, ErrorDialogActivity.class);
10284 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10285 mApp.startActivity(intent);
10286 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010287 }
10288
10289 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010290 public String getMmsUAProfUrl(int subId) {
10291 //TODO investigate if this API should require proper permission check in R b/133791609
10292 final long identity = Binder.clearCallingIdentity();
10293 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010294 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10295 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10296 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10297 return carrierUAProfUrl;
10298 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010299 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10300 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
10304 }
10305
10306 @Override
10307 public String getMmsUserAgent(int subId) {
10308 //TODO investigate if this API should require proper permission check in R b/133791609
10309 final long identity = Binder.clearCallingIdentity();
10310 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010311 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10312 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10313 if (!TextUtils.isEmpty(carrierUserAgent)) {
10314 return carrierUserAgent;
10315 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010316 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10317 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010318 } finally {
10319 Binder.restoreCallingIdentity(identity);
10320 }
10321 }
Jack Yub07d4972019-05-28 16:12:25 -070010322
10323 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010324 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10325 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010326
Jack Yub07d4972019-05-28 16:12:25 -070010327 final long identity = Binder.clearCallingIdentity();
10328 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010329 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010330 if (phone == null) return false;
10331
Ling Maf188d502022-09-16 15:22:36 -070010332 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010333 } finally {
10334 Binder.restoreCallingIdentity(identity);
10335 }
10336 }
10337
10338 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010339 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010340 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010341 enforceModifyPermission();
10342
changbettyd5c246e2019-12-24 15:40:37 +080010343 final long identity = Binder.clearCallingIdentity();
10344 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010345 Phone phone = getPhone(subscriptionId);
10346 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010347
Ling Maf188d502022-09-16 15:22:36 -070010348 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010354 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010355 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010356 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10357 * otherwise.
10358 */
10359 @Override
10360 public void setCepEnabled(boolean isCepEnabled) {
10361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10362
10363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10366 for (Phone phone : PhoneFactory.getPhones()) {
10367 Phone defaultPhone = phone.getImsPhone();
10368 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10369 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10370 ImsPhoneCallTracker imsPhoneCallTracker =
10371 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10372 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10373 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10374 + imsPhone.getMsisdn());
10375 }
10376 }
10377 } finally {
10378 Binder.restoreCallingIdentity(identity);
10379 }
10380 }
allenwtsu46dcc572020-01-08 18:24:03 +080010381
10382 /**
10383 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10384 *
10385 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10386 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10387 * before being read.
10388 */
10389 @Override
10390 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10391 isCompressed) {
10392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10393 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010394 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10395 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10396 }
10397 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010398 // ProvisioningManager can not handle ServiceSpecificException.
10399 // Throw the IllegalStateException and annotate ProvisioningManager.
10400 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010401 }
10402
10403 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010404 try {
Hui Wang761a6682020-10-31 05:12:53 +000010405 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10406 } finally {
10407 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010408 }
10409 }
zoey chene02881a2019-12-30 16:11:23 +080010410
10411 @Override
10412 public boolean isIccLockEnabled(int subId) {
10413 enforceReadPrivilegedPermission("isIccLockEnabled");
10414
10415 // Now that all security checks passes, perform the operation as ourselves.
10416 final long identity = Binder.clearCallingIdentity();
10417 try {
10418 Phone phone = getPhone(subId);
10419 if (phone != null && phone.getIccCard() != null) {
10420 return phone.getIccCard().getIccLockEnabled();
10421 } else {
10422 return false;
10423 }
10424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
10429 /**
10430 * Set the ICC pin lock enabled or disabled.
10431 *
10432 * @return an integer representing the status of IccLock enabled or disabled in the following
10433 * three cases:
10434 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10435 * successfully.
10436 * - Positive number and zero for remaining password attempts.
10437 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10438 *
10439 */
10440 @Override
10441 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10442 enforceModifyPermission();
10443
10444 Phone phone = getPhone(subId);
10445 if (phone == null) {
10446 return 0;
10447 }
10448 // Now that all security checks passes, perform the operation as ourselves.
10449 final long identity = Binder.clearCallingIdentity();
10450 try {
10451 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10452 new Pair<Boolean, String>(enabled, password), phone, null);
10453 return attemptsRemaining;
10454
10455 } catch (Exception e) {
10456 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10457 } finally {
10458 Binder.restoreCallingIdentity(identity);
10459 }
10460 return 0;
10461 }
10462
10463 /**
10464 * Change the ICC password used in ICC pin lock.
10465 *
10466 * @return an integer representing the status of IccLock changed in the following three cases:
10467 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10468 * - Positive number and zero for remaining password attempts.
10469 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10470 *
10471 */
10472 @Override
10473 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10474 enforceModifyPermission();
10475
10476 Phone phone = getPhone(subId);
10477 if (phone == null) {
10478 return 0;
10479 }
10480 // Now that all security checks passes, perform the operation as ourselves.
10481 final long identity = Binder.clearCallingIdentity();
10482 try {
10483 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10484 new Pair<String, String>(oldPassword, newPassword), phone, null);
10485 return attemptsRemaining;
10486
10487 } catch (Exception e) {
10488 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10489 } finally {
10490 Binder.restoreCallingIdentity(identity);
10491 }
10492 return 0;
10493 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010494
10495 /**
10496 * Request for receiving user activity notification
10497 */
10498 @Override
10499 public void requestUserActivityNotification() {
10500 if (!mNotifyUserActivity.get()
10501 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10502 mNotifyUserActivity.set(true);
10503 }
10504 }
10505
10506 /**
10507 * Called when userActivity is signalled in the power manager.
10508 * This is safe to call from any thread, with any window manager locks held or not.
10509 */
10510 @Override
10511 public void userActivity() {
10512 // ***************************************
10513 // * Inherited from PhoneWindowManager *
10514 // ***************************************
10515 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10516 // WITH ITS LOCKS HELD.
10517 //
10518 // This code must be VERY careful about the locks
10519 // it acquires.
10520 // In fact, the current code acquires way too many,
10521 // and probably has lurking deadlocks.
10522
10523 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10524 throw new SecurityException("Only the OS may call notifyUserActivity()");
10525 }
10526
10527 if (mNotifyUserActivity.getAndSet(false)) {
10528 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10529 USER_ACTIVITY_NOTIFICATION_DELAY);
10530 }
10531 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010532
10533 @Override
10534 public boolean canConnectTo5GInDsdsMode() {
10535 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10536 }
Jack Yud10cdd42020-09-28 20:28:01 -070010537
10538 @Override
10539 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10540 String callingFeatureId) {
10541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10542 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10543 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10544 }
10545
10546 Phone phone = getPhone(subId);
10547 if (phone == null) {
10548 throw new RuntimeException("phone is not available");
10549 }
10550 // Now that all security checks passes, perform the operation as ourselves.
10551 final long identity = Binder.clearCallingIdentity();
10552 try {
10553 return phone.getEquivalentHomePlmns();
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
Daniel Bright59e67312020-11-13 11:49:37 -080010558
10559 @Override
10560 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010561 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10562 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010563 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010564 if (radioInterfaceCapabilities == null) {
10565 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010566 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010567 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010568 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010569
Hui Wang641e81c2020-10-12 12:14:23 -070010570 @Override
10571 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10572 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010573 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10574 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10575 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10576 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10577 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010578 if (DBG) {
10579 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10580 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10581 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10582 }
10583
10584 if (!SubscriptionManager.isValidSubscriptionId(subId)
10585 || appType < TelephonyManager.APPTYPE_UNKNOWN
10586 || appType > TelephonyManager.APPTYPE_ISIM
10587 || nafUrl == null || securityProtocol == null || callback == null) {
10588 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10589 if (callback != null) {
10590 try {
10591 callback.onAuthenticationFailure(
10592 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10593 } catch (RemoteException exception) {
10594 log("Fail to notify onAuthenticationFailure due to " + exception);
10595 }
10596 return;
10597 }
10598 }
10599
10600 final long token = Binder.clearCallingIdentity();
10601 try {
10602 getGbaManager(subId).bootstrapAuthenticationRequest(
10603 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010604 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010605 } finally {
10606 Binder.restoreCallingIdentity(token);
10607 }
10608 }
10609
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010610 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010611 * Attempts to set the radio power state for all phones for thermal reason.
10612 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010613 * requested radio power state will actually be set. See {@link
10614 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10615 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010616 * @param enable {@code true} if trying to turn radio on.
10617 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10618 * false}.
10619 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010620 private boolean setRadioPowerForThermal(boolean enable) {
10621 boolean isPhoneAvailable = false;
10622 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10623 Phone phone = PhoneFactory.getPhone(i);
10624 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010625 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010626 isPhoneAvailable = true;
10627 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010628 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010629
10630 // return true if successfully informed the phone object about the thermal radio power
10631 // request.
10632 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010633 }
10634
10635 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010636 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010637 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10638 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10639 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10640 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10641 throw new IllegalArgumentException("modem does not support data throttling");
10642 }
10643
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010644 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10645 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010646 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010647 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10648 }
10649
Sarah Chinecc78c42022-03-31 21:16:48 -070010650 setDataEnabledForReason(
10651 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010652
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010653 if (isDataThrottlingSupported) {
10654 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010655 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010656 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10657 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10658 } else if (thermalMitigationResult
10659 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010660 log("Modem likely does not support data throttling on secondary carrier. Data " +
10661 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10662 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010663 }
10664 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010665 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010666
10667 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010668 }
10669
Jack Nudelman644b91a2021-03-12 14:09:48 -080010670 private static List<String> getThermalMitigationAllowlist(Context context) {
10671 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10672 for (String pckg : context.getResources()
10673 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10674 sThermalMitigationAllowlistedPackages.add(pckg);
10675 }
10676 }
10677
10678 return sThermalMitigationAllowlistedPackages;
10679 }
10680
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010681 private boolean isAnyPhoneInEmergencyState() {
10682 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10683 if (tm.isInEmergencyCall()) {
10684 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10685 return true;
10686 }
10687 for (Phone phone : PhoneFactory.getPhones()) {
10688 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10689 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010690 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10691 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010692 return true;
10693 }
10694 }
10695
10696 return false;
10697 }
10698
Jack Nudelman644b91a2021-03-12 14:09:48 -080010699 /**
10700 * Used by shell commands to add an authorized package name for thermal mitigation.
10701 * @param packageName name of package to be allowlisted
10702 * @param context
10703 */
10704 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10705 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10706 sThermalMitigationAllowlistedPackages.add(packageName);
10707 }
10708
10709 /**
10710 * Used by shell commands to remove an authorized package name for thermal mitigation.
10711 * @param packageName name of package to remove from allowlist
10712 * @param context
10713 */
10714 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10715 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10716 sThermalMitigationAllowlistedPackages.remove(packageName);
10717 }
10718
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010719 /**
10720 * Thermal mitigation request to control functionalities at modem.
10721 *
10722 * @param subId the id of the subscription.
10723 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010724 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010725 *
10726 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10727 */
10728 @Override
10729 @ThermalMitigationResult
10730 public int sendThermalMitigationRequest(
10731 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010732 ThermalMitigationRequest thermalMitigationRequest,
10733 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010734 enforceModifyPermission();
10735
Jack Nudelman644b91a2021-03-12 14:09:48 -080010736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10737 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10738 .contains(callingPackage)) {
10739 throw new SecurityException("Calling package must be configured in the device config. "
10740 + "calling package: " + callingPackage);
10741 }
10742
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10744 final long identity = Binder.clearCallingIdentity();
10745
10746 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10747 try {
10748 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10749 switch (thermalMitigationAction) {
10750 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10751 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010752 handleDataThrottlingRequest(subId,
10753 thermalMitigationRequest.getDataThrottlingRequest(),
10754 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010755 break;
10756 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10757 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10758 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10759 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10760 }
10761
10762 // Ensure that radio is on. If not able to power on due to phone being
10763 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010764 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010765 thermalMitigationResult =
10766 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10767 break;
10768 }
10769
10770 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010771 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010772 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10773 break;
10774 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10775 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10776 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10777 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10778 }
10779
10780 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10781 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010782 Phone phone = getPhone(subId);
10783 if (phone == null) {
10784 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010785 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010786 break;
10787 }
10788
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010789 TelephonyConnectionService service =
10790 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010791 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010792 Log.e(LOG_TAG, "An emergency call is pending");
10793 thermalMitigationResult =
10794 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10795 break;
10796 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010797 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010798 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010799 break;
10800 }
10801 } else {
10802 thermalMitigationResult =
10803 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10804 break;
10805 }
10806
10807 // Turn radio off. If not able to power off due to phone being unavailable,
10808 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010809 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010810 thermalMitigationResult =
10811 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10812 break;
10813 }
10814 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010815 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010816 break;
10817 default:
10818 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10819 + "not exist. Requested action: " + thermalMitigationAction);
10820 }
10821 } catch (IllegalArgumentException e) {
10822 throw e;
10823 } catch (Exception e) {
10824 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10825 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10826 } finally {
10827 Binder.restoreCallingIdentity(identity);
10828 }
10829
10830 if (DBG) {
10831 log("thermalMitigationRequest returning with thermalMitigationResult: "
10832 + thermalMitigationResult);
10833 }
10834
10835 return thermalMitigationResult;
10836 }
Hui Wang641e81c2020-10-12 12:14:23 -070010837
10838 /**
10839 * Set the GbaService Package Name that Telephony will bind to.
10840 *
10841 * @param subId The sim that the GbaService is associated with.
10842 * @param packageName The name of the package to be replaced with.
10843 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10844 */
10845 @Override
10846 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10847 enforceModifyPermission();
10848
10849 final long identity = Binder.clearCallingIdentity();
10850 try {
10851 return getGbaManager(subId).overrideServicePackage(packageName);
10852 } finally {
10853 Binder.restoreCallingIdentity(identity);
10854 }
10855 }
10856
10857 /**
10858 * Return the package name of the currently bound GbaService.
10859 *
10860 * @param subId The sim that the GbaService is associated with.
10861 * @return the package name of the GbaService configuration, null if GBA is not supported.
10862 */
10863 @Override
10864 public String getBoundGbaService(int subId) {
10865 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10866
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 return getGbaManager(subId).getServicePackage();
10870 } finally {
10871 Binder.restoreCallingIdentity(identity);
10872 }
10873 }
10874
10875 /**
10876 * Set the release time for telephony to unbind GbaService.
10877 *
10878 * @param subId The sim that the GbaService is associated with.
10879 * @param interval The release time to unbind GbaService by millisecond.
10880 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10881 */
10882 @Override
10883 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10884 enforceModifyPermission();
10885
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
10888 return getGbaManager(subId).overrideReleaseTime(interval);
10889 } finally {
10890 Binder.restoreCallingIdentity(identity);
10891 }
10892 }
10893
10894 /**
10895 * Return the release time for telephony to unbind GbaService.
10896 *
10897 * @param subId The sim that the GbaService is associated with.
10898 * @return The release time to unbind GbaService by millisecond.
10899 */
10900 @Override
10901 public int getGbaReleaseTime(int subId) {
10902 enforceReadPrivilegedPermission("getGbaReleaseTime");
10903
10904 final long identity = Binder.clearCallingIdentity();
10905 try {
10906 return getGbaManager(subId).getReleaseTime();
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
10912 private GbaManager getGbaManager(int subId) {
10913 GbaManager instance = GbaManager.getInstance(subId);
10914 if (instance == null) {
10915 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10916 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10917 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10918 }
10919 return instance;
10920 }
Hui Wang761a6682020-10-31 05:12:53 +000010921
10922 /**
10923 * indicate whether the device and the carrier can support
10924 * RCS VoLTE single registration.
10925 */
10926 @Override
10927 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010928 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10929 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10930 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10931 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010932
10933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10934 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10935 }
10936
10937 final long identity = Binder.clearCallingIdentity();
10938 try {
10939 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10940 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010941 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10942 if (isCapable != null) {
10943 return isCapable;
10944 }
Hui Wang761a6682020-10-31 05:12:53 +000010945 }
Hui Wang67af90e2021-06-04 16:57:15 -070010946 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10947 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010948 } finally {
10949 Binder.restoreCallingIdentity(identity);
10950 }
10951 }
10952
10953 /**
10954 * Register RCS provisioning callback.
10955 */
10956 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010957 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010958 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010959 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010960 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010961 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10962 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010963
10964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10965 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10966 }
10967 if (!isImsAvailableOnDevice()) {
10968 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10969 "IMS not available on device.");
10970 }
10971
10972 final long identity = Binder.clearCallingIdentity();
10973 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010974 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010975 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010976 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10977 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010978 }
Hui Wang761a6682020-10-31 05:12:53 +000010979 } finally {
10980 Binder.restoreCallingIdentity(identity);
10981 }
10982 }
10983
10984 /**
10985 * Unregister RCS provisioning callback.
10986 */
10987 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010988 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010989 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010990 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010991 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010992 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10993 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010994
10995 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10996 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10997 }
10998 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010999 // operation failed silently
11000 Rlog.w(LOG_TAG, "IMS not available on device.");
11001 return;
Hui Wang761a6682020-10-31 05:12:53 +000011002 }
11003
11004 final long identity = Binder.clearCallingIdentity();
11005 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011006 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011007 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011008 } finally {
11009 Binder.restoreCallingIdentity(identity);
11010 }
11011 }
11012
11013 /**
11014 * trigger RCS reconfiguration.
11015 */
11016 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011017 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11018 "triggerRcsReconfiguration",
11019 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011020
11021 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11022 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11023 }
11024 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011025 // ProvisioningManager can not handle ServiceSpecificException.
11026 // Throw the IllegalStateException and annotate ProvisioningManager.
11027 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011028 }
11029
11030 final long identity = Binder.clearCallingIdentity();
11031 try {
11032 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11033 } finally {
11034 Binder.restoreCallingIdentity(identity);
11035 }
11036 }
11037
11038 /**
11039 * Provide the client configuration parameters of the RCS application.
11040 */
11041 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011042 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11043 "setRcsClientConfiguration",
11044 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011045
11046 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11047 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11048 }
11049 if (!isImsAvailableOnDevice()) {
11050 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11051 "IMS not available on device.");
11052 }
11053
11054 final long identity = Binder.clearCallingIdentity();
11055
11056 try {
11057 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11058 if (configBinder == null) {
11059 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011060 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11061 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011062 } else {
11063 configBinder.setRcsClientConfiguration(rcc);
11064 }
joonhunshin3e154242021-09-17 06:33:39 +000011065
11066 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11067 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011068 } catch (RemoteException e) {
11069 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011070 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11071 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011072 } finally {
11073 Binder.restoreCallingIdentity(identity);
11074 }
11075 }
11076
11077 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011078 * Enables or disables the test mode for RCS VoLTE single registration.
11079 */
11080 @Override
11081 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11083 "setRcsSingleRegistrationTestModeEnabled");
11084
11085 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11086 }
11087
11088 /**
11089 * Gets the test mode for RCS VoLTE single registration.
11090 */
11091 @Override
11092 public boolean getRcsSingleRegistrationTestModeEnabled() {
11093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11094 "getRcsSingleRegistrationTestModeEnabled");
11095
11096 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11097 }
11098
11099 /**
Hui Wang761a6682020-10-31 05:12:53 +000011100 * Overrides the config of RCS VoLTE single registration enabled for the device.
11101 */
11102 @Override
11103 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11105 "setDeviceSingleRegistrationEnabledOverride");
11106 enforceModifyPermission();
11107
11108 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11109 : Boolean.parseBoolean(enabledStr);
11110 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011111 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011112 }
11113
11114 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011115 * Sends a device to device communication message. Only usable via shell.
11116 * @param message message to send.
11117 * @param value message value.
11118 */
11119 @Override
11120 public void sendDeviceToDeviceMessage(int message, int value) {
11121 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011122 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011123 enforceModifyPermission();
11124
11125 final long identity = Binder.clearCallingIdentity();
11126 try {
11127 TelephonyConnectionService service =
11128 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11129 if (service == null) {
11130 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11131 return;
11132 }
11133 service.sendTestDeviceToDeviceMessage(message, value);
11134 } finally {
11135 Binder.restoreCallingIdentity(identity);
11136 }
11137 }
11138
Tyler Gunnbabbda02021-02-10 11:05:02 -080011139 /**
11140 * Sets the specified device to device transport active.
11141 * @param transport The transport to set active.
11142 */
11143 @Override
11144 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11146 "setActiveDeviceToDeviceTransport");
11147 enforceModifyPermission();
11148
11149 final long identity = Binder.clearCallingIdentity();
11150 try {
11151 TelephonyConnectionService service =
11152 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11153 if (service == null) {
11154 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11155 return;
11156 }
11157 service.setActiveDeviceToDeviceTransport(transport);
11158 } finally {
11159 Binder.restoreCallingIdentity(identity);
11160 }
11161 }
Tyler Gunn92479152021-01-20 16:30:10 -080011162
Tyler Gunnd4339262021-05-03 14:46:49 -070011163 @Override
11164 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11166 "setDeviceToDeviceForceEnabled");
11167
11168 final long identity = Binder.clearCallingIdentity();
11169 try {
11170 Arrays.stream(PhoneFactory.getPhones()).forEach(
11171 p -> {
11172 Phone thePhone = p.getImsPhone();
11173 if (thePhone != null && thePhone instanceof ImsPhone) {
11174 ImsPhone imsPhone = (ImsPhone) thePhone;
11175 CallTracker tracker = imsPhone.getCallTracker();
11176 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11177 ImsPhoneCallTracker imsPhoneCallTracker =
11178 (ImsPhoneCallTracker) tracker;
11179 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11180 }
11181 }
11182 }
11183 );
11184 } finally {
11185 Binder.restoreCallingIdentity(identity);
11186 }
11187 }
11188
Tyler Gunn92479152021-01-20 16:30:10 -080011189 /**
Hui Wang761a6682020-10-31 05:12:53 +000011190 * Gets the config of RCS VoLTE single registration enabled for the device.
11191 */
11192 @Override
11193 public boolean getDeviceSingleRegistrationEnabled() {
11194 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11195 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11196 }
11197
11198 /**
11199 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11200 */
11201 @Override
11202 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11203 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11204 "setCarrierSingleRegistrationEnabledOverride");
11205 enforceModifyPermission();
11206
11207 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11208 : Boolean.parseBoolean(enabledStr);
11209 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11210 subId, enabled);
11211 }
11212
11213 /**
11214 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11215 */
11216 @Override
11217 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11218 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11219 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11220 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011221
11222 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011223 * Overrides the ims feature validation result
11224 */
11225 @Override
11226 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11227 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11228 "setImsFeatureValidationOverride");
11229
11230 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11231 : Boolean.parseBoolean(enabledStr);
11232 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11233 subId, enabled);
11234 }
11235
11236 /**
11237 * Gets the ims feature validation override value
11238 */
11239 @Override
11240 public boolean getImsFeatureValidationOverride(int subId) {
11241 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11242 "getImsFeatureValidationOverride");
11243 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11244 }
11245
11246 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011247 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11248 * their mobile plan.
11249 */
11250 @Override
11251 public String getMobileProvisioningUrl() {
11252 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 return getDefaultPhone().getMobileProvisioningUrl();
11256 } finally {
11257 Binder.restoreCallingIdentity(identity);
11258 }
11259 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011260
James.cf Linbcdf8b32021-01-14 16:44:13 +080011261 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011262 * Get the EAB contact from the EAB database.
11263 */
11264 @Override
11265 public String getContactFromEab(String contact) {
11266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11267 enforceModifyPermission();
11268 final long identity = Binder.clearCallingIdentity();
11269 try {
11270 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11271 } finally {
11272 Binder.restoreCallingIdentity(identity);
11273 }
11274 }
11275
11276 /**
Calvin Pana1434322021-07-01 19:27:01 +080011277 * Get the EAB capability from the EAB database.
11278 */
11279 @Override
11280 public String getCapabilityFromEab(String contact) {
11281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11282 enforceModifyPermission();
11283 final long identity = Binder.clearCallingIdentity();
11284 try {
11285 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11286 } finally {
11287 Binder.restoreCallingIdentity(identity);
11288 }
11289 }
11290
11291 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011292 * Remove the EAB contacts from the EAB database.
11293 */
11294 @Override
11295 public int removeContactFromEab(int subId, String contacts) {
11296 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11297 enforceModifyPermission();
11298 final long identity = Binder.clearCallingIdentity();
11299 try {
11300 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11301 } finally {
11302 Binder.restoreCallingIdentity(identity);
11303 }
11304 }
11305
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011306 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011307 public boolean getDeviceUceEnabled() {
11308 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11309 final long identity = Binder.clearCallingIdentity();
11310 try {
11311 return mApp.getDeviceUceEnabled();
11312 } finally {
11313 Binder.restoreCallingIdentity(identity);
11314 }
11315 }
11316
11317 @Override
11318 public void setDeviceUceEnabled(boolean isEnabled) {
11319 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11320 final long identity = Binder.clearCallingIdentity();
11321 try {
11322 mApp.setDeviceUceEnabled(isEnabled);
11323 } finally {
11324 Binder.restoreCallingIdentity(identity);
11325 }
11326 }
11327
Brad Ebinger14d467f2021-02-12 06:18:28 +000011328 /**
11329 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11330 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11331 */
11332 // Used for SHELL command only right now.
11333 @Override
11334 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11335 List<String> featureTags) {
11336 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11337 "addUceRegistrationOverrideShell");
11338 final long identity = Binder.clearCallingIdentity();
11339 try {
11340 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11341 new ArraySet<>(featureTags));
11342 } catch (ImsException e) {
11343 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11344 } finally {
11345 Binder.restoreCallingIdentity(identity);
11346 }
11347 }
11348
11349 /**
11350 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11351 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11352 */
11353 // Used for SHELL command only right now.
11354 @Override
11355 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11356 List<String> featureTags) {
11357 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11358 "removeUceRegistrationOverrideShell");
11359 final long identity = Binder.clearCallingIdentity();
11360 try {
11361 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11362 new ArraySet<>(featureTags));
11363 } catch (ImsException e) {
11364 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11365 } finally {
11366 Binder.restoreCallingIdentity(identity);
11367 }
11368 }
11369
11370 /**
11371 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11372 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11373 */
11374 // Used for SHELL command only right now.
11375 @Override
11376 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11378 "clearUceRegistrationOverrideShell");
11379 final long identity = Binder.clearCallingIdentity();
11380 try {
11381 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11382 } catch (ImsException e) {
11383 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11384 } finally {
11385 Binder.restoreCallingIdentity(identity);
11386 }
11387 }
11388
11389 /**
11390 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11391 */
11392 // Used for SHELL command only right now.
11393 @Override
11394 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11395 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11396 "getLatestRcsContactUceCapabilityShell");
11397 final long identity = Binder.clearCallingIdentity();
11398 try {
11399 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11400 } catch (ImsException e) {
11401 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11402 } finally {
11403 Binder.restoreCallingIdentity(identity);
11404 }
11405 }
11406
11407 /**
11408 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11409 * device does not have an active PUBLISH.
11410 */
11411 // Used for SHELL command only right now.
11412 @Override
11413 public String getLastUcePidfXmlShell(int subId) {
11414 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11415 final long identity = Binder.clearCallingIdentity();
11416 try {
11417 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11418 } catch (ImsException e) {
11419 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11420 } finally {
11421 Binder.restoreCallingIdentity(identity);
11422 }
11423 }
11424
James.cf Line8713a42021-04-29 16:04:26 +080011425 /**
11426 * Remove UCE requests cannot be sent to the network status.
11427 */
11428 // Used for SHELL command only right now.
11429 @Override
11430 public boolean removeUceRequestDisallowedStatus(int subId) {
11431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11432 final long identity = Binder.clearCallingIdentity();
11433 try {
11434 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11435 } catch (ImsException e) {
11436 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11437 } finally {
11438 Binder.restoreCallingIdentity(identity);
11439 }
11440 }
11441
James.cf Lin18bb9002021-05-25 01:37:38 +080011442 /**
11443 * Remove UCE requests cannot be sent to the network status.
11444 */
11445 // Used for SHELL command only.
11446 @Override
11447 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11448 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11449 final long identity = Binder.clearCallingIdentity();
11450 try {
11451 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11452 } catch (ImsException e) {
11453 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11454 } finally {
11455 Binder.restoreCallingIdentity(identity);
11456 }
11457 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011458
James.cf Lin4b784aa2021-01-31 03:25:15 +080011459 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011460 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11461 String callingPackage) {
11462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11463 mApp, subId, "setSignalStrengthUpdateRequest");
11464
11465 final int callingUid = Binder.getCallingUid();
11466 // Verify that tha callingPackage belongs to the calling UID
11467 mApp.getSystemService(AppOpsManager.class)
11468 .checkPackage(callingUid, callingPackage);
11469
Rambo Wang3607f502021-02-01 21:51:40 -080011470 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011471
11472 final long identity = Binder.clearCallingIdentity();
11473 try {
11474 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11475 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11476
11477 if (result instanceof IllegalStateException) {
11478 throw (IllegalStateException) result;
11479 }
11480 } finally {
11481 Binder.restoreCallingIdentity(identity);
11482 }
11483 }
11484
11485 @Override
11486 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11487 String callingPackage) {
11488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11489 mApp, subId, "clearSignalStrengthUpdateRequest");
11490
11491 final int callingUid = Binder.getCallingUid();
11492 // Verify that tha callingPackage belongs to the calling UID
11493 mApp.getSystemService(AppOpsManager.class)
11494 .checkPackage(callingUid, callingPackage);
11495
11496 final long identity = Binder.clearCallingIdentity();
11497 try {
11498 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11499 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11500
11501 if (result instanceof IllegalStateException) {
11502 throw (IllegalStateException) result;
11503 }
11504 } finally {
11505 Binder.restoreCallingIdentity(identity);
11506 }
11507 }
11508
Rambo Wang3607f502021-02-01 21:51:40 -080011509 private static void validateSignalStrengthUpdateRequest(Context context,
11510 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011511 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11512 // phone/system process do not have further restriction on request
11513 return;
11514 }
11515
11516 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011517 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011518 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011519 context.enforceCallingOrSelfPermission(
11520 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11521 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011522 }
11523
11524 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011525 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011526 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011527 || info.isEnabled()) {
11528 throw new IllegalArgumentException(
11529 "Only system can set hide fields in SignalThresholdInfo");
11530 }
11531
11532 // Thresholds length for each RAN need in range. This has been validated in
11533 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11534 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11535 final int[] thresholds = info.getThresholds();
11536 Objects.requireNonNull(thresholds);
11537 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11538 || thresholds.length
11539 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11540 throw new IllegalArgumentException(
11541 "thresholds length is out of range: " + thresholds.length);
11542 }
11543 }
11544 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011545
11546 /**
11547 * Gets the current phone capability.
11548 *
11549 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11550 * @return the PhoneCapability which describes the data connection capability of modem.
11551 * It's used to evaluate possible phone config change, for example from single
11552 * SIM device to multi-SIM device.
11553 */
11554 @Override
11555 public PhoneCapability getPhoneCapability() {
11556 enforceReadPrivilegedPermission("getPhoneCapability");
11557 final long identity = Binder.clearCallingIdentity();
11558 try {
11559 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11560 } finally {
11561 Binder.restoreCallingIdentity(identity);
11562 }
11563 }
Michele Berionne5e411512020-11-13 02:36:59 +000011564
11565 /**
11566 * Prepare TelephonyManager for an unattended reboot. The reboot is
11567 * required to be done shortly after the API is invoked.
11568 */
11569 @Override
11570 @TelephonyManager.PrepareUnattendedRebootResult
11571 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011572 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011573 enforceRebootPermission();
11574
11575 final long identity = Binder.clearCallingIdentity();
11576 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011577 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011578 } finally {
11579 Binder.restoreCallingIdentity(identity);
11580 }
11581 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011582
11583 /**
11584 * Request to get the current slicing configuration including URSP rules and
11585 * NSSAIs (configured, allowed and rejected).
11586 *
11587 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11588 */
11589 @Override
11590 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011591 TelephonyPermissions
11592 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11593 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011594
11595 final long identity = Binder.clearCallingIdentity();
11596 try {
11597 Phone phone = getDefaultPhone();
11598 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11599 } finally {
11600 Binder.restoreCallingIdentity(identity);
11601 }
11602 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011603
11604 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011605 * Check whether the given premium capability is available for purchase from the carrier.
11606 *
11607 * @param capability The premium capability to check.
11608 * @param subId The subId to check the premium capability for.
11609 *
11610 * @return Whether the given premium capability is available to purchase.
11611 */
11612 @Override
11613 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11614 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11615 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11616 log("Premium capability "
11617 + TelephonyManager.convertPremiumCapabilityToString(capability)
11618 + " is not available for purchase due to missing permissions.");
11619 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11620 + "permission READ_BASIC_PHONE_STATE.");
11621 }
11622
11623 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011624 if (phone == null) {
11625 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11626 return false;
11627 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011628 final long identity = Binder.clearCallingIdentity();
11629 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011630 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011631 .isPremiumCapabilityAvailableForPurchase(capability);
11632 } finally {
11633 Binder.restoreCallingIdentity(identity);
11634 }
11635 }
11636
11637 /**
11638 * Purchase the given premium capability from the carrier.
11639 *
11640 * @param capability The premium capability to purchase.
11641 * @param callback The result of the purchase request.
11642 * @param subId The subId to purchase the premium capability for.
11643 */
11644 @Override
11645 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11646 log("purchasePremiumCapability: capability="
11647 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11648 + getCurrentPackageName());
11649
11650 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11651 mApp, "purchasePremiumCapability")) {
11652 log("purchasePremiumCapability "
11653 + TelephonyManager.convertPremiumCapabilityToString(capability)
11654 + " failed due to missing permissions.");
11655 throw new SecurityException("purchasePremiumCapability requires permission "
11656 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011657 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11658 mApp, "purchasePremiumCapability")) {
11659 log("purchasePremiumCapability "
11660 + TelephonyManager.convertPremiumCapabilityToString(capability)
11661 + " failed due to missing permissions.");
11662 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011663 }
11664
11665 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011666 if (phone == null) {
11667 try {
11668 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11669 callback.accept(result);
11670 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11671 } catch (RemoteException e) {
11672 String logStr = "Purchase premium capability "
11673 + TelephonyManager.convertPremiumCapabilityToString(capability)
11674 + " failed due to RemoteException handling null phone: " + e;
11675 if (DBG) log(logStr);
11676 AnomalyReporter.reportAnomaly(
11677 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11678 }
11679 return;
11680 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011681
11682 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011683 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011684 callingProcess = mApp.getPackageManager().getApplicationInfo(
11685 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011686 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011687 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011688 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011689
11690 boolean isVisible = false;
11691 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11692 if (am != null) {
11693 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11694 if (processes != null) {
11695 for (ActivityManager.RunningAppProcessInfo process : processes) {
11696 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011697 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011698 if (process.processName.equals(callingProcess) && process.importance
11699 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11700 isVisible = true;
11701 break;
11702 }
11703 }
11704 }
11705 }
11706
11707 if (!isVisible) {
11708 try {
11709 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11710 callback.accept(result);
11711 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11712 } catch (RemoteException e) {
11713 String logStr = "Purchase premium capability "
11714 + TelephonyManager.convertPremiumCapabilityToString(capability)
11715 + " failed due to RemoteException handling background application: " + e;
11716 if (DBG) log(logStr);
11717 AnomalyReporter.reportAnomaly(
11718 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11719 }
11720 return;
11721 }
11722
Sarah Chin71b3a852022-09-28 15:54:19 -070011723 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011724 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011725 }
11726
11727 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011728 * Register an IMS connection state callback
11729 */
11730 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011731 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11732 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011733 if (feature == ImsFeature.FEATURE_MMTEL) {
11734 // ImsMmTelManager
11735 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11736 TelephonyPermissions
11737 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11738 mApp, subId, "registerImsStateCallback");
11739 } else if (feature == ImsFeature.FEATURE_RCS) {
11740 // ImsRcsManager or SipDelegateManager
11741 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11742 Binder.getCallingUid(), "registerImsStateCallback",
11743 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11744 Manifest.permission.READ_PRECISE_PHONE_STATE,
11745 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11746 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11747 }
11748
11749 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11751 "IMS not available on device.");
11752 }
11753
11754 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11755 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11756 }
11757
11758 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11759 if (controller == null) {
11760 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11761 "IMS not available on device.");
11762 }
11763
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011764 if (callingPackage == null) {
11765 callingPackage = getCurrentPackageName();
11766 }
11767
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011768 final long token = Binder.clearCallingIdentity();
11769 try {
11770 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011771 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011772 } catch (ImsException e) {
11773 throw new ServiceSpecificException(e.getCode());
11774 } finally {
11775 Binder.restoreCallingIdentity(token);
11776 }
11777 }
11778
11779 /**
11780 * Unregister an IMS connection state callback
11781 */
11782 @Override
11783 public void unregisterImsStateCallback(IImsStateCallback cb) {
11784 final long token = Binder.clearCallingIdentity();
11785 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11786 if (controller == null) {
11787 return;
11788 }
11789 try {
11790 controller.unregisterImsStateCallback(cb);
11791 } finally {
11792 Binder.restoreCallingIdentity(token);
11793 }
11794 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011795
11796 /**
11797 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11798 *
11799 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11800 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11801 * SecurityException.
11802 * If there is current registered network this value will be same as the registered cell
11803 * identity. If the device goes out of service the previous cell identity is cached and
11804 * will be returned. If the cache age of the Cell identity is more than 24 hours
11805 * it will be cleared and null will be returned.
11806 *
11807 */
11808 @Override
11809 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11810 String callingFeatureId) {
11811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11812 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11813 LocationAccessPolicy.checkLocationPermission(mApp,
11814 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11815 .setCallingPackage(callingPackage)
11816 .setCallingFeatureId(callingFeatureId)
11817 .setCallingPid(Binder.getCallingPid())
11818 .setCallingUid(Binder.getCallingUid())
11819 .setMethod("getLastKnownCellIdentity")
11820 .setLogAsInfo(true)
11821 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11822 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11823 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11824 .build());
11825
11826 boolean hasFinePermission =
11827 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11828 if (!hasFinePermission
11829 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11830 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011831 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011832 }
11833
11834 final long identity = Binder.clearCallingIdentity();
11835 try {
Ling Mac28f0212023-03-24 16:07:15 -070011836 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011837 if (sst == null) return null;
11838 return sst.getLastKnownCellIdentity();
11839 } finally {
11840 Binder.restoreCallingIdentity(identity);
11841 }
11842 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011843
jimsun3b9ccac2021-10-26 15:01:23 +080011844 /**
11845 * Sets the modem service class Name that Telephony will bind to.
11846 *
11847 * @param serviceName The class name of the modem service.
11848 * @return true if the operation is succeed, otherwise false.
11849 */
11850 public boolean setModemService(String serviceName) {
11851 Log.d(LOG_TAG, "setModemService - " + serviceName);
11852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011854 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11855 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011856 return mPhoneConfigurationManager.setModemService(serviceName);
11857 }
11858
11859 /**
11860 * Return the class name of the currently bounded modem service.
11861 *
11862 * @return the class name of the modem service.
11863 */
11864 public String getModemService() {
11865 String result;
11866 Log.d(LOG_TAG, "getModemService");
11867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11868 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011869 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011870 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11871 "getModemService");
11872 result = mPhoneConfigurationManager.getModemService();
11873 Log.d(LOG_TAG, "result = " + result);
11874 return result;
11875 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011876
11877 @Override
11878 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11879 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11880 mApp.enforceCallingOrSelfPermission(
11881 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11882 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11883
11884 final long identity = Binder.clearCallingIdentity();
11885 try {
11886 Phone phone = getPhone(subId);
11887 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011888 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11889 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011890 phone.setVoiceServiceStateOverride(hasService);
11891 } finally {
11892 Binder.restoreCallingIdentity(identity);
11893 }
11894 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011895
11896 /**
11897 * set removable eSIM as default eUICC.
11898 *
11899 * @hide
11900 */
11901 @Override
11902 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11903 enforceModifyPermission();
11904 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11905
11906 final long identity = Binder.clearCallingIdentity();
11907 try {
11908 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11909 } finally {
11910 Binder.restoreCallingIdentity(identity);
11911 }
11912 }
11913
11914 /**
11915 * Returns whether the removable eSIM is default eUICC or not.
11916 *
11917 * @hide
11918 */
11919 @Override
11920 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11921 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11923
11924 final long identity = Binder.clearCallingIdentity();
11925 try {
11926 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11927 } finally {
11928 Binder.restoreCallingIdentity(identity);
11929 }
11930 }
11931
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011932 /**
11933 * Get the component name of the default app to direct respond-via-message intent for the
11934 * user associated with this subscription, update the cache if there is no respond-via-message
11935 * application currently configured for this user.
11936 * @return component name of the app and class to direct Respond Via Message intent to, or
11937 * {@code null} if the functionality is not supported.
11938 * @hide
11939 */
11940 @Override
11941 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11942 boolean updateIfNeeded) {
11943 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011944
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011945 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11946
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011947 UserHandle userHandle = null;
11948 final long identity = Binder.clearCallingIdentity();
11949 try {
11950 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11951 } finally {
11952 Binder.restoreCallingIdentity(identity);
11953 }
11954 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11955 updateIfNeeded, userHandle);
11956 }
Jack Yuf5badd92022-12-08 00:50:53 -080011957
11958 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011959 * Set whether the device is able to connect with null ciphering or integrity
11960 * algorithms. This is a global setting and will apply to all active subscriptions
11961 * and all new subscriptions after this.
11962 *
11963 * @param enabled when true, null cipher and integrity algorithms are allowed.
11964 * @hide
11965 */
11966 @Override
11967 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11968 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11969 enforceModifyPermission();
11970 checkForNullCipherAndIntegritySupport();
11971
11972 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11973 // for listening to these preference changes and applying them immediately.
11974 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11975 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11976 editor.apply();
11977
11978 for (Phone phone: PhoneFactory.getPhones()) {
11979 phone.handleNullCipherEnabledChange();
11980 }
11981 }
11982
11983
11984 /**
11985 * Get whether the device is able to connect with null ciphering or integrity
11986 * algorithms. Note that this retrieves the phone-global preference and not
11987 * the state of the radio.
11988 *
11989 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11990 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11991 * version for this feature.
11992 * @hide
11993 */
11994 @Override
11995 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11996 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11997 enforceReadPermission();
11998 checkForNullCipherAndIntegritySupport();
11999 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12000 }
12001
12002 private void checkForNullCipherAndIntegritySupport() {
12003 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12004 throw new UnsupportedOperationException(
12005 "Null cipher and integrity operations require HAL 2.1 or above");
12006 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012007 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12008 throw new UnsupportedOperationException(
12009 "Null cipher and integrity operations unsupported by modem");
12010 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012011 }
12012
Gil Cukierman06403e12023-11-29 16:33:03 +000012013 private void checkForIdentifierDisclosureNotificationSupport() {
12014 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12015 throw new UnsupportedOperationException(
12016 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12017 + "above");
12018 }
12019 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12020 throw new UnsupportedOperationException(
12021 "Cellular identifier disclosure transparency operations unsupported by modem");
12022 }
12023 }
12024
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012025 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012026 * Get the SIM state for the slot index.
12027 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12028 *
12029 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12030 */
12031 @Override
12032 @SimState
12033 public int getSimStateForSlotIndex(int slotIndex) {
12034 IccCardConstants.State simState;
12035 if (slotIndex < 0) {
12036 simState = IccCardConstants.State.UNKNOWN;
12037 } else {
12038 Phone phone = null;
12039 try {
12040 phone = PhoneFactory.getPhone(slotIndex);
12041 } catch (IllegalStateException e) {
12042 // ignore
12043 }
12044 if (phone == null) {
12045 simState = IccCardConstants.State.UNKNOWN;
12046 } else {
12047 IccCard icc = phone.getIccCard();
12048 if (icc == null) {
12049 simState = IccCardConstants.State.UNKNOWN;
12050 } else {
12051 simState = icc.getState();
12052 }
12053 }
12054 }
12055 return simState.ordinal();
12056 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012057
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012058 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12059 boolean enableLogcat,
12060 long logcatStartTimestampMillis, boolean enableTelecomDump,
12061 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012062 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12063 TelephonyManager.EmergencyCallDiagnosticParams edp =
12064 new TelephonyManager.EmergencyCallDiagnosticParams();
12065 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12066 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12067 edp.setTelecomDumpSysCollection(enableTelecomDump);
12068 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12069 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12070 Executors.newCachedThreadPool(), db,
12071 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12072 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012073 }
12074
12075 /**
12076 * Request telephony to persist state for debugging emergency call failures.
12077 *
12078 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12079 * @param enableLogcat whether to collect logcat output
12080 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12081 * @param enableTelecomDump whether to collect telecom dumpsys
12082 * @param enableTelephonyDump whether to collect telephony dumpsys
12083 */
12084 @Override
12085 @RequiresPermission(android.Manifest.permission.DUMP)
12086 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12087 long logcatStartTimestampMillis, boolean enableTelecomDump,
12088 boolean enableTelephonyDump) {
12089 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12090 "persistEmergencyCallDiagnosticData");
12091 final long identity = Binder.clearCallingIdentity();
12092 try {
12093 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12094 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12095
12096 } finally {
12097 Binder.restoreCallingIdentity(identity);
12098 }
12099 }
12100
Hui Wang9b5793a2022-12-05 14:38:06 -060012101 /**
12102 * Get current cell broadcast ranges.
12103 */
12104 @Override
12105 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12106 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12107 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12108 "getCellBroadcastIdRanges");
12109 final long identity = Binder.clearCallingIdentity();
12110 try {
12111 return getPhone(subId).getCellBroadcastIdRanges();
12112 } finally {
12113 Binder.restoreCallingIdentity(identity);
12114 }
12115 }
12116
12117 /**
12118 * Set reception of cell broadcast messages with the list of the given ranges
12119 *
12120 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12121 */
12122 @Override
12123 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12124 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12125 @Nullable IIntegerConsumer callback) {
12126 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12127 "setCellBroadcastIdRanges");
12128 final long identity = Binder.clearCallingIdentity();
12129 try {
12130 Phone phone = getPhoneFromSubId(subId);
12131 if (DBG) {
12132 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12133 }
12134 phone.setCellBroadcastIdRanges(ranges, result -> {
12135 if (callback != null) {
12136 try {
12137 callback.accept(result);
12138 } catch (RemoteException e) {
12139 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12140 }
12141 }
12142 });
12143 } finally {
12144 Binder.restoreCallingIdentity(identity);
12145 }
12146 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012147
12148 /**
12149 * Returns whether the device supports the domain selection service.
12150 *
12151 * @return {@code true} if the device supports the domain selection service.
12152 */
12153 @Override
12154 public boolean isDomainSelectionSupported() {
12155 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12156 "isDomainSelectionSupported");
12157
12158 final long identity = Binder.clearCallingIdentity();
12159 try {
12160 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12161 } finally {
12162 Binder.restoreCallingIdentity(identity);
12163 }
12164 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012165
12166 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012167 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12168 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12169 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012170 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012171 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012172 * @param enableSatellite {@code true} to enable the satellite modem and
12173 * {@code false} to disable.
12174 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12175 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012176 *
12177 * @throws SecurityException if the caller doesn't have the required permission.
12178 */
12179 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012180 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12181 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012182 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012183 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12184 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012185 }
12186
12187 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012188 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012189 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012190 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012191 * @param result The result receiver that returns whether the satellite modem is enabled
12192 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012193 *
12194 * @throws SecurityException if the caller doesn't have the required permission.
12195 */
12196 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012197 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12198 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012199 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012200 }
12201
12202 /**
Sarah Chin43457982023-02-15 17:50:38 -080012203 * Request to get whether the satellite service demo mode is enabled.
12204 *
12205 * @param subId The subId of the subscription to check whether the satellite demo mode
12206 * is enabled for.
12207 * @param result The result receiver that returns whether the satellite demo mode is enabled
12208 * if the request is successful or an error code if the request failed.
12209 *
12210 * @throws SecurityException if the caller doesn't have the required permission.
12211 */
12212 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012213 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12214 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12215 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012216 }
12217
12218 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012219 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012220 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012221 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012222 * @param result The result receiver that returns whether the satellite service is supported on
12223 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012224 */
12225 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012226 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012227 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012228 }
12229
12230 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012231 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012232 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012233 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012234 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12235 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012236 *
12237 * @throws SecurityException if the caller doesn't have required permission.
12238 */
12239 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012240 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12241 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012242 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012243 }
12244
12245 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012246 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012247 * This can be called by the pointing UI when the user starts pointing to the satellite.
12248 * Modem should continue to report the pointing input as the device or satellite moves.
12249 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012250 * @param subId The subId of the subscription to start satellite transmission updates for.
12251 * @param resultCallback The callback to get the result of the request.
12252 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012253 *
12254 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012255 */
12256 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012257 public void startSatelliteTransmissionUpdates(int subId,
12258 @NonNull IIntegerConsumer resultCallback,
12259 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12260 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12261 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012262 }
12263
12264 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012265 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012266 * This can be called by the pointing UI when the user stops pointing to the satellite.
12267 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012268 * @param subId The subId of the subscription to stop satellite transmission updates for.
12269 * @param resultCallback The callback to get the result of the request.
12270 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12271 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012272 *
12273 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012274 */
12275 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012276 public void stopSatelliteTransmissionUpdates(int subId,
12277 @NonNull IIntegerConsumer resultCallback,
12278 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12279 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12280 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012281 }
12282
12283 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012284 * Register the subscription with a satellite provider.
12285 * This is needed to register the subscription if the provider allows dynamic registration.
12286 *
12287 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012288 * @param token The token to be used as a unique identifier for provisioning with satellite
12289 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012290 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012291 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012292 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012293 * @return The signal transport used by the caller to cancel the provision request,
12294 * or {@code null} if the request failed.
12295 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012296 * @throws SecurityException if the caller doesn't have the required permission.
12297 */
12298 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012299 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012300 @NonNull String token, @NonNull byte[] provisionData,
12301 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012302 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012303 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12304 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012305 }
12306
12307 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012308 * Unregister the device/subscription with the satellite provider.
12309 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012310 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012311 * should report as deprovisioned.
12312 *
12313 * @param subId The subId of the subscription to be deprovisioned.
12314 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012315 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012316 *
12317 * @throws SecurityException if the caller doesn't have the required permission.
12318 */
12319 @Override
12320 public void deprovisionSatelliteService(int subId,
12321 @NonNull String token, @NonNull IIntegerConsumer callback) {
12322 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012323 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012324 }
12325
12326 /**
Sarah Chin43457982023-02-15 17:50:38 -080012327 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012328 *
Sarah Chin43457982023-02-15 17:50:38 -080012329 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012330 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012331 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012332 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012333 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012334 * @throws SecurityException if the caller doesn't have the required permission.
12335 */
12336 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012337 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12338 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012339 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012340 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012341 }
12342
12343 /**
Sarah Chin43457982023-02-15 17:50:38 -080012344 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012345 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012346 *
Sarah Chin43457982023-02-15 17:50:38 -080012347 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012348 * @param callback The callback that was passed to
12349 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012350 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012351 * @throws SecurityException if the caller doesn't have the required permission.
12352 */
12353 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012354 public void unregisterForSatelliteProvisionStateChanged(
12355 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012356 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012357 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012358 }
12359
12360 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012361 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012362 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012363 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012364 * @param result The result receiver that returns whether the device is provisioned with a
12365 * satellite provider if the request is successful or an error code if the
12366 * request failed.
12367 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012368 * @throws SecurityException if the caller doesn't have the required permission.
12369 */
12370 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012371 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12372 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012373 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012374 }
12375
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012376 /**
Sarah Chin43457982023-02-15 17:50:38 -080012377 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012378 *
Sarah Chin43457982023-02-15 17:50:38 -080012379 * @param subId The subId of the subscription to register for satellite modem state changed.
12380 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012381 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012382 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012383 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012384 * @throws SecurityException if the caller doesn't have the required permission.
12385 */
12386 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012387 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012388 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012389 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012390 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012391 }
12392
12393 /**
Sarah Chin43457982023-02-15 17:50:38 -080012394 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012395 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012396 *
Sarah Chin43457982023-02-15 17:50:38 -080012397 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012398 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012399 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012400 *
12401 * @throws SecurityException if the caller doesn't have the required permission.
12402 */
12403 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012404 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012405 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012406 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012407 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012408 }
12409
12410 /**
12411 * Register to receive incoming datagrams over satellite.
12412 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012413 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012414 * @param callback The callback to handle incoming datagrams over satellite.
12415 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012416 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012417 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012418 * @throws SecurityException if the caller doesn't have the required permission.
12419 */
12420 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012421 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012422 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012423 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012424 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012425 }
12426
12427 /**
12428 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012429 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012430 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012431 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12432 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012433 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012434 *
12435 * @throws SecurityException if the caller doesn't have the required permission.
12436 */
12437 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012438 public void unregisterForSatelliteDatagram(int subId,
12439 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012440 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012441 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012442 }
12443
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012444 /**
12445 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012446 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012447 * This method requests modem to check if there are any pending datagrams to be received over
12448 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012449 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012450 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012451 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012452 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012453 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012454 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012455 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012456 @Override
12457 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012458 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012459 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012460 }
12461
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012462 /**
12463 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012464 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012465 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12466 * input to this method. Datagram received here will be passed down to modem without any
12467 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012468 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012469 * @param subId The subId of the subscription to send satellite datagrams for.
12470 * @param datagramType datagram type indicating whether the datagram is of type
12471 * SOS_SMS or LOCATION_SHARING.
12472 * @param datagram encoded gateway datagram which is encrypted by the caller.
12473 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012474 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12475 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012476 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012477 *
12478 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012479 */
12480 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012481 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12482 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12483 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012484 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012485 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12486 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012487 }
12488
Sarah Chindf715ec2023-02-13 13:46:24 -080012489 /**
12490 * Request to get whether satellite communication is allowed for the current location.
12491 *
12492 * @param subId The subId of the subscription to check whether satellite communication is
12493 * allowed for the current location for.
12494 * @param result The result receiver that returns whether satellite communication is allowed
12495 * for the current location if the request is successful or an error code
12496 * if the request failed.
12497 *
12498 * @throws SecurityException if the caller doesn't have the required permission.
12499 */
12500 @Override
12501 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12502 @NonNull ResultReceiver result) {
12503 enforceSatelliteCommunicationPermission(
12504 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012505 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12506 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012507 }
12508
12509 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012510 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012511 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012512 * @param subId The subId to get the time after which the satellite will be visible for.
12513 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012514 * be visible if the request is successful or an error code if the request failed.
12515 *
12516 * @throws SecurityException if the caller doesn't have the required permission.
12517 */
12518 @Override
12519 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12520 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012521 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012522 }
12523
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012524 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012525 * Inform that Device is aligned to satellite for demo mode.
12526 *
12527 * @param subId The subId to get the time after which the satellite will be visible for.
12528 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12529 * {@code false} Device fails to align with the satellite for demo mode.
12530 *
12531 * @throws SecurityException if the caller doesn't have required permission.
12532 */
12533 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12534
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012535 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012536 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012537 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012538 }
12539
12540 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012541 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12542 * by modem.
12543 *
12544 * @param subId The subId of the subscription to request for.
12545 * @param reason Reason for disallowing satellite communication for carrier.
12546 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12547 * operation.
12548 *
12549 * @throws SecurityException if the caller doesn't have required permission.
12550 */
12551 public void addSatelliteAttachRestrictionForCarrier(int subId,
12552 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12553 @NonNull IIntegerConsumer callback) {
12554 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12555 final long identity = Binder.clearCallingIdentity();
12556 try {
12557 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12558 } finally {
12559 Binder.restoreCallingIdentity(identity);
12560 }
12561 }
12562
12563 /**
12564 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12565 * by modem.
12566 *
12567 * @param subId The subId of the subscription to request for.
12568 * @param reason Reason for disallowing satellite communication.
12569 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12570 * operation.
12571 *
12572 * @throws SecurityException if the caller doesn't have required permission.
12573 */
12574 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12575 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12576 @NonNull IIntegerConsumer callback) {
12577 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12578 final long identity = Binder.clearCallingIdentity();
12579 try {
12580 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12581 callback);
12582 } finally {
12583 Binder.restoreCallingIdentity(identity);
12584 }
12585 }
12586
12587 /**
12588 * Get reasons for disallowing satellite communication, as requested by
12589 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12590 *
12591 * @param subId The subId of the subscription to request for.
12592 *
12593 * @return Integer array of reasons for disallowing satellite communication.
12594 *
12595 * @throws SecurityException if the caller doesn't have the required permission.
12596 */
12597 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12598 int subId) {
12599 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12600 final long identity = Binder.clearCallingIdentity();
12601 try {
12602 Set<Integer> reasonSet =
12603 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12604 return reasonSet.stream().mapToInt(i->i).toArray();
12605 } finally {
12606 Binder.restoreCallingIdentity(identity);
12607 }
12608 }
12609
12610 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012611 * Request to get the signal strength of the satellite connection.
12612 *
12613 * @param subId The subId of the subscription to request for.
12614 * @param result Result receiver to get the error code of the request and the current signal
12615 * strength of the satellite connection.
12616 *
12617 * @throws SecurityException if the caller doesn't have required permission.
12618 */
12619 @Override
12620 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12621 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12622 final long identity = Binder.clearCallingIdentity();
12623 try {
12624 mSatelliteController.requestNtnSignalStrength(subId, result);
12625 } finally {
12626 Binder.restoreCallingIdentity(identity);
12627 }
12628 }
12629
12630 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012631 * Registers for NTN signal strength changed from satellite modem. If the registration operation
12632 * is not successful, a {@link ServiceSpecificException} that contains
12633 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012634 *
12635 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012636 * @param callback The callback to handle the NTN signal strength changed event. If the
12637 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
12638 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
12639 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
12640 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012641 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012642 * @throws SecurityException If the caller doesn't have the required permission.
12643 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012644 */
12645 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012646 public void registerForNtnSignalStrengthChanged(int subId,
12647 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000012648 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12649 final long identity = Binder.clearCallingIdentity();
12650 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012651 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000012652 } finally {
12653 Binder.restoreCallingIdentity(identity);
12654 }
12655 }
12656
12657 /**
12658 * Unregisters for NTN signal strength changed from satellite modem.
12659 * If callback was not registered before, the request will be ignored.
12660 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000012661 * @param subId The subId of the subscription to unregister for listening NTN signal strength
12662 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012663 * @param callback The callback that was passed to
12664 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12665 *
12666 * @throws SecurityException if the caller doesn't have the required permission.
12667 */
12668 @Override
12669 public void unregisterForNtnSignalStrengthChanged(
12670 int subId, @NonNull INtnSignalStrengthCallback callback) {
12671 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12672 final long identity = Binder.clearCallingIdentity();
12673 try {
12674 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12675 } finally {
12676 Binder.restoreCallingIdentity(identity);
12677 }
12678 }
12679
12680 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000012681 * Registers for satellite capabilities change event from the satellite service.
12682 *
12683 * @param subId The subId of the subscription to request for.
12684 * @param callback The callback to handle the satellite capabilities changed event.
12685 *
12686 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12687 *
12688 * @throws SecurityException if the caller doesn't have required permission.
12689 */
12690 @Override
12691 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
12692 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12693 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
12694 final long identity = Binder.clearCallingIdentity();
12695 try {
12696 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
12697 } finally {
12698 Binder.restoreCallingIdentity(identity);
12699 }
12700 }
12701
12702 /**
12703 * Unregisters for satellite capabilities change event from the satellite service.
12704 * If callback was not registered before, the request will be ignored.
12705 *
12706 * @param subId The subId of the subscription to unregister for satellite capabilities change.
12707 * @param callback The callback that was passed to.
12708 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
12709 *
12710 * @throws SecurityException if the caller doesn't have required permission.
12711 */
12712 @Override
12713 public void unregisterForSatelliteCapabilitiesChanged(
12714 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12715 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
12716 final long identity = Binder.clearCallingIdentity();
12717 try {
12718 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
12719 } finally {
12720 Binder.restoreCallingIdentity(identity);
12721 }
12722 }
12723
12724 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012725 * This API can be used by only CTS to update satellite vendor service package name.
12726 *
12727 * @param servicePackageName The package name of the satellite vendor service.
12728 * @return {@code true} if the satellite vendor service is set successfully,
12729 * {@code false} otherwise.
12730 */
12731 public boolean setSatelliteServicePackageName(String servicePackageName) {
12732 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12733 TelephonyPermissions.enforceShellOnly(
12734 Binder.getCallingUid(), "setSatelliteServicePackageName");
12735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12736 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12737 "setSatelliteServicePackageName");
12738 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12739 }
12740
12741 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012742 * This API can be used by only CTS to update satellite gateway service package name.
12743 *
12744 * @param servicePackageName The package name of the satellite gateway service.
12745 * @return {@code true} if the satellite gateway service is set successfully,
12746 * {@code false} otherwise.
12747 */
12748 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12749 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12750 TelephonyPermissions.enforceShellOnly(
12751 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12753 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12754 "setSatelliteGatewayServicePackageName");
12755 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12756 }
12757
12758 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012759 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12760 *
12761 * @param packageName The package name of the satellite pointing UI app.
12762 * @param className The class name of the satellite pointing UI app.
12763 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12764 * {@code false} otherwise.
12765 */
12766 public boolean setSatellitePointingUiClassName(
12767 @Nullable String packageName, @Nullable String className) {
12768 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12769 + ", className=" + className);
12770 TelephonyPermissions.enforceShellOnly(
12771 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12773 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12774 "setSatelliteGatewayServicePackageName");
12775 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12776 }
12777
12778 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012779 * This API can be used by only CTS to update the timeout duration in milliseconds that
12780 * satellite should stay at listening mode to wait for the next incoming page before disabling
12781 * listening mode.
12782 *
12783 * @param timeoutMillis The timeout duration in millisecond.
12784 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12785 */
12786 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12787 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12788 TelephonyPermissions.enforceShellOnly(
12789 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12791 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12792 "setSatelliteListeningTimeoutDuration");
12793 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12794 }
12795
12796 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012797 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12798 * the device is aligned with the satellite for demo mode
12799 *
12800 * @param timeoutMillis The timeout duration in millisecond.
12801 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12802 */
12803 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12804 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12805 TelephonyPermissions.enforceShellOnly(
12806 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12808 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12809 "setDeviceAlignedTimeoutDuration");
12810 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12811 }
12812
12813 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070012814 * This API can be used in only testing to override connectivity status in monitoring emergency
12815 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
12816 *
12817 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
12818 * of the following values to enable the override:
12819 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
12820 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
12821 * To disable the override, use -1 for handoverType.
12822 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
12823 * delaySeconds after the emergency call starts.
12824 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
12825 */
12826 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
12827 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
12828 TelephonyPermissions.enforceShellOnly(
12829 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
12830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12831 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12832 "setEmergencyCallToSatelliteHandoverType");
12833 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
12834 handoverType, delaySeconds);
12835 }
12836
12837 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000012838 * This API can be used by only CTS to override the cached value for the device overlay config
12839 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
12840 * outgoing satellite datagrams should be sent to modem in demo mode.
12841 *
12842 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
12843 * satellite modem or not.
12844 *
12845 * @return {@code true} if the operation is successful, {@code false} otherwise.
12846 */
12847 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
12848 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
12849 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
12850 + "disabled");
12851 return false;
12852 }
12853 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
12854 TelephonyPermissions.enforceShellOnly(
12855 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
12856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12857 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12858 "setShouldSendDatagramToModemInDemoMode");
12859 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
12860 shouldSendToModemInDemoMode);
12861 }
12862
12863 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000012864 * Enable or disable notifications sent for cellular identifier disclosure events.
12865 *
12866 * Disclosure events are defined as instances where a device has sent a cellular identifier
12867 * on the Non-access stratum (NAS) before a security context is established. As a result the
12868 * identifier is sent in the clear, which has privacy implications for the user.
12869 *
12870 * @param enable if notifications about disclosure events should be enabled
12871 * @throws SecurityException if the caller does not have the required privileges
12872 * @throws UnsupportedOperationException if the modem does not support this feature.
12873 */
12874 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000012875 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000012876 enforceModifyPermission();
12877 checkForIdentifierDisclosureNotificationSupport();
12878
12879 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12880 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
12881 editor.apply();
12882
12883 // Each phone instance is responsible for updating its respective modem immediately
12884 // after we've made a preference change.
12885 for (Phone phone : PhoneFactory.getPhones()) {
12886 phone.handleIdentifierDisclosureNotificationPreferenceChange();
12887 }
12888 }
12889
12890 /**
12891 * Get whether or not cellular identifier disclosure notifications are enabled.
12892 *
12893 * @throws SecurityException if the caller does not have the required privileges
12894 * @throws UnsupportedOperationException if the modem does not support this feature.
12895 */
12896 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000012897 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000012898 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
12899 checkForIdentifierDisclosureNotificationSupport();
12900 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
12901 }
12902
12903 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012904 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12905 *
12906 * <p>This method behaves in one of the following ways:
12907 * <ul>
12908 * <li>return true : if the calling package has the appop permission {@link
12909 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12910 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12911 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12912 * Owner device identifier access check, or the calling package has carrier privileges</>
12913 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12914 * </ul>
12915 */
12916 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12917 String callingPackage, @Nullable String callingFeatureId, String message) {
12918 for (Phone phone : PhoneFactory.getPhones()) {
12919 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12920 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12921 return true;
12922 }
12923 }
12924 return false;
12925 }
arunvoddud7401012022-12-15 16:08:12 +000012926
12927 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012928 * @return The subscription manager service instance.
12929 */
12930 public SubscriptionManagerService getSubscriptionManagerService() {
12931 return SubscriptionManagerService.getInstance();
12932 }
12933
12934 /**
arunvoddud7401012022-12-15 16:08:12 +000012935 * Class binds the consumer[callback] and carrierId.
12936 */
12937 private static class CallerCallbackInfo {
12938 private final Consumer<Integer> mConsumer;
12939 private final int mCarrierId;
12940
12941 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12942 mConsumer = consumer;
12943 mCarrierId = carrierId;
12944 }
12945
12946 public Consumer<Integer> getConsumer() {
12947 return mConsumer;
12948 }
12949
12950 public int getCarrierId() {
12951 return mCarrierId;
12952 }
12953 }
Jack Yufa8ed012023-02-11 15:42:28 -080012954}