blob: 29c064200bb542c3553cbc4dbb51435db03c0b0c [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;
Michael Groover826b71d2023-12-21 22:08:06 -0600406 // Null cipher notification support was added in IRadioNetwork 2.2
407 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000408
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 /** The singleton instance. */
410 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800411 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412
Sarah Chin4beb2b72023-02-14 14:47:54 -0800413 private final PhoneGlobals mApp;
Sarah Chincc5446f2023-10-23 17:57:19 -0700414 private final FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800415 private final CallManager mCM;
416 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000417
418 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800419 private final UserManager mUserManager;
420 private final AppOpsManager mAppOps;
421 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800422 private final SharedPreferences mTelephonySharedPreferences;
423 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800424 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425
Peter Wangdafb9ac2020-01-15 14:13:38 -0800426 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800427 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800428 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
429
Sarah Chin4beb2b72023-02-14 14:47:54 -0800430 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800431
Derek Tan97ebb422014-09-05 16:55:38 -0700432 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
433 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800434 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800435 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700436
Michelecea4cf22018-12-21 15:00:11 -0800437 // String to store multi SIM allowed
438 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
439
Derek Tan740e1672017-06-27 14:56:27 -0700440 // The AID of ISD-R.
441 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
442
yinxub1bed742017-04-17 11:45:04 -0700443 private NetworkScanRequestTracker mNetworkScanRequestTracker;
444
David Kelly5e06a7f2018-03-12 14:10:59 +0000445 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
446 private static final int MANUFACTURER_CODE_LENGTH = 8;
447
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800448 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800449 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800450
Sarah Chin2ec39f62022-08-31 17:03:26 -0700451 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
452 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
453
Derek Tan89e89d42014-07-08 17:00:10 -0700454 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700455 * Experiment flag to enable erase modem config on reset network, default value is false
456 */
457 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
458 "reset_network_erase_modem_config_enabled";
459
Rambo Wang0f050d82021-02-12 11:43:36 -0800460 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800461
Gary Jian76280a42022-12-07 16:18:33 +0800462 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
463
sandeepjsb6c87872021-09-27 15:34:44 +0000464 /**
465 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
466 * one ICCID active at the same time.
467 * Apps should use below API signatures if targeting SDK is T and beyond.
468 *
469 * @hide
470 */
471 @ChangeId
472 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
473 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800474
Naina Nallurid63128d2019-09-17 14:10:30 -0700475 /**
Chen Xu540470b2021-12-14 17:15:47 -0800476 * Apps targeting on Android T and beyond will get exception whenever icc close channel
477 * operation fails.
478 */
479 @ChangeId
480 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
481 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
482
483 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 * A request object to use for transmitting data to an ICC.
485 */
486 private static final class IccAPDUArgument {
487 public int channel, cla, command, p1, p2, p3;
488 public String data;
489
490 public IccAPDUArgument(int channel, int cla, int command,
491 int p1, int p2, int p3, String data) {
492 this.channel = channel;
493 this.cla = cla;
494 this.command = command;
495 this.p1 = p1;
496 this.p2 = p2;
497 this.p3 = p3;
498 this.data = data;
499 }
500 }
501
502 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700503 * A request object to use for transmitting data to an ICC.
504 */
505 private static final class ManualNetworkSelectionArgument {
506 public OperatorInfo operatorInfo;
507 public boolean persistSelection;
508
509 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
510 this.operatorInfo = operatorInfo;
511 this.persistSelection = persistSelection;
512 }
513 }
514
Sarah Chin71b3a852022-09-28 15:54:19 -0700515 private static final class PurchasePremiumCapabilityArgument {
516 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700517 public @NonNull IIntegerConsumer callback;
518
519 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800520 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700521 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700522 this.callback = callback;
523 }
524 }
525
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700526 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
528 * request after sending. The main thread will notify the request when it is complete.
529 */
530 private static final class MainThreadRequest {
531 /** The argument to use for the request */
532 public Object argument;
533 /** The result of the request that is run on the main thread */
534 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800535 // The subscriber id that this request applies to. Defaults to
536 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
537 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538
Nathan Harold92bed182018-10-12 18:16:49 -0700539 // In cases where subId is unavailable, the caller needs to specify the phone.
540 public Phone phone;
541
vagdeviaf9a5b92018-08-15 16:01:53 -0700542 public WorkSource workSource;
543
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 public MainThreadRequest(Object argument) {
545 this.argument = argument;
546 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800547
Nathan Harold92bed182018-10-12 18:16:49 -0700548 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
549 this.argument = argument;
550 if (phone != null) {
551 this.phone = phone;
552 }
553 this.workSource = workSource;
554 }
555
vagdeviaf9a5b92018-08-15 16:01:53 -0700556 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800557 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800558 if (subId != null) {
559 this.subId = subId;
560 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700561 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 }
564
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800565 private static final class IncomingThirdPartyCallArgs {
566 public final ComponentName component;
567 public final String callId;
568 public final String callerDisplayName;
569
570 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
571 String callerDisplayName) {
572 this.component = component;
573 this.callId = callId;
574 this.callerDisplayName = callerDisplayName;
575 }
576 }
577
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 /**
579 * A handler that processes messages on the main thread in the phone process. Since many
580 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
581 * inbound binder threads to the main thread in the phone process. The Binder thread
582 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
583 * on, which will be notified when the operation completes and will contain the result of the
584 * request.
585 *
586 * <p>If a MainThreadRequest object is provided in the msg.obj field,
587 * note that request.result must be set to something non-null for the calling thread to
588 * unblock.
589 */
590 private final class MainThreadHandler extends Handler {
591 @Override
592 public void handleMessage(Message msg) {
593 MainThreadRequest request;
594 Message onCompleted;
595 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800598 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599
600 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 case CMD_HANDLE_USSD_REQUEST: {
602 request = (MainThreadRequest) msg.obj;
603 final Phone phone = getPhoneFromRequest(request);
604 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800605 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700607
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 if (!isUssdApiAllowed(request.subId)) {
609 // Carrier does not support use of this API, return failure.
610 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
611 UssdResponse response = new UssdResponse(ussdRequest, null);
612 Bundle returnData = new Bundle();
613 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
614 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700615
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 request.result = true;
617 notifyRequester(request);
618 return;
619 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700620
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 try {
622 request.result = phone != null
623 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
624 } catch (CallStateException cse) {
625 request.result = false;
626 }
627 // Wake up the requesting thread
628 notifyRequester(request);
629 break;
pkanwar32d516d2016-10-14 19:37:38 -0700630 }
631
Yorke Lee716f67e2015-06-17 15:39:16 -0700632 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700633 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700634 final Phone phone = getPhoneFromRequest(request);
635 request.result = phone != null ?
636 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
637 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700638 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700640 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700642
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort = getUiccPortFromRequest(request);
647 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800653 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000654 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800655 iccArgument.channel, iccArgument.cla, iccArgument.command,
656 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
657 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result;
666 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 if (ar.result == null) {
669 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800670 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800672 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 } else {
674 loge("iccTransmitApduLogicalChannel: Unknown exception");
675 }
676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
681 request = (MainThreadRequest) msg.obj;
682 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort = getUiccPortFromRequest(request);
684 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 } else {
689 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800690 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800692 iccArgument.cla, iccArgument.command, iccArgument.p1,
693 iccArgument.p2,
694 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 }
696 break;
697
698 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result;
703 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 if (ar.result == null) {
706 loge("iccTransmitApduBasicChannel: Empty response");
707 } else if (ar.exception instanceof CommandException) {
708 loge("iccTransmitApduBasicChannel: CommandException: " +
709 ar.exception);
710 } else {
711 loge("iccTransmitApduBasicChannel: Unknown exception");
712 }
713 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 break;
716
717 case CMD_EXCHANGE_SIM_IO:
718 request = (MainThreadRequest) msg.obj;
719 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 uiccPort = getUiccPortFromRequest(request);
721 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800723 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 } else {
726 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
727 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000728 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
730 iccArgument.data, onCompleted);
731 }
732 break;
733
734 case EVENT_EXCHANGE_SIM_IO_DONE:
735 ar = (AsyncResult) msg.obj;
736 request = (MainThreadRequest) ar.userObj;
737 if (ar.exception == null && ar.result != null) {
738 request.result = ar.result;
739 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800740 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 break;
744
Derek Tan4d5e5c12014-02-04 11:54:58 -0800745 case CMD_SEND_ENVELOPE:
746 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000747 uiccPort = getUiccPortFromRequest(request);
748 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800750 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700752 } else {
753 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800754 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700755 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800756 break;
757
758 case EVENT_SEND_ENVELOPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800764 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700765 if (ar.result == null) {
766 loge("sendEnvelopeWithStatus: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("sendEnvelopeWithStatus: CommandException: " +
769 ar.exception);
770 } else {
771 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
772 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800775 break;
776
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 case CMD_OPEN_CHANNEL:
778 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000779 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800780 IccLogicalChannelRequest openChannelRequest =
781 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000782 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800784 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800785 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 } else {
788 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800789 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
790 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 break;
793
794 case EVENT_OPEN_CHANNEL_DONE:
795 ar = (AsyncResult) msg.obj;
796 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700797 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700799 int[] result = (int[]) ar.result;
800 int channelId = result[0];
801 byte[] selectResponse = null;
802 if (result.length > 1) {
803 selectResponse = new byte[result.length - 1];
804 for (int i = 1; i < result.length; ++i) {
805 selectResponse[i - 1] = (byte) result[i];
806 }
807 }
808 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800809 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800810
811 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700812 if (uiccPort == null) {
813 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
814 } else {
815 IccLogicalChannelRequest channelRequest =
816 (IccLogicalChannelRequest) request.argument;
817 channelRequest.channel = channelId;
818 uiccPort.onLogicalChannelOpened(channelRequest);
819 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700820 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 if (ar.result == null) {
822 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700823 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700824 if (ar.exception != null) {
825 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
826 }
827
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700828 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700829 if (ar.exception instanceof CommandException) {
830 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800831 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700832 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700833 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700834 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700835 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700836 }
837 }
838 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800839 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700840 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700841 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700842 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 break;
844
845 case CMD_CLOSE_CHANNEL:
846 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000847 uiccPort = getUiccPortFromRequest(request);
848 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700849 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800850 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800851 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800852 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700853 } else {
854 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000855 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700856 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 break;
858
859 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800860 ar = (AsyncResult) msg.obj;
861 request = (MainThreadRequest) ar.userObj;
862 if (ar.exception == null) {
863 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800864 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700865 if (uiccPort == null) {
866 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
867 } else {
868 final int channelId = (Integer) request.argument;
869 uiccPort.onLogicalChannelClosed(channelId);
870 }
Chen Xu540470b2021-12-14 17:15:47 -0800871 } else {
872 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800873 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800874 if (ar.exception instanceof CommandException) {
875 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
876 CommandException.Error error =
877 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800878 if (error == CommandException.Error.INVALID_ARGUMENTS) {
879 // should only throw exceptions from the binder threads.
880 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800881 "iccCloseLogicalChannel: invalid argument ");
882 }
883 } else {
884 loge("iccCloseLogicalChannel: Unknown exception");
885 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800886 request.result = (exception != null) ? exception :
887 new IllegalStateException(
888 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800889 }
890 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
893 case CMD_NV_READ_ITEM:
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800896 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
897 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800898 break;
899
900 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700905 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800906 request.result = "";
907 if (ar.result == null) {
908 loge("nvReadItem: Empty response");
909 } else if (ar.exception instanceof CommandException) {
910 loge("nvReadItem: CommandException: " +
911 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700912 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800913 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700917 break;
918
Jake Hambye994d462014-02-03 13:10:13 -0800919 case CMD_NV_WRITE_ITEM:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
922 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800923 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700924 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800925 break;
926
927 case EVENT_NV_WRITE_ITEM_DONE:
928 handleNullReturnEvent(msg, "nvWriteItem");
929 break;
930
931 case CMD_NV_WRITE_CDMA_PRL:
932 request = (MainThreadRequest) msg.obj;
933 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800934 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800935 break;
936
937 case EVENT_NV_WRITE_CDMA_PRL_DONE:
938 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
939 break;
940
chen xu6dac5ab2018-10-26 17:39:23 -0700941 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800942 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700943 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800944 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800945 break;
946
chen xu6dac5ab2018-10-26 17:39:23 -0700947 case EVENT_RESET_MODEM_CONFIG_DONE:
948 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800949 break;
950
Sooraj Sasindran37444802020-08-11 10:40:43 -0700951 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
954 request);
955 Phone phone = getPhoneFromRequest(request);
956 if (phone != null) {
957 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
958 } else {
959 loge("isNRDualConnectivityEnabled: No phone object");
960 request.result = false;
961 notifyRequester(request);
962 }
963 break;
964 }
965
966 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception == null && ar.result != null) {
970 request.result = ar.result;
971 } else {
972 // request.result must be set to something non-null
973 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700974 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700975 request.result = ar.result;
976 } else {
977 request.result = false;
978 }
979 if (ar.result == null) {
980 loge("isNRDualConnectivityEnabled: Empty response");
981 } else if (ar.exception instanceof CommandException) {
982 loge("isNRDualConnectivityEnabled: CommandException: "
983 + ar.exception);
984 } else {
985 loge("isNRDualConnectivityEnabled: Unknown exception");
986 }
987 }
988 notifyRequester(request);
989 break;
990
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700991 case CMD_IS_VONR_ENABLED: {
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
994 request);
995 Phone phone = getPhoneFromRequest(request);
996 if (phone != null) {
997 phone.isVoNrEnabled(onCompleted, request.workSource);
998 } else {
999 loge("isVoNrEnabled: No phone object");
1000 request.result = false;
1001 notifyRequester(request);
1002 }
1003 break;
1004 }
1005
1006 case EVENT_IS_VONR_ENABLED_DONE:
1007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception == null && ar.result != null) {
1010 request.result = ar.result;
1011 } else {
1012 // request.result must be set to something non-null
1013 // for the calling thread to unblock
1014 if (ar.result != null) {
1015 request.result = ar.result;
1016 } else {
1017 request.result = false;
1018 }
1019 if (ar.result == null) {
1020 loge("isVoNrEnabled: Empty response");
1021 } else if (ar.exception instanceof CommandException) {
1022 loge("isVoNrEnabled: CommandException: "
1023 + ar.exception);
1024 } else {
1025 loge("isVoNrEnabled: Unknown exception");
1026 }
1027 }
1028 notifyRequester(request);
1029 break;
1030
Sooraj Sasindran37444802020-08-11 10:40:43 -07001031 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1032 request = (MainThreadRequest) msg.obj;
1033 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1034 Phone phone = getPhoneFromRequest(request);
1035 if (phone != null) {
1036 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1037 request.workSource);
1038 } else {
1039 loge("enableNrDualConnectivity: No phone object");
1040 request.result =
1041 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1042 notifyRequester(request);
1043 }
1044 break;
1045 }
1046
1047 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
1050 if (ar.exception == null) {
1051 request.result =
1052 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1053 } else {
1054 request.result =
1055 TelephonyManager
1056 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1057 if (ar.exception instanceof CommandException) {
1058 CommandException.Error error =
1059 ((CommandException) (ar.exception)).getCommandError();
1060 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1061 request.result =
1062 TelephonyManager
1063 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001064 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1065 request.result =
1066 TelephonyManager
1067 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001068 }
1069 loge("enableNrDualConnectivity" + ": CommandException: "
1070 + ar.exception);
1071 } else {
1072 loge("enableNrDualConnectivity" + ": Unknown exception");
1073 }
1074 }
1075 notifyRequester(request);
1076 break;
1077 }
1078
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001079 case CMD_ENABLE_VONR: {
1080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1082 Phone phone = getPhoneFromRequest(request);
1083 if (phone != null) {
1084 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1085 request.workSource);
1086 } else {
1087 loge("setVoNrEnabled: No phone object");
1088 request.result =
1089 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1090 notifyRequester(request);
1091 }
1092 break;
1093 }
1094
1095 case EVENT_ENABLE_VONR_DONE: {
1096 ar = (AsyncResult) msg.obj;
1097 request = (MainThreadRequest) ar.userObj;
1098 if (ar.exception == null) {
1099 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1100 } else {
1101 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1102 if (ar.exception instanceof CommandException) {
1103 CommandException.Error error =
1104 ((CommandException) (ar.exception)).getCommandError();
1105 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1106 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1107 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1109 } else {
1110 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1111 }
1112 loge("setVoNrEnabled" + ": CommandException: "
1113 + ar.exception);
1114 } else {
1115 loge("setVoNrEnabled" + ": Unknown exception");
1116 }
1117 }
1118 notifyRequester(request);
1119 break;
1120 }
1121
SongFerngWang3ef3e072020-12-21 16:41:52 +08001122 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001124 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1125 request);
1126 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 break;
1128
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 ar = (AsyncResult) msg.obj;
1131 request = (MainThreadRequest) ar.userObj;
1132 if (ar.exception == null && ar.result != null) {
1133 request.result = ar.result; // Integer
1134 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301135 // request.result must be set to something non-null
1136 // for the calling thread to unblock
1137 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001139 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 loge("getAllowedNetworkTypesBitmask: CommandException: "
1142 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 }
1146 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001147 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 break;
1149
SongFerngWang3ef3e072020-12-21 16:41:52 +08001150 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1153 request);
1154 Pair<Integer, Long> reasonWithNetworkTypes =
1155 (Pair<Integer, Long>) request.argument;
1156 getPhoneFromRequest(request).setAllowedNetworkTypes(
1157 reasonWithNetworkTypes.first,
1158 reasonWithNetworkTypes.second,
1159 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 break;
1161
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1163 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 break;
1165
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001166 case CMD_SET_VOICEMAIL_NUMBER:
1167 request = (MainThreadRequest) msg.obj;
1168 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1169 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001170 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1171 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001172 break;
1173
1174 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1175 handleNullReturnEvent(msg, "setVoicemailNumber");
1176 break;
1177
Stuart Scott54788802015-03-30 13:18:01 -07001178 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1179 request = (MainThreadRequest) msg.obj;
1180 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1181 request);
1182 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1183 break;
1184
1185 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1186 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1187 break;
1188
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 case CMD_PERFORM_NETWORK_SCAN:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1192 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1193 break;
1194
Hall Liu27d24262020-09-18 19:04:59 -07001195 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001196 request = (MainThreadRequest) msg.obj;
1197 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001198 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1199 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1200 request.argument;
1201 int callForwardingReason = args.first;
1202 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
Hall Liu27d24262020-09-18 19:04:59 -07001204 }
1205 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001206 ar = (AsyncResult) msg.obj;
1207 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001208 TelephonyManager.CallForwardingInfoCallback callback =
1209 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1210 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001211 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001212 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001213 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1214 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1215 // Service Class is a bit mask per 3gpp 27.007. Search for
1216 // any service for voice call.
1217 if ((callForwardInfo.serviceClass
1218 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001219 callForwardingInfo = new CallForwardingInfo(
1220 callForwardInfo.status
1221 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001222 callForwardInfo.reason,
1223 callForwardInfo.number,
1224 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 break;
1226 }
1227 }
1228 // Didn't find a call forward info for voice call.
1229 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001230 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1231 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 }
Hall Liu27d24262020-09-18 19:04:59 -07001233 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001234 } else {
1235 if (ar.result == null) {
1236 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1237 }
1238 if (ar.exception != null) {
1239 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1240 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001241 int errorCode = TelephonyManager
1242 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001243 if (ar.exception instanceof CommandException) {
1244 CommandException.Error error =
1245 ((CommandException) (ar.exception)).getCommandError();
1246 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001247 errorCode = TelephonyManager
1248 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001249 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001250 errorCode = TelephonyManager
1251 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001252 }
1253 }
Hall Liu27d24262020-09-18 19:04:59 -07001254 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256 break;
Hall Liu27d24262020-09-18 19:04:59 -07001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258
Hall Liu27d24262020-09-18 19:04:59 -07001259 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 request = (MainThreadRequest) msg.obj;
1261 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001262 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001264 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1265 request.argument).first;
1266 request.phone.setCallForwardingOption(
1267 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001268 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001269 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001270 callForwardingInfoToSet.getReason(),
1271 callForwardingInfoToSet.getNumber(),
1272 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1273 break;
Hall Liu27d24262020-09-18 19:04:59 -07001274 }
Shuo Qian4a594052020-01-23 11:59:30 -08001275
Hall Liu27d24262020-09-18 19:04:59 -07001276 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001279 Consumer<Integer> callback =
1280 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1281 request.argument).second;
1282 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001283 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001284 int errorCode = TelephonyManager.CallForwardingInfoCallback
1285 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001286 if (ar.exception instanceof CommandException) {
1287 CommandException.Error error =
1288 ((CommandException) (ar.exception)).getCommandError();
1289 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001290 errorCode = TelephonyManager.CallForwardingInfoCallback
1291 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001292 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001293 errorCode = TelephonyManager.CallForwardingInfoCallback
1294 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001295 }
1296 }
1297 callback.accept(errorCode);
1298 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001299 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001300 }
Shuo Qian4a594052020-01-23 11:59:30 -08001301 break;
Hall Liu27d24262020-09-18 19:04:59 -07001302 }
Shuo Qian4a594052020-01-23 11:59:30 -08001303
Hall Liu27d24262020-09-18 19:04:59 -07001304 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001305 request = (MainThreadRequest) msg.obj;
1306 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1307 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1308 break;
Hall Liu27d24262020-09-18 19:04:59 -07001309 }
Shuo Qian4a594052020-01-23 11:59:30 -08001310
Hall Liu27d24262020-09-18 19:04:59 -07001311 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001312 ar = (AsyncResult) msg.obj;
1313 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001314 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001315 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001316 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001317 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001318 // Service Class is a bit mask per 3gpp 27.007.
1319 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001320 if (callForwardResults.length > 1
1321 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001322 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001323 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001324 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1325 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001326 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001327 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001328 }
1329 } else {
1330 if (ar.result == null) {
1331 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1332 }
1333 if (ar.exception != null) {
1334 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1335 }
1336 if (ar.exception instanceof CommandException) {
1337 CommandException.Error error =
1338 ((CommandException) (ar.exception)).getCommandError();
1339 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001341 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001342 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1343 callWaitingStatus =
1344 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001345 }
1346 }
1347 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001348 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001349 break;
Hall Liu27d24262020-09-18 19:04:59 -07001350 }
Shuo Qian4a594052020-01-23 11:59:30 -08001351
Hall Liu27d24262020-09-18 19:04:59 -07001352 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001353 request = (MainThreadRequest) msg.obj;
1354 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001355 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1356 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001357 break;
Hall Liu27d24262020-09-18 19:04:59 -07001358 }
Shuo Qian4a594052020-01-23 11:59:30 -08001359
Hall Liu27d24262020-09-18 19:04:59 -07001360 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001363 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1364 Consumer<Integer> callback =
1365 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1366 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001367 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001368 if (ar.exception instanceof CommandException) {
1369 CommandException.Error error =
1370 ((CommandException) (ar.exception)).getCommandError();
1371 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1372 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001373 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1374 callback.accept(
1375 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001376 } else {
1377 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1378 }
1379 } else {
1380 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1381 }
1382 } else {
1383 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1384 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001385 }
Shuo Qian4a594052020-01-23 11:59:30 -08001386 break;
Hall Liu27d24262020-09-18 19:04:59 -07001387 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001388 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 CellNetworkScanResult cellScanResult;
1392 if (ar.exception == null && ar.result != null) {
1393 cellScanResult = new CellNetworkScanResult(
1394 CellNetworkScanResult.STATUS_SUCCESS,
1395 (List<OperatorInfo>) ar.result);
1396 } else {
1397 if (ar.result == null) {
1398 loge("getCellNetworkScanResults: Empty response");
1399 }
1400 if (ar.exception != null) {
1401 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1402 }
1403 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1404 if (ar.exception instanceof CommandException) {
1405 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001406 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1408 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1409 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1410 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1411 }
1412 }
1413 cellScanResult = new CellNetworkScanResult(errorCode, null);
1414 }
1415 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001416 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001417 break;
1418
1419 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1420 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001421 ManualNetworkSelectionArgument selArg =
1422 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001423 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1424 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001425 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1426 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001427 break;
1428
1429 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001430 ar = (AsyncResult) msg.obj;
1431 request = (MainThreadRequest) ar.userObj;
1432 if (ar.exception == null) {
1433 request.result = true;
1434 } else {
1435 request.result = false;
1436 loge("setNetworkSelectionModeManual " + ar.exception);
1437 }
1438 notifyRequester(request);
1439 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001440 break;
1441
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 case CMD_GET_MODEM_ACTIVITY_INFO:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001445 if (defaultPhone != null) {
1446 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001447 } else {
1448 ResultReceiver result = (ResultReceiver) request.argument;
1449 Bundle bundle = new Bundle();
1450 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001451 new ModemActivityInfo(0, 0, 0,
1452 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001454 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 break;
1456
Hall Liud0f208c2020-10-14 16:54:44 -07001457 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001461 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001462 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001463 if (mLastModemActivityInfo == null) {
1464 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1465 mLastModemActivitySpecificInfo[0] =
1466 new ActivityStatsTechSpecificInfo(
1467 0,
1468 0,
1469 new int[ModemActivityInfo.getNumTxPowerLevels()],
1470 0);
1471 mLastModemActivityInfo =
1472 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1473 }
1474
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001476 // Update the last modem activity info and the result of the request.
1477 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1478 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001479 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001480 } else {
1481 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001482 }
Kai Shi917fdc62022-11-28 14:01:02 -08001483 // This is needed to decouple ret from mLastModemActivityInfo
1484 // We don't want to return mLastModemActivityInfo which is updated
1485 // inside mergeModemActivityInfo()
1486 ret = new ModemActivityInfo(
1487 mLastModemActivityInfo.getTimestampMillis(),
1488 mLastModemActivityInfo.getSleepTimeMillis(),
1489 mLastModemActivityInfo.getIdleTimeMillis(),
1490 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001491
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001492 } else {
1493 if (ar.result == null) {
1494 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001495 error = TelephonyManager.ModemActivityInfoException
1496 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001498 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001499 error = TelephonyManager.ModemActivityInfoException
1500 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001501 } else {
1502 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001503 error = TelephonyManager.ModemActivityInfoException
1504 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 }
1506 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001507 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001508 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001509 bundle.putParcelable(
1510 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001511 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001512 } else {
1513 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1514 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001515 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001516 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001518 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001520 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001521 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001522 CarrierRestrictionRules argument =
1523 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001525 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001527 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001528
1529 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception == null && ar.result != null) {
1533 request.result = ar.result;
1534 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001535 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1536 if (ar.exception instanceof CommandException) {
1537 loge("setAllowedCarriers: CommandException: " + ar.exception);
1538 CommandException.Error error =
1539 ((CommandException) (ar.exception)).getCommandError();
1540 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1541 request.result =
1542 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1543 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 } else {
1545 loge("setAllowedCarriers: Unknown exception");
1546 }
1547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001548 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 break;
1550
1551 case CMD_GET_ALLOWED_CARRIERS:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001554 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001555 break;
1556
1557 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 if (ar.exception == null && ar.result != null) {
1561 request.result = ar.result;
1562 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001563 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001564 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001565 if (ar.result == null) {
1566 loge("getAllowedCarriers: Empty response");
1567 } else if (ar.exception instanceof CommandException) {
1568 loge("getAllowedCarriers: CommandException: " +
1569 ar.exception);
1570 } else {
1571 loge("getAllowedCarriers: Unknown exception");
1572 }
1573 }
arunvoddud7401012022-12-15 16:08:12 +00001574 if (request.argument != null) {
1575 // This is for the implementation of carrierRestrictionStatus.
1576 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1577 Consumer<Integer> callback = callbackInfo.getConsumer();
1578 int callerCarrierId = callbackInfo.getCarrierId();
1579 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1580 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1581 CarrierRestrictionRules carrierRestrictionRules =
1582 (CarrierRestrictionRules) ar.result;
1583 int carrierId = -1;
1584 try {
1585 CarrierIdentifier carrierIdentifier =
1586 carrierRestrictionRules.getAllowedCarriers().get(0);
1587 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1588 carrierIdentifier);
1589 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1590 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1591 }
1592 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1593 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1594 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001595 lockStatus = TelephonyManager
1596 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001597 }
1598 } else {
1599 Rlog.e(LOG_TAG,
1600 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1601 }
1602 callback.accept(lockStatus);
1603 } else {
1604 // This is for the implementation of getAllowedCarriers.
1605 notifyRequester(request);
1606 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001607 break;
1608
Nathan Haroldb3014052017-01-25 15:57:32 -08001609 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 if (ar.exception == null && ar.result != null) {
1613 request.result = ar.result;
1614 } else {
1615 request.result = new IllegalArgumentException(
1616 "Failed to retrieve Forbidden Plmns");
1617 if (ar.result == null) {
1618 loge("getForbiddenPlmns: Empty response");
1619 } else {
1620 loge("getForbiddenPlmns: Unknown exception");
1621 }
1622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001623 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001624 break;
1625
1626 case CMD_GET_FORBIDDEN_PLMNS:
1627 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001628 uiccPort = getUiccPortFromRequest(request);
1629 if (uiccPort == null) {
1630 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001631 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001632 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001633 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 break;
1635 }
1636 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001637 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001638 if (uiccApp == null) {
1639 loge("getForbiddenPlmns() no app with specified type -- "
1640 + appType);
1641 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001642 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001643 break;
1644 } else {
1645 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1646 + " specified type -- " + appType);
1647 }
1648 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1649 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001650 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 break;
1652
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001653 case CMD_SWITCH_SLOTS:
1654 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001655 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001656 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001657 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 break;
1659
1660 case EVENT_SWITCH_SLOTS_DONE:
1661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001664 notifyRequester(request);
1665 break;
1666 case CMD_GET_NETWORK_SELECTION_MODE:
1667 request = (MainThreadRequest) msg.obj;
1668 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1669 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1670 break;
1671
1672 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1673 ar = (AsyncResult) msg.obj;
1674 request = (MainThreadRequest) ar.userObj;
1675 if (ar.exception != null) {
1676 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1677 } else {
1678 int mode = ((int[]) ar.result)[0];
1679 if (mode == 0) {
1680 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1681 } else {
1682 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1683 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001685 notifyRequester(request);
1686 break;
1687 case CMD_GET_CDMA_ROAMING_MODE:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1690 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1691 break;
1692 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 if (ar.exception != null) {
1696 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1697 } else {
1698 request.result = ((int[]) ar.result)[0];
1699 }
1700 notifyRequester(request);
1701 break;
1702 case CMD_SET_CDMA_ROAMING_MODE:
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1705 int mode = (int) request.argument;
1706 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1707 break;
1708 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 request.result = ar.exception == null;
1712 notifyRequester(request);
1713 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001714 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1715 request = (MainThreadRequest) msg.obj;
1716 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1717 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1718 break;
1719 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 if (ar.exception != null) {
1723 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1724 } else {
1725 request.result = ((int[]) ar.result)[0];
1726 }
1727 notifyRequester(request);
1728 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001729 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1730 request = (MainThreadRequest) msg.obj;
1731 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1732 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001733 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1734 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001735 break;
1736 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 request.result = ar.exception == null;
1740 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001741 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 case CMD_GET_ALL_CELL_INFO:
1743 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001744 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001745 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001746 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 case EVENT_GET_ALL_CELL_INFO_DONE:
1748 ar = (AsyncResult) msg.obj;
1749 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001750 // If a timeout occurs, the response will be null
1751 request.result = (ar.exception == null && ar.result != null)
1752 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001753 synchronized (request) {
1754 request.notifyAll();
1755 }
1756 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001757 case CMD_REQUEST_CELL_INFO_UPDATE:
1758 request = (MainThreadRequest) msg.obj;
1759 request.phone.requestCellInfoUpdate(request.workSource,
1760 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1761 break;
1762 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1766 try {
1767 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001768 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001769 cb.onError(
1770 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1771 ar.exception.getClass().getName(),
1772 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001773 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001774 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001775 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001776 } else {
1777 // use the result as returned
1778 cb.onCellInfo((List<CellInfo>) ar.result);
1779 }
1780 } catch (RemoteException re) {
1781 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1782 }
1783 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001784 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001785 request = (MainThreadRequest) msg.obj;
1786 WorkSource ws = (WorkSource) request.argument;
1787 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001788 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001789 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001790 }
1791 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794 if (ar.exception == null) {
1795 request.result = ar.result;
1796 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001797 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001798 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001799 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001800 }
1801
1802 synchronized (request) {
1803 request.notifyAll();
1804 }
1805 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 }
chen xu6dac5ab2018-10-26 17:39:23 -07001807 case CMD_MODEM_REBOOT:
1808 request = (MainThreadRequest) msg.obj;
1809 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001810 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001811 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001812 case EVENT_CMD_MODEM_REBOOT_DONE:
1813 handleNullReturnEvent(msg, "rebootModem");
1814 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001815 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001816 request = (MainThreadRequest) msg.obj;
1817 boolean enable = (boolean) request.argument;
1818 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001819 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001820 PhoneConfigurationManager.getInstance()
1821 .enablePhone(request.phone, enable, onCompleted);
1822 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001823 }
Michele Berionne5e411512020-11-13 02:36:59 +00001824 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001825 ar = (AsyncResult) msg.obj;
1826 request = (MainThreadRequest) ar.userObj;
1827 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001828 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001829 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001830 if ((boolean) request.result) {
1831 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1832 updateModemStateMetrics();
1833 } else {
1834 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1835 + ar.exception);
1836 }
1837 notifyRequester(request);
1838 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001839 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001840 case CMD_GET_MODEM_STATUS:
1841 request = (MainThreadRequest) msg.obj;
1842 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1843 PhoneConfigurationManager.getInstance()
1844 .getPhoneStatusFromModem(request.phone, onCompleted);
1845 break;
1846 case EVENT_GET_MODEM_STATUS_DONE:
1847 ar = (AsyncResult) msg.obj;
1848 request = (MainThreadRequest) ar.userObj;
1849 int id = request.phone.getPhoneId();
1850 if (ar.exception == null && ar.result != null) {
1851 request.result = ar.result;
1852 //update the cache as modem status has changed
1853 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1854 (boolean) request.result);
1855 } else {
1856 // Return true if modem status cannot be retrieved. For most cases,
1857 // modem status is on. And for older version modems, GET_MODEM_STATUS
1858 // and disable modem are not supported. Modem is always on.
1859 // TODO: this should be fixed in R to support a third
1860 // status UNKNOWN b/131631629
1861 request.result = true;
1862 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1863 + ar.exception);
1864 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001865 notifyRequester(request);
1866 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001867 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1868 request = (MainThreadRequest) msg.obj;
1869 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1870 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1871 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1872 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1873 break;
1874 }
1875 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1876 ar = (AsyncResult) msg.obj;
1877 request = (MainThreadRequest) ar.userObj;
1878 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1879 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1880 args.second.accept(ar.exception == null);
1881 notifyRequester(request);
1882 break;
1883 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001884 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1885 request = (MainThreadRequest) msg.obj;
1886 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1887 Phone phone = getPhoneFromRequest(request);
1888 if (phone != null) {
1889 phone.getSystemSelectionChannels(onCompleted);
1890 } else {
1891 loge("getSystemSelectionChannels: No phone object");
1892 request.result = new ArrayList<RadioAccessSpecifier>();
1893 notifyRequester(request);
1894 }
1895 break;
1896 }
1897 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1898 ar = (AsyncResult) msg.obj;
1899 request = (MainThreadRequest) ar.userObj;
1900 if (ar.exception == null && ar.result != null) {
1901 request.result = ar.result;
1902 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001903 request.result = new IllegalStateException(
1904 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001905 if (ar.result == null) {
1906 loge("getSystemSelectionChannels: Empty response");
1907 } else {
1908 loge("getSystemSelectionChannels: Unknown exception");
1909 }
1910 }
1911 notifyRequester(request);
1912 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001913 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1914 ar = (AsyncResult) msg.obj;
1915 request = (MainThreadRequest) ar.userObj;
1916 if (ar.exception == null && ar.result != null) {
1917 request.result = ar.result;
1918 } else {
1919 request.result = -1;
1920 loge("Failed to set Forbidden Plmns");
1921 if (ar.result == null) {
1922 loge("setForbidenPlmns: Empty response");
1923 } else if (ar.exception != null) {
1924 loge("setForbiddenPlmns: Exception: " + ar.exception);
1925 request.result = -1;
1926 } else {
1927 loge("setForbiddenPlmns: Unknown exception");
1928 }
1929 }
1930 notifyRequester(request);
1931 break;
1932 case CMD_SET_FORBIDDEN_PLMNS:
1933 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001934 uiccPort = getUiccPortFromRequest(request);
1935 if (uiccPort == null) {
1936 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001937 request.result = -1;
1938 notifyRequester(request);
1939 break;
1940 }
1941 Pair<Integer, List<String>> setFplmnsArgs =
1942 (Pair<Integer, List<String>>) request.argument;
1943 appType = setFplmnsArgs.first;
1944 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001945 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001946 if (uiccApp == null) {
1947 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1948 request.result = -1;
1949 loge("Failed to get UICC App");
1950 notifyRequester(request);
1951 } else {
1952 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1953 ((SIMRecords) uiccApp.getIccRecords())
1954 .setForbiddenPlmns(onCompleted, fplmns);
1955 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001956 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001957 case CMD_ERASE_MODEM_CONFIG:
1958 request = (MainThreadRequest) msg.obj;
1959 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1960 defaultPhone.eraseModemConfig(onCompleted);
1961 break;
1962 case EVENT_ERASE_MODEM_CONFIG_DONE:
1963 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001964 break;
zoey chene02881a2019-12-30 16:11:23 +08001965
Kai Shif70f46f2021-03-03 13:59:46 -08001966 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1967 request = (MainThreadRequest) msg.obj;
1968 request.result = defaultPhone.eraseDataInSharedPreferences();
1969 notifyRequester(request);
1970 break;
1971
zoey chene02881a2019-12-30 16:11:23 +08001972 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1973 request = (MainThreadRequest) msg.obj;
1974 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1975 Pair<String, String> changed = (Pair<String, String>) request.argument;
1976 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1977 changed.first, changed.second, onCompleted);
1978 break;
1979 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1980 ar = (AsyncResult) msg.obj;
1981 request = (MainThreadRequest) ar.userObj;
1982 if (ar.exception == null) {
1983 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001984 // If the operation is successful, update the PIN storage
1985 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1986 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001987 UiccController.getInstance().getPinStorage()
1988 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001989 } else {
1990 request.result = msg.arg1;
1991 }
1992 notifyRequester(request);
1993 break;
1994
Michele Berionne5e411512020-11-13 02:36:59 +00001995 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001996 request = (MainThreadRequest) msg.obj;
1997 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1998 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1999 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2000 enabled.first, enabled.second, onCompleted);
2001 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002002 }
zoey chene02881a2019-12-30 16:11:23 +08002003 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2004 ar = (AsyncResult) msg.obj;
2005 request = (MainThreadRequest) ar.userObj;
2006 if (ar.exception == null) {
2007 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002008 // If the operation is successful, update the PIN storage
2009 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2010 int phoneId = getPhoneFromRequest(request).getPhoneId();
2011 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002012 UiccController.getInstance().getPinStorage()
2013 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002014 } else {
2015 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2016 }
zoey chene02881a2019-12-30 16:11:23 +08002017 } else {
2018 request.result = msg.arg1;
2019 }
Michele Berionne5e411512020-11-13 02:36:59 +00002020
2021
zoey chene02881a2019-12-30 16:11:23 +08002022 notifyRequester(request);
2023 break;
2024
Peter Wangdafb9ac2020-01-15 14:13:38 -08002025 case MSG_NOTIFY_USER_ACTIVITY:
2026 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002027 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002028 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2029 getDefaultPhone().getContext().sendBroadcastAsUser(
2030 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2031 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002032
2033 case CMD_SET_DATA_THROTTLING: {
2034 request = (MainThreadRequest) msg.obj;
2035 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2036 DataThrottlingRequest dataThrottlingRequest =
2037 (DataThrottlingRequest) request.argument;
2038 Phone phone = getPhoneFromRequest(request);
2039 if (phone != null) {
2040 phone.setDataThrottling(onCompleted,
2041 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2042 dataThrottlingRequest.getCompletionDurationMillis());
2043 } else {
2044 loge("setDataThrottling: No phone object");
2045 request.result =
2046 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2047 notifyRequester(request);
2048 }
2049
2050 break;
2051 }
2052 case EVENT_SET_DATA_THROTTLING_DONE:
2053 ar = (AsyncResult) msg.obj;
2054 request = (MainThreadRequest) ar.userObj;
2055
2056 if (ar.exception == null) {
2057 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2058 } else if (ar.exception instanceof CommandException) {
2059 loge("setDataThrottling: CommandException: " + ar.exception);
2060 CommandException.Error error =
2061 ((CommandException) (ar.exception)).getCommandError();
2062
2063 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2064 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002065 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002066 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2067 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002068 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2069 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002070 } else {
2071 request.result =
2072 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2073 }
2074 } else {
2075 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2076 }
2077 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2078 notifyRequester(request);
2079 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002080
2081 case CMD_SET_SIM_POWER: {
2082 request = (MainThreadRequest) msg.obj;
2083 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2084 request = (MainThreadRequest) msg.obj;
2085 int stateToSet =
2086 ((Pair<Integer, IIntegerConsumer>)
2087 request.argument).first;
2088 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2089 break;
2090 }
2091 case EVENT_SET_SIM_POWER_DONE: {
2092 ar = (AsyncResult) msg.obj;
2093 request = (MainThreadRequest) ar.userObj;
2094 IIntegerConsumer callback =
2095 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2096 if (ar.exception != null) {
2097 loge("setSimPower exception: " + ar.exception);
2098 int errorCode = TelephonyManager.CallForwardingInfoCallback
2099 .RESULT_ERROR_UNKNOWN;
2100 if (ar.exception instanceof CommandException) {
2101 CommandException.Error error =
2102 ((CommandException) (ar.exception)).getCommandError();
2103 if (error == CommandException.Error.SIM_ERR) {
2104 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2105 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2106 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2107 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2108 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2109 } else {
2110 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2111 }
2112 }
2113 try {
2114 callback.accept(errorCode);
2115 } catch (RemoteException e) {
2116 // Ignore if the remote process is no longer available to call back.
2117 Log.w(LOG_TAG, "setSimPower: callback not available.");
2118 }
2119 } else {
2120 try {
2121 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2122 } catch (RemoteException e) {
2123 // Ignore if the remote process is no longer available to call back.
2124 Log.w(LOG_TAG, "setSimPower: callback not available.");
2125 }
2126 }
2127 break;
2128 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002129 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2130 request = (MainThreadRequest) msg.obj;
2131
2132 final Phone phone = getPhoneFromRequest(request);
2133 if (phone == null || phone.getServiceStateTracker() == null) {
2134 request.result = new IllegalStateException("Phone or SST is null");
2135 notifyRequester(request);
2136 break;
2137 }
2138
2139 Pair<Integer, SignalStrengthUpdateRequest> pair =
2140 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2141 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2142 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002143 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002144 request.subId, pair.first /*callingUid*/,
2145 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002146 break;
2147 }
2148 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2149 ar = (AsyncResult) msg.obj;
2150 request = (MainThreadRequest) ar.userObj;
2151 // request.result will be the exception of ar if present, true otherwise.
2152 // Be cautious not to leave result null which will wait() forever
2153 request.result = ar.exception != null ? ar.exception : true;
2154 notifyRequester(request);
2155 break;
2156 }
2157 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2158 request = (MainThreadRequest) msg.obj;
2159
2160 Phone phone = getPhoneFromRequest(request);
2161 if (phone == null || phone.getServiceStateTracker() == null) {
2162 request.result = new IllegalStateException("Phone or SST is null");
2163 notifyRequester(request);
2164 break;
2165 }
2166
2167 Pair<Integer, SignalStrengthUpdateRequest> pair =
2168 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2169 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2170 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002171 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002172 request.subId, pair.first /*callingUid*/,
2173 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002174 break;
2175 }
2176 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2177 ar = (AsyncResult) msg.obj;
2178 request = (MainThreadRequest) ar.userObj;
2179 request.result = ar.exception != null ? ar.exception : true;
2180 notifyRequester(request);
2181 break;
2182 }
Jordan Liu109698e2020-11-24 14:50:34 -08002183
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002184 case CMD_GET_SLICING_CONFIG: {
2185 request = (MainThreadRequest) msg.obj;
2186 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2187 request.phone.getSlicingConfig(onCompleted);
2188 break;
2189 }
2190 case EVENT_GET_SLICING_CONFIG_DONE: {
2191 ar = (AsyncResult) msg.obj;
2192 request = (MainThreadRequest) ar.userObj;
2193 ResultReceiver result = (ResultReceiver) request.argument;
2194
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002195 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002196 Bundle bundle = new Bundle();
2197 int resultCode = 0;
2198 if (ar.exception != null) {
2199 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2200 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002201 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002202 } else if (ar.result == null) {
2203 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002204 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 } else {
2206 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002207 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2208 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 }
2210
2211 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002212 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002213 }
2214 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2215 result.send(resultCode, bundle);
2216 notifyRequester(request);
2217 break;
2218 }
2219
Sarah Chin71b3a852022-09-28 15:54:19 -07002220 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002221 request = (MainThreadRequest) msg.obj;
2222 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002223 PurchasePremiumCapabilityArgument arg =
2224 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002225 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2226 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002229
Sarah Chin71b3a852022-09-28 15:54:19 -07002230 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 ar = (AsyncResult) msg.obj;
2232 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 PurchasePremiumCapabilityArgument arg =
2234 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002235 try {
2236 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002237 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002238 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002239 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002240 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 + TelephonyManager.convertPurchaseResultToString(result));
2242 } catch (RemoteException e) {
2243 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245 + " failed: " + e;
2246 if (DBG) log(logStr);
2247 AnomalyReporter.reportAnomaly(
2248 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2249 }
2250 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252
Michele Berionne5e411512020-11-13 02:36:59 +00002253 case CMD_PREPARE_UNATTENDED_REBOOT:
2254 request = (MainThreadRequest) msg.obj;
2255 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002256 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002257 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002258 notifyRequester(request);
2259 break;
2260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 default:
2262 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2263 break;
2264 }
2265 }
Jake Hambye994d462014-02-03 13:10:13 -08002266
Pengquan Menga1bb6272018-09-06 09:59:22 -07002267 private void notifyRequester(MainThreadRequest request) {
2268 synchronized (request) {
2269 request.notifyAll();
2270 }
2271 }
2272
Jake Hambye994d462014-02-03 13:10:13 -08002273 private void handleNullReturnEvent(Message msg, String command) {
2274 AsyncResult ar = (AsyncResult) msg.obj;
2275 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2276 if (ar.exception == null) {
2277 request.result = true;
2278 } else {
2279 request.result = false;
2280 if (ar.exception instanceof CommandException) {
2281 loge(command + ": CommandException: " + ar.exception);
2282 } else {
2283 loge(command + ": Unknown exception");
2284 }
2285 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002286 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
2290 /**
2291 * Posts the specified command to be executed on the main thread,
2292 * waits for the request to complete, and returns the result.
2293 * @see #sendRequestAsync
2294 */
2295 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002296 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2297 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002298 }
2299
2300 /**
2301 * Posts the specified command to be executed on the main thread,
2302 * waits for the request to complete, and returns the result.
2303 * @see #sendRequestAsync
2304 */
2305 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2306 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002307 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
2309
2310 /**
2311 * Posts the specified command to be executed on the main thread,
2312 * waits for the request to complete, and returns the result.
2313 * @see #sendRequestAsync
2314 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002315 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2317 }
2318
2319 /**
2320 * Posts the specified command to be executed on the main thread,
2321 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2322 * if not timeout or null otherwise.
2323 * @see #sendRequestAsync
2324 */
2325 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2326 long timeoutInMs) {
2327 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002328 }
2329
2330 /**
2331 * Posts the specified command to be executed on the main thread,
2332 * waits for the request to complete, and returns the result.
2333 * @see #sendRequestAsync
2334 */
Nathan Harold92bed182018-10-12 18:16:49 -07002335 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002337 }
2338
2339 /**
2340 * Posts the specified command to be executed on the main thread,
2341 * waits for the request to complete, and returns the result.
2342 * @see #sendRequestAsync
2343 */
2344 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002345 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2346 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002347 }
2348
2349 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002350 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2351 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2352 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002353 * @see #sendRequestAsync
2354 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002355 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2356 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2358 throw new RuntimeException("This method will deadlock if called from the main thread.");
2359 }
2360
Nathan Harold92bed182018-10-12 18:16:49 -07002361 MainThreadRequest request = null;
2362 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2363 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2364 } else if (phone != null) {
2365 request = new MainThreadRequest(argument, phone, workSource);
2366 } else {
2367 request = new MainThreadRequest(argument, subId, workSource);
2368 }
2369
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 Message msg = mMainThreadHandler.obtainMessage(command, request);
2371 msg.sendToTarget();
2372
Rambo Wang0f050d82021-02-12 11:43:36 -08002373
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 if (timeoutInMs >= 0) {
2376 // Wait for at least timeoutInMs before returning null request result
2377 long now = SystemClock.elapsedRealtime();
2378 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002379 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002380 try {
2381 request.wait(deadline - now);
2382 } catch (InterruptedException e) {
2383 // Do nothing, go back and check if request is completed or timeout
2384 } finally {
2385 now = SystemClock.elapsedRealtime();
2386 }
2387 }
2388 } else {
2389 // Wait for the request to complete
2390 while (request.result == null) {
2391 try {
2392 request.wait();
2393 } catch (InterruptedException e) {
2394 // Do nothing, go back and wait until the request is complete
2395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 }
2397 }
2398 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002399 if (request.result == null) {
2400 Log.wtf(LOG_TAG,
2401 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 return request.result;
2404 }
2405
2406 /**
2407 * Asynchronous ("fire and forget") version of sendRequest():
2408 * Posts the specified command to be executed on the main thread, and
2409 * returns immediately.
2410 * @see #sendRequest
2411 */
2412 private void sendRequestAsync(int command) {
2413 mMainThreadHandler.sendEmptyMessage(command);
2414 }
2415
2416 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002417 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002418 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002419 */
2420 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002421 sendRequestAsync(command, argument, null, null);
2422 }
2423
2424 /**
2425 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2426 * @see {@link #sendRequest(int,Object)}
2427 */
2428 private void sendRequestAsync(
2429 int command, Object argument, Phone phone, WorkSource workSource) {
2430 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002431 Message msg = mMainThreadHandler.obtainMessage(command, request);
2432 msg.sendToTarget();
2433 }
2434
2435 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 * Initialize the singleton PhoneInterfaceManager instance.
2437 * This is only done once, at startup, from PhoneApp.onCreate().
2438 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002439 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 synchronized (PhoneInterfaceManager.class) {
2441 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002442 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 } else {
2444 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2445 }
2446 return sInstance;
2447 }
2448 }
2449
2450 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002451 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002453 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002455 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002456 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002457 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2459 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002460 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002461 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002462 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002463 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002464 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002465 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 publish();
arunvoddud7401012022-12-15 16:08:12 +00002467 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002470 @VisibleForTesting
2471 public SharedPreferences getSharedPreferences() {
2472 return mTelephonySharedPreferences;
2473 }
2474
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002475 /**
2476 * Get the default phone for this device.
2477 */
2478 @VisibleForTesting
2479 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002480 Phone thePhone = getPhone(getDefaultSubscription());
2481 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2482 }
2483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 private void publish() {
2485 if (DBG) log("publish: " + this);
2486
Peter Wangc035ce42020-01-08 21:00:22 -08002487 TelephonyFrameworkInitializer
2488 .getTelephonyServiceManager()
2489 .getTelephonyServiceRegisterer()
2490 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492
Stuart Scott584921c2015-01-15 17:10:34 -08002493 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002494 if (request.phone != null) {
2495 return request.phone;
2496 } else {
2497 return getPhoneFromSubId(request.subId);
2498 }
2499 }
2500
2501 private Phone getPhoneFromSubId(int subId) {
2502 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2503 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002504 }
2505
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002506 /**
2507 * Get phone object associated with a subscription.
2508 * Return default phone if phone object associated with subscription is null
2509 * @param subId - subscriptionId
2510 * @return phone object associated with a subscription or default phone if null.
2511 */
Ling Mac28f0212023-03-24 16:07:15 -07002512 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002513 Phone phone = getPhoneFromSubId(subId);
2514 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002515 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002516 phone = getDefaultPhone();
2517 }
2518 return phone;
2519 }
2520
Rambo Wange53e07d2022-05-10 13:01:13 -07002521 @Nullable
2522 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002523 Phone phone = getPhoneFromRequest(request);
2524 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002525 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002526 }
2527
Ling Mac28f0212023-03-24 16:07:15 -07002528 /**
2529 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2530 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2531 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2532 * @return The Phone associated the sub Id
2533 */
2534 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002535 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
Kai Shif70f46f2021-03-03 13:59:46 -08002538 private void sendEraseModemConfig(@NonNull Phone phone) {
2539 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2540 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2541 }
2542
2543 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2544 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2545 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002546 }
2547
Peter Wang44b186e2020-01-13 23:33:09 -08002548 private boolean isImsAvailableOnDevice() {
2549 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2550 if (pm == null) {
2551 // For some reason package manger is not available.. This will fail internally anyway,
2552 // so do not throw error and allow.
2553 return true;
2554 }
2555 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2556 }
2557
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002559 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002560 }
2561
Wink Savilleb564aae2014-10-23 10:18:09 -07002562 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 if (DBG) log("dial: " + number);
2564 // No permission check needed here: This is just a wrapper around the
2565 // ACTION_DIAL intent, which is available to any app since it puts up
2566 // the UI before it does anything.
2567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 String url = createTelUrl(number);
2571 if (url == null) {
2572 return;
2573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 // PENDING: should we just silently fail if phone is offhook or ringing?
2576 PhoneConstants.State state = mCM.getState(subId);
2577 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2578 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2579 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2580 mApp.startActivity(intent);
2581 }
2582 } finally {
2583 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 }
2585 }
2586
2587 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002588 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002589 }
2590
Wink Savilleb564aae2014-10-23 10:18:09 -07002591 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 if (DBG) log("call: " + number);
2593
2594 // This is just a wrapper around the ACTION_CALL intent, but we still
2595 // need to do a permission check since we're calling startActivity()
2596 // from the context of the phone app.
2597 enforceCallPermission();
2598
Jordan Liu1617b712019-07-10 15:06:26 -07002599 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 != AppOpsManager.MODE_ALLOWED) {
2601 return;
2602 }
2603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 final long identity = Binder.clearCallingIdentity();
2605 try {
2606 String url = createTelUrl(number);
2607 if (url == null) {
2608 return;
2609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 boolean isValid = false;
2612 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2613 if (slist != null) {
2614 for (SubscriptionInfo subInfoRecord : slist) {
2615 if (subInfoRecord.getSubscriptionId() == subId) {
2616 isValid = true;
2617 break;
2618 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002619 }
Wink Saville08874612014-08-31 19:19:58 -07002620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 if (!isValid) {
2622 return;
2623 }
Wink Saville08874612014-08-31 19:19:58 -07002624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2626 intent.putExtra(SUBSCRIPTION_KEY, subId);
2627 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2628 mApp.startActivity(intent);
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
2631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 }
2633
Wink Savilleb564aae2014-10-23 10:18:09 -07002634 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002635 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002636 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2637 }
2638
Wink Savilleb564aae2014-10-23 10:18:09 -07002639 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002640 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002641 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2642 }
2643
Wink Savilleb564aae2014-10-23 10:18:09 -07002644 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646
2647 final long identity = Binder.clearCallingIdentity();
2648 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002649 Phone phone = getPhone(subId);
2650 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 checkSimPin.start();
2652 return checkSimPin.unlockSim(null, pin);
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
Wink Savilleb564aae2014-10-23 10:18:09 -07002658 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002663 Phone phone = getPhone(subId);
2664 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 checkSimPuk.start();
2666 return checkSimPuk.unlockSim(puk, pin);
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
2672 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002673 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 * a synchronous one.
2675 */
2676 private static class UnlockSim extends Thread {
2677
2678 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002679 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680
2681 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002682 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2683 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684
2685 // For replies from SimCard interface
2686 private Handler mHandler;
2687
2688 // For async handler to identify request type
2689 private static final int SUPPLY_PIN_COMPLETE = 100;
2690
Michele Berionne5e411512020-11-13 02:36:59 +00002691 UnlockSim(int phoneId, IccCard simCard) {
2692 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 mSimCard = simCard;
2694 }
2695
2696 @Override
2697 public void run() {
2698 Looper.prepare();
2699 synchronized (UnlockSim.this) {
2700 mHandler = new Handler() {
2701 @Override
2702 public void handleMessage(Message msg) {
2703 AsyncResult ar = (AsyncResult) msg.obj;
2704 switch (msg.what) {
2705 case SUPPLY_PIN_COMPLETE:
2706 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2707 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002708 mRetryCount = msg.arg1;
2709 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002710 CommandException.Error error = null;
2711 if (ar.exception instanceof CommandException) {
2712 error = ((CommandException) (ar.exception))
2713 .getCommandError();
2714 }
2715 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002716 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002717 } else if (error == CommandException.Error.ABORTED) {
2718 /* When UiccCardApp dispose, handle message and return
2719 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002720 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002721 } else {
2722 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2723 }
2724 } else {
2725 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 mDone = true;
2728 UnlockSim.this.notifyAll();
2729 }
2730 break;
2731 }
2732 }
2733 };
2734 UnlockSim.this.notifyAll();
2735 }
2736 Looper.loop();
2737 }
2738
2739 /*
2740 * Use PIN or PUK to unlock SIM card
2741 *
2742 * If PUK is null, unlock SIM card with PIN
2743 *
2744 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302745 *
2746 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2747 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 */
Wink Saville9de0f752013-10-22 19:04:03 -07002749 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750
2751 while (mHandler == null) {
2752 try {
2753 wait();
2754 } catch (InterruptedException e) {
2755 Thread.currentThread().interrupt();
2756 }
2757 }
2758 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2759
2760 if (puk == null) {
2761 mSimCard.supplyPin(pin, callback);
2762 } else {
2763 mSimCard.supplyPuk(puk, pin, callback);
2764 }
2765
2766 while (!mDone) {
2767 try {
2768 Log.d(LOG_TAG, "wait for done");
2769 wait();
2770 } catch (InterruptedException e) {
2771 // Restore the interrupted status
2772 Thread.currentThread().interrupt();
2773 }
2774 }
2775 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002776 int[] resultArray = new int[2];
2777 resultArray[0] = mResult;
2778 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002779
2780 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002781 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002782 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302783 // This instance is no longer reused, so quit its thread's looper.
2784 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002785
Wink Saville9de0f752013-10-22 19:04:03 -07002786 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788 }
2789
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002790 /**
2791 * This method has been removed due to privacy and stability concerns.
2792 */
2793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002795 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2796 return;
Wink Saville36469e72014-06-11 15:17:00 -07002797 }
2798
Nathan Harold1f889d82020-06-04 17:05:26 -07002799 @Override
2800 public void updateServiceLocationWithPackageName(String callingPackage) {
2801 mApp.getSystemService(AppOpsManager.class)
2802 .checkPackage(Binder.getCallingUid(), callingPackage);
2803
Nathan Haroldf096d982020-11-18 17:18:06 -08002804 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002805 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2806 // Callers targeting S have no business invoking this method.
2807 return;
2808 }
2809
2810 LocationAccessPolicy.LocationPermissionResult locationResult =
2811 LocationAccessPolicy.checkLocationPermission(mApp,
2812 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2813 .setCallingPackage(callingPackage)
2814 .setCallingFeatureId(null)
2815 .setCallingPid(Binder.getCallingPid())
2816 .setCallingUid(Binder.getCallingUid())
2817 .setMethod("updateServiceLocation")
2818 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2819 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2820 .build());
2821 // Apps that lack location permission have no business calling this method;
2822 // however, because no permission was declared in the public API, denials must
2823 // all be "soft".
2824 switch (locationResult) {
2825 case DENIED_HARD: /* fall through */
2826 case DENIED_SOFT:
2827 return;
2828 }
2829
2830 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 final long identity = Binder.clearCallingIdentity();
2832 try {
Ling Mac28f0212023-03-24 16:07:15 -07002833 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 }
2838
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002839 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002840 @Override
2841 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002842 return isRadioOnWithFeature(callingPackage, null);
2843 }
2844
2845
2846 @Override
2847 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2848 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2849 callingFeatureId);
2850 }
2851
2852 @Deprecated
2853 @Override
2854 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2855 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002856 }
2857
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2860 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002862 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002863 return false;
2864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
2868 return isRadioOnForSubscriber(subId);
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002872 }
2873
2874 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 final Phone phone = getPhone(subId);
2878 if (phone != null) {
2879 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2880 } else {
2881 return false;
2882 }
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
2887
2888 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002889 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
Wink Saville36469e72014-06-11 15:17:00 -07002891
Wink Savilleb564aae2014-10-23 10:18:09 -07002892 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002893 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894
2895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 final Phone phone = getPhone(subId);
2898 if (phone != null) {
2899 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2900 }
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002903 }
Wink Saville36469e72014-06-11 15:17:00 -07002904 }
2905
2906 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002907 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002908 }
2909
Wink Savilleb564aae2014-10-23 10:18:09 -07002910 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002911 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912
2913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 final Phone phone = getPhone(subId);
2916 if (phone == null) {
2917 return false;
2918 }
2919 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2920 toggleRadioOnOffForSubscriber(subId);
2921 }
2922 return true;
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
Wink Saville36469e72014-06-11 15:17:00 -07002927
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002928 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002929 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002930 /*
2931 * If any of the Radios are available, it will need to be
2932 * shutdown. So return true if any Radio is available.
2933 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2937 Phone phone = PhoneFactory.getPhone(i);
2938 if (phone != null && phone.isRadioAvailable()) return true;
2939 }
2940 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2941 return false;
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002944 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002945 }
2946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002948 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949 enforceModifyPermission();
2950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2954 logv("Shutting down Phone " + i);
2955 shutdownRadioUsingPhoneId(i);
2956 }
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002959 }
2960 }
2961
2962 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002963 Phone phone = PhoneFactory.getPhone(phoneId);
2964 if (phone != null && phone.isRadioAvailable()) {
2965 phone.shutdownRadio();
2966 }
2967 }
2968
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002970 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971
Ling Ma83dc5ea2023-01-12 15:06:04 -08002972 if (!turnOn) {
2973 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2974 }
2975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2979 if (defaultPhone != null) {
2980 defaultPhone.setRadioPower(turnOn);
2981 return true;
2982 } else {
2983 loge("There's no default phone.");
2984 return false;
2985 }
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002988 }
Wink Saville36469e72014-06-11 15:17:00 -07002989 }
2990
Wink Savilleb564aae2014-10-23 10:18:09 -07002991 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993
Ling Ma83dc5ea2023-01-12 15:06:04 -08002994 if (!turnOn) {
2995 log("setRadioPowerForSubscriber off: subId=" + subId
2996 + ",callingPackage=" + getCurrentPackageName());
2997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 final Phone phone = getPhone(subId);
3001 if (phone != null) {
3002 phone.setRadioPower(turnOn);
3003 return true;
3004 } else {
3005 return false;
3006 }
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 }
3011
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003012 /**
3013 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3014 * no reason to power it off. When any of the voters want to power it off, it will be turned
3015 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3016 * powering it off, and these radio off votes will be cleared.
3017 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3018 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3019 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3020 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3021 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3022 * check its vote.
3023 *
3024 * @param subId The subscription ID.
3025 * @param reason The reason for powering off radio.
3026 * @return true on success and false on failure.
3027 */
3028 public boolean requestRadioPowerOffForReason(int subId,
3029 @TelephonyManager.RadioPowerReason int reason) {
3030 enforceModifyPermission();
3031
Ling Ma83dc5ea2023-01-12 15:06:04 -08003032 log("requestRadioPowerOffForReason: subId=" + subId
3033 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003034 final long identity = Binder.clearCallingIdentity();
3035 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003036 boolean result = false;
3037 for (Phone phone : PhoneFactory.getPhones()) {
3038 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003039 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003040 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003041 if (!result) {
3042 loge("requestRadioPowerOffForReason: no phone exists");
3043 }
3044 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 /**
3051 * Remove the vote on powering off the radio for a reason, as requested by
3052 * {@link requestRadioPowerOffForReason}.
3053 *
3054 * @param subId The subscription ID.
3055 * @param reason The reason for powering off radio.
3056 * @return true on success and false on failure.
3057 */
3058 public boolean clearRadioPowerOffForReason(int subId,
3059 @TelephonyManager.RadioPowerReason int reason) {
3060 enforceModifyPermission();
3061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003064 boolean result = false;
3065 for (Phone phone : PhoneFactory.getPhones()) {
3066 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003067 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003068 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003069 if (!result) {
3070 loge("clearRadioPowerOffForReason: no phone exists");
3071 }
3072 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 /**
3079 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3080 *
3081 * @param subId The subscription ID.
3082 * @param callingPackage The package making the call.
3083 * @param callingFeatureId The feature in the package.
3084 * @return List of reasons for powering off radio.
3085 */
3086 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3087 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3088
3089 final long identity = Binder.clearCallingIdentity();
3090 List result = new ArrayList();
3091 try {
3092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3093 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3094 return result;
3095 }
3096
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003097 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003098 if (phone != null) {
3099 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003100 } else {
3101 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003102 }
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 return result;
3107 }
3108
Wink Saville36469e72014-06-11 15:17:00 -07003109 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003110 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003111 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
Jack Yu285100e2022-12-02 22:48:35 -08003116 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 final Phone phone = getPhone(subId);
3118 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003119 phone.getDataSettingsManager().setDataEnabled(
3120 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121 return true;
3122 } else {
3123 return false;
3124 }
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 }
3129
Wink Saville36469e72014-06-11 15:17:00 -07003130 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003132 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
Jack Yu285100e2022-12-02 22:48:35 -08003137 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 final Phone phone = getPhone(subId);
3139 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003140 phone.getDataSettingsManager().setDataEnabled(
3141 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142 return true;
3143 } else {
3144 return false;
3145 }
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 }
3150
Sanket Padawe356d7632015-06-22 14:03:32 -07003151 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003152 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 final Phone phone = getPhone(subId);
3156 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003157 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 } else {
3159 return false;
3160 }
3161 } finally {
3162 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003163 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164 }
3165
3166 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003167 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003168 }
3169
pkanwarae03a6b2016-11-06 20:37:09 -08003170 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 enforceCallPermission();
3172
3173 final long identity = Binder.clearCallingIdentity();
3174 try {
3175 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3176 return;
3177 }
3178 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3179 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
pkanwar32d516d2016-10-14 19:37:38 -07003183 };
3184
Wink Savilleb564aae2014-10-23 10:18:09 -07003185 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187
3188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3191 return false;
3192 }
3193 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003199 /**
3200 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3201 * tag on getCallState Binder call.
3202 */
3203 @Deprecated
3204 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003206 if (CompatChanges.isChangeEnabled(
3207 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3208 Binder.getCallingUid())) {
3209 // Do not allow this API to be called on API version 31+, it should only be
3210 // called on old apps using this Binder call directly.
3211 throw new SecurityException("This method can only be used for applications "
3212 + "targeting API version 30 or less.");
3213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
Ling Mac28f0212023-03-24 16:07:15 -07003216 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3217 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
3221 }
3222
3223 @Override
3224 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3225 if (CompatChanges.isChangeEnabled(
3226 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3227 Binder.getCallingUid())) {
3228 // Check READ_PHONE_STATE for API version 31+
3229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3230 featureId, "getCallStateForSubscription")) {
3231 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3232 + "targeting API level 31+.");
3233 }
3234 }
3235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3239 PhoneConstantConversions.convertCallState(phone.getState());
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 }
3244
Sanket Padawe356d7632015-06-22 14:03:32 -07003245 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003246 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003247 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003248 }
3249
3250 @Override
3251 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 final long identity = Binder.clearCallingIdentity();
3253 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003254 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003256 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 } else {
3258 return PhoneConstantConversions.convertDataState(
3259 PhoneConstants.DataState.DISCONNECTED);
3260 }
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 }
3265
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003267 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003268 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003269 }
3270
3271 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003272 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 final long identity = Binder.clearCallingIdentity();
3274 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003275 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003277 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 } else {
3279 return TelephonyManager.DATA_ACTIVITY_NONE;
3280 }
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
3286 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003287 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003288 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003289 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003290
3291 LocationAccessPolicy.LocationPermissionResult locationResult =
3292 LocationAccessPolicy.checkLocationPermission(mApp,
3293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3294 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003295 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003296 .setCallingPid(Binder.getCallingPid())
3297 .setCallingUid(Binder.getCallingUid())
3298 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003299 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003300 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3301 .build());
3302 switch (locationResult) {
3303 case DENIED_HARD:
3304 throw new SecurityException("Not allowed to access cell location");
3305 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003306 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3307 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 }
3309
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003314 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003315 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Svetoslav64fad262015-04-14 14:35:21 -07003319 }
3320
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003322 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003323 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3324 // registered cell info, so return a NULL country instead.
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003327 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3328 // Get default phone in this case.
3329 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3330 }
Jack Yu285100e2022-12-02 22:48:35 -08003331 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003333 if (phone == null) return "";
3334 ServiceStateTracker sst = phone.getServiceStateTracker();
3335 if (sst == null) return "";
3336 LocaleTracker lt = sst.getLocaleTracker();
3337 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003338 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003342 }
3343
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003344 /**
3345 * This method was removed due to potential issues caused by performing partial
3346 * updates of service state, and lack of a credible use case.
3347 *
3348 * This has the ability to break the telephony implementation by disabling notification of
3349 * changes in device connectivity. DO NOT USE THIS!
3350 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003351 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 public void enableLocationUpdates() {
3353 mApp.enforceCallingOrSelfPermission(
3354 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 }
3356
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003357 /**
3358 * This method was removed due to potential issues caused by performing partial
3359 * updates of service state, and lack of a credible use case.
3360 *
3361 * This has the ability to break the telephony implementation by disabling notification of
3362 * changes in device connectivity. DO NOT USE THIS!
3363 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 @Override
3365 public void disableLocationUpdates() {
3366 mApp.enforceCallingOrSelfPermission(
3367 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 }
3369
3370 @Override
3371 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003372 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3373 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003374 try {
3375 mApp.getSystemService(AppOpsManager.class)
3376 .checkPackage(Binder.getCallingUid(), callingPackage);
3377 } catch (SecurityException e) {
3378 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3379 throw e;
3380 }
3381
Nathan Haroldf096d982020-11-18 17:18:06 -08003382 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003383 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3384 throw new SecurityException(
3385 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3386 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003387
Jordan Liu1617b712019-07-10 15:06:26 -07003388 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3390 return null;
3391 }
Svetoslav64fad262015-04-14 14:35:21 -07003392
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003393 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003395 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003396 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397
Nathan Haroldf180aac2018-06-01 18:43:55 -07003398 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3399 for (CellInfo ci : info) {
3400 if (ci instanceof CellInfoGsm) {
3401 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3402 } else if (ci instanceof CellInfoWcdma) {
3403 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003406 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 }
3408
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003409 private List<CellInfo> getCachedCellInfo() {
3410 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3411 for (Phone phone : PhoneFactory.getPhones()) {
3412 List<CellInfo> info = phone.getAllCellInfo();
3413 if (info != null) cellInfos.addAll(info);
3414 }
3415 return cellInfos;
3416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003417
3418 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003419 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003420 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003421 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003422
3423 LocationAccessPolicy.LocationPermissionResult locationResult =
3424 LocationAccessPolicy.checkLocationPermission(mApp,
3425 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3426 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003427 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003428 .setCallingPid(Binder.getCallingPid())
3429 .setCallingUid(Binder.getCallingUid())
3430 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003431 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003432 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3433 .build());
3434 switch (locationResult) {
3435 case DENIED_HARD:
3436 throw new SecurityException("Not allowed to access cell info");
3437 case DENIED_SOFT:
3438 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 }
3440
Nathan Haroldf096d982020-11-18 17:18:06 -08003441 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003442 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3443 return getCachedCellInfo();
3444 }
3445
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003446 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3451 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003452 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003453 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454 if (info != null) cellInfos.addAll(info);
3455 }
3456 return cellInfos;
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 }
3460 }
3461
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003462 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003463 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3464 String callingFeatureId) {
3465 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3466 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003467 }
3468
3469 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003470 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3471 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003472 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003473 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003474 }
3475
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003476 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3477 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003479 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003480
3481 LocationAccessPolicy.LocationPermissionResult locationResult =
3482 LocationAccessPolicy.checkLocationPermission(mApp,
3483 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3484 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003485 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003486 .setCallingPid(Binder.getCallingPid())
3487 .setCallingUid(Binder.getCallingUid())
3488 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003489 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3490 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003491 .build());
3492 switch (locationResult) {
3493 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003494 if (TelephonyPermissions
3495 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003496 // Safetynet logging for b/154934934
3497 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3498 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003499 throw new SecurityException("Not allowed to access cell info");
3500 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003501 if (TelephonyPermissions
3502 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003503 // Safetynet logging for b/154934934
3504 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3505 }
Nathan Harold5320c422019-05-09 10:26:08 -07003506 try {
3507 cb.onCellInfo(new ArrayList<CellInfo>());
3508 } catch (RemoteException re) {
3509 // Drop without consequences
3510 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003511 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003512 }
3513
Nathan Harolda939a962019-05-09 10:13:47 -07003514
3515 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003516 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3517
3518 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3519 }
3520
3521 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003522 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003523 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003524 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003528 Phone phone = getPhone(subId);
3529 if (phone == null) {
3530 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3531 } else {
3532 phone.setCellInfoListRate(rateInMillis, workSource);
3533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 }
3538
Shishir Agrawala9f32182016-04-12 12:00:16 -07003539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003540 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 Phone phone = PhoneFactory.getPhone(slotIndex);
3542 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 return null;
3544 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003546 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003547 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003549 return null;
3550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 return phone.getImei();
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003558 }
3559
3560 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003561 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3562 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3563 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3564 callingFeatureId, "getPrimaryImei")) {
3565 throw new SecurityException("Caller does not have permission");
3566 }
3567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 for (Phone phone : PhoneFactory.getPhones()) {
3570 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3571 return phone.getImei();
3572 }
3573 }
3574 throw new UnsupportedOperationException("Operation not supported");
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
3580 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003581 public String getTypeAllocationCodeForSlot(int slotIndex) {
3582 Phone phone = PhoneFactory.getPhone(slotIndex);
3583 String tac = null;
3584 if (phone != null) {
3585 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003586 try {
3587 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3588 } catch (IndexOutOfBoundsException e) {
3589 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3590 return null;
3591 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003592 }
3593 return tac;
3594 }
3595
3596 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003597 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003598 try {
3599 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3600 } catch (SecurityException se) {
3601 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3602 throw new SecurityException("Package " + callingPackage + " does not belong to "
3603 + Binder.getCallingUid());
3604 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003605 Phone phone = PhoneFactory.getPhone(slotIndex);
3606 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003607 return null;
3608 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609
Jeff Davidson913390f2018-02-23 17:11:49 -08003610 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003611 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003612 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003613 return null;
3614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615
3616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 return phone.getMeid();
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
3621 }
Jack Yu2af8d712017-03-15 17:14:14 -07003622 }
3623
3624 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003625 public String getManufacturerCodeForSlot(int slotIndex) {
3626 Phone phone = PhoneFactory.getPhone(slotIndex);
3627 String manufacturerCode = null;
3628 if (phone != null) {
3629 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003630 try {
3631 manufacturerCode =
3632 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3633 } catch (IndexOutOfBoundsException e) {
3634 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3635 return null;
3636 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003637 }
3638 return manufacturerCode;
3639 }
3640
3641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003642 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3643 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 Phone phone = PhoneFactory.getPhone(slotIndex);
3645 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003646 return null;
3647 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 int subId = phone.getSubId();
3649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003650 mApp, subId, callingPackage, callingFeatureId,
3651 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003652 return null;
3653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 return phone.getDeviceSvn();
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003661 }
3662
fionaxu43304da2017-11-27 22:51:16 -08003663 @Override
3664 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
3668 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
fionaxu43304da2017-11-27 22:51:16 -08003672 }
3673
3674 @Override
3675 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = getPhone(subId);
3679 return phone == null ? null : phone.getCarrierName();
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
fionaxu43304da2017-11-27 22:51:16 -08003683 }
3684
calvinpanffe225e2018-11-01 19:43:06 +08003685 @Override
chen xu0026ca62019-03-06 15:28:50 -08003686 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 final Phone phone = getPhone(subId);
3690 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003691 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
3697 @Override
chen xu0026ca62019-03-06 15:28:50 -08003698 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003702 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
3706 }
3707
chen xu651eec72018-11-11 19:03:44 -08003708 @Override
chen xu864e11c2018-12-06 22:10:03 -08003709 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3710 if (!isSubscriptionMccMnc) {
3711 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3712 }
chen xu651eec72018-11-11 19:03:44 -08003713 final Phone phone = PhoneFactory.getPhone(slotIndex);
3714 if (phone == null) {
3715 return TelephonyManager.UNKNOWN_CARRIER_ID;
3716 }
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003725 //
3726 // Internal helper methods.
3727 //
3728
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003729 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003730 * Make sure the caller is the calling package itself
3731 *
3732 * @throws SecurityException if the caller is not the calling package
3733 */
3734 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3735 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003736 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3737 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003738 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003739 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003740 } catch (PackageManager.NameNotFoundException e) {
3741 // packageUid is -1
3742 }
3743 if (packageUid != callingUid) {
3744 throw new SecurityException(message + ": Package " + callingPackage
3745 + " does not belong to " + callingUid);
3746 }
3747 }
3748
3749 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003750 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3751 *
3752 * @throws SecurityException if the caller does not have the required permission
3753 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003754 @VisibleForTesting
3755 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003756 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3757 }
3758
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003759 /**
arunvoddud7401012022-12-15 16:08:12 +00003760 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003761 *
3762 * @throws SecurityException if the caller does not have the required permission
3763 */
3764 @VisibleForTesting
3765 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003766 enforceReadPermission(null);
3767 }
3768
3769 /**
3770 * Make sure the caller has the READ_PHONE_STATE permissions.
3771 *
3772 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3773 */
3774 @VisibleForTesting
3775 public void enforceReadPermission(String msg) {
3776 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003777 }
3778
Shuo Qian3b6ee772019-11-13 17:43:31 -08003779 private void enforceActiveEmergencySessionPermission() {
3780 mApp.enforceCallingOrSelfPermission(
3781 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3782 }
3783
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003784 /**
3785 * Make sure the caller has the CALL_PHONE permission.
3786 *
3787 * @throws SecurityException if the caller does not have the required permission
3788 */
3789 private void enforceCallPermission() {
3790 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3791 }
3792
paulhu5a773602019-08-23 19:17:33 +08003793 private void enforceSettingsPermission() {
3794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003795 }
3796
Michele Berionne5e411512020-11-13 02:36:59 +00003797 private void enforceRebootPermission() {
3798 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3799 }
3800
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003801 /**
3802 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3803 * @param message - log message to print.
3804 * @throws SecurityException if the caller does not have the required permission
3805 */
3806 private void enforceSatelliteCommunicationPermission(String message) {
3807 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3808 }
3809
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003810 private String createTelUrl(String number) {
3811 if (TextUtils.isEmpty(number)) {
3812 return null;
3813 }
3814
Jake Hambye994d462014-02-03 13:10:13 -08003815 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Ihab Awadf9e92732013-12-05 18:02:52 -08003818 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003819 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003820 }
3821
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003822 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003823 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003824 }
3825
Ihab Awadf9e92732013-12-05 18:02:52 -08003826 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003827 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003828 }
3829
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003831 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003832 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003833 }
3834
Sanket Padawe356d7632015-06-22 14:03:32 -07003835 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003836 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 final Phone phone = PhoneFactory.getPhone(slotIndex);
3840 if (phone == null) {
3841 return PhoneConstants.PHONE_TYPE_NONE;
3842 } else {
3843 return phone.getPhoneType();
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003848 }
3849
3850 /**
3851 * Returns the CDMA ERI icon index to display
3852 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003854 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3855 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3856 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003857 }
3858
Sanket Padawe356d7632015-06-22 14:03:32 -07003859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003860 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3861 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003863 mApp, subId, callingPackage, callingFeatureId,
3864 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003865 return -1;
3866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 final Phone phone = getPhone(subId);
3871 if (phone != null) {
3872 return phone.getCdmaEriIconIndex();
3873 } else {
3874 return -1;
3875 }
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003879 }
3880
3881 /**
3882 * Returns the CDMA ERI icon mode,
3883 * 0 - ON
3884 * 1 - FLASHING
3885 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003887 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3888 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3889 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003890 }
3891
Sanket Padawe356d7632015-06-22 14:03:32 -07003892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003893 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3894 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003896 mApp, subId, callingPackage, callingFeatureId,
3897 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003898 return -1;
3899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900
3901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 final Phone phone = getPhone(subId);
3904 if (phone != null) {
3905 return phone.getCdmaEriIconMode();
3906 } else {
3907 return -1;
3908 }
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 }
3913
3914 /**
3915 * Returns the CDMA ERI text,
3916 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003918 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3919 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3920 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003921 }
3922
Sanket Padawe356d7632015-06-22 14:03:32 -07003923 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003924 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3925 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003927 mApp, subId, callingPackage, callingFeatureId,
3928 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003929 return null;
3930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 final Phone phone = getPhone(subId);
3935 if (phone != null) {
3936 return phone.getCdmaEriText();
3937 } else {
3938 return null;
3939 }
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003943 }
3944
3945 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003946 * Returns the CDMA MDN.
3947 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003948 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003949 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3951 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003956 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 return phone.getLine1Number();
3958 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003959 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 return null;
3961 }
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003964 }
3965 }
3966
3967 /**
3968 * Returns the CDMA MIN.
3969 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003970 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003971 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3973 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974
3975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 final Phone phone = getPhone(subId);
3978 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3979 return phone.getCdmaMin();
3980 } else {
3981 return null;
3982 }
3983 } finally {
3984 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003985 }
3986 }
3987
Hall Liud892bec2018-11-30 14:51:45 -08003988 @Override
3989 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3990 INumberVerificationCallback callback, String callingPackage) {
3991 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3992 != PERMISSION_GRANTED) {
3993 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3994 }
3995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3996
3997 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3998 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003999 throw new SecurityException("Calling package must be configured in the device config: "
4000 + "calling package: " + callingPackage
4001 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004002 }
4003
4004 if (range == null) {
4005 throw new NullPointerException("Range must be non-null");
4006 }
4007
4008 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004009 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004010
4011 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4012 }
4013
Junda Liuca05d5d2014-08-14 22:36:34 -07004014 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004015 * Returns true if CDMA provisioning needs to run.
4016 */
4017 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 final long identity = Binder.clearCallingIdentity();
4019 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004024 }
4025
4026 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004027 * Sets the voice mail number of a given subId.
4028 */
4029 @Override
4030 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004031 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4032 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4037 new Pair<String, String>(alphaTag, number), new Integer(subId));
4038 return success;
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004042 }
4043
Ta-wei Yen87c49842016-05-13 21:19:52 -07004044 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004045 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004047 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4048 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004049 if (!TextUtils.equals(callingPackage, systemDialer)) {
4050 throw new SecurityException("caller must be system dialer");
4051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4056 if (phoneAccountHandle == null) {
4057 return null;
4058 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060 } finally {
4061 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004062 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004063 }
4064
4065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4067 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004070 mApp, subId, callingPackage, callingFeatureId,
4071 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004072 return null;
4073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004075 final long identity = Binder.clearCallingIdentity();
4076 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004077 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004081 }
4082
4083 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004084 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4085 VisualVoicemailSmsFilterSettings settings) {
4086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004091 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004095 }
4096
4097 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004098 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004108 }
4109
4110 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004111 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4112 String callingPackage, int subId) {
4113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114
4115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004118 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004122 }
4123
4124 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004125 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004131 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004135 }
4136
4137 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004138 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4139 String callingAttributionTag, int subId, String number, int port, String text,
4140 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004141 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004142 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004143 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004144 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004145 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4146 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004147 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004148
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004149 /**
fionaxu0152e512016-11-14 13:36:14 -08004150 * Sets the voice activation state of a given subId.
4151 */
4152 @Override
4153 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4155 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 final Phone phone = getPhone(subId);
4160 if (phone != null) {
4161 phone.setVoiceActivationState(activationState);
4162 } else {
4163 loge("setVoiceActivationState fails with invalid subId: " + subId);
4164 }
4165 } finally {
4166 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004167 }
4168 }
4169
4170 /**
4171 * Sets the data activation state of a given subId.
4172 */
4173 @Override
4174 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4176 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 final Phone phone = getPhone(subId);
4181 if (phone != null) {
4182 phone.setDataActivationState(activationState);
4183 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004184 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185 }
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004188 }
4189 }
4190
4191 /**
4192 * Returns the voice activation state of a given subId.
4193 */
4194 @Override
4195 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197
fionaxu0152e512016-11-14 13:36:14 -08004198 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 if (phone != null) {
4202 return phone.getVoiceActivationState();
4203 } else {
4204 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4205 }
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004208 }
4209 }
4210
4211 /**
4212 * Returns the data activation state of a given subId.
4213 */
4214 @Override
4215 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217
fionaxu0152e512016-11-14 13:36:14 -08004218 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 if (phone != null) {
4222 return phone.getDataActivationState();
4223 } else {
4224 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4225 }
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004228 }
4229 }
4230
4231 /**
Wink Saville36469e72014-06-11 15:17:00 -07004232 * Returns the unread count of voicemails for a subId
4233 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004235 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4236 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004238 mApp, subId, callingPackage, callingFeatureId,
4239 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004240 return 0;
4241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 final Phone phone = getPhone(subId);
4245 if (phone != null) {
4246 return phone.getVoiceMessageCount();
4247 } else {
4248 return 0;
4249 }
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004253 }
4254
4255 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004256 * returns true, if the device is in a state where both voice and data
4257 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004258 */
4259 @Override
4260 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
Ling Mac28f0212023-03-24 16:07:15 -07004263 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004267 }
4268
4269 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004270 * Send the dialer code if called from the current default dialer or the caller has
4271 * carrier privilege.
4272 * @param inputCode The dialer code to send
4273 */
4274 @Override
4275 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004276 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004277 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004278 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4279 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004280 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004281 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004282 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284
4285 final long identity = Binder.clearCallingIdentity();
4286 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004287 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
fionaxu235cc5e2017-03-06 22:25:57 -08004291 }
4292
Pengquan Menga1bb6272018-09-06 09:59:22 -07004293 @Override
4294 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004295 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004296 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4297 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 if (!isActiveSubscription(subId)) {
4301 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4302 }
4303 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4304 } finally {
4305 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004307 }
4308
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004310 public boolean isInEmergencySmsMode() {
4311 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 for (Phone phone : PhoneFactory.getPhones()) {
4315 if (phone.isInEmergencySmsMode()) {
4316 return true;
4317 }
4318 }
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 return false;
4323 }
4324
shilu366312e2019-12-17 09:28:10 -08004325 /**
4326 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4327 * @param subId The subscription to use to check the configuration.
4328 * @param c The callback that will be used to send the result.
4329 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004330 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004331 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4332 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004333 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004334 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004335
4336 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4337 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4338 "IMS not available on device.");
4339 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 final long token = Binder.clearCallingIdentity();
4341 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004342 int slotId = getSlotIndexOrException(subId);
4343 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004344
4345 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4346 if (controller != null) {
4347 ImsManager imsManager = controller.getImsManager(subId);
4348 if (imsManager != null) {
4349 imsManager.addRegistrationCallbackForSubscription(c, subId);
4350 } else {
4351 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4352 }
4353 } else {
4354 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4355 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 } finally {
4359 Binder.restoreCallingIdentity(token);
4360 }
4361 }
4362
shilu366312e2019-12-17 09:28:10 -08004363 /**
4364 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4365 * @param subId The subscription to use to check the configuration.
4366 * @param c The callback that will be used to send the result.
4367 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004369 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004370 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004371 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004372 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4373 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4374 }
Meng Wangafbc5852019-09-19 17:37:13 -07004375 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004376
Meng Wangafbc5852019-09-19 17:37:13 -07004377 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004378 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4379 if (controller != null) {
4380 ImsManager imsManager = controller.getImsManager(subId);
4381 if (imsManager != null) {
4382 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4383 } else {
4384 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4385 + "is inactive, ignoring unregister.");
4386 // If the ImsManager is not valid, just return, since the callback
4387 // will already have been removed internally.
4388 }
4389 }
Meng Wangafbc5852019-09-19 17:37:13 -07004390 } finally {
4391 Binder.restoreCallingIdentity(token);
4392 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 }
4394
Brad Ebingera34a6c22019-10-22 17:36:18 -07004395 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004396 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4397 * @param subId The subscription to use to check the configuration.
4398 * @param c The callback that will be used to send the result.
4399 */
4400 @Override
4401 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4402 throws RemoteException {
4403 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4404 mApp, subId, "registerImsEmergencyRegistrationCallback");
4405
4406 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4407 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4408 "IMS not available on device.");
4409 }
4410 final long token = Binder.clearCallingIdentity();
4411 try {
4412 int slotId = getSlotIndexOrException(subId);
4413 verifyImsMmTelConfiguredOrThrow(slotId);
4414
4415 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4416 if (controller != null) {
4417 ImsManager imsManager = controller.getImsManager(subId);
4418 if (imsManager != null) {
4419 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4420 } else {
4421 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4422 }
4423 } else {
4424 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4425 }
4426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
4428 } finally {
4429 Binder.restoreCallingIdentity(token);
4430 }
4431 }
4432
4433 /**
4434 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4435 * @param subId The subscription to use to check the configuration.
4436 * @param c The callback that will be used to send the result.
4437 */
4438 @Override
4439 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4440 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4441 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4442 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4443 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4444 }
4445 final long token = Binder.clearCallingIdentity();
4446
4447 try {
4448 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4449 if (controller != null) {
4450 ImsManager imsManager = controller.getImsManager(subId);
4451 if (imsManager != null) {
4452 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4453 } else {
4454 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4455 + "is inactive, ignoring unregister.");
4456 // If the ImsManager is not valid, just return, since the callback
4457 // will already have been removed internally.
4458 }
4459 }
4460 } finally {
4461 Binder.restoreCallingIdentity(token);
4462 }
4463 }
4464
4465 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004466 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4467 */
4468 @Override
4469 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4470 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4471 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4472 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4473 "IMS not available on device.");
4474 }
4475 final long token = Binder.clearCallingIdentity();
4476 try {
4477 Phone phone = getPhone(subId);
4478 if (phone == null) {
4479 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4480 + subId + "'");
4481 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4482 }
4483 phone.getImsRegistrationState(regState -> {
4484 try {
4485 consumer.accept((regState == null)
4486 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4487 } catch (RemoteException e) {
4488 // Ignore if the remote process is no longer available to call back.
4489 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4490 }
4491 });
4492 } finally {
4493 Binder.restoreCallingIdentity(token);
4494 }
4495 }
4496
4497 /**
4498 * Get the transport type for the IMS service registration state.
4499 */
4500 @Override
4501 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004502 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004503 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004504 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4505 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4506 "IMS not available on device.");
4507 }
4508 final long token = Binder.clearCallingIdentity();
4509 try {
4510 Phone phone = getPhone(subId);
4511 if (phone == null) {
4512 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4513 + subId + "'");
4514 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4515 }
4516 phone.getImsRegistrationTech(regTech -> {
4517 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4518 int regTechConverted = (regTech == null)
4519 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4520 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4521 regTechConverted);
4522 try {
4523 consumer.accept(regTechConverted);
4524 } catch (RemoteException e) {
4525 // Ignore if the remote process is no longer available to call back.
4526 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4527 }
4528 });
4529 } finally {
4530 Binder.restoreCallingIdentity(token);
4531 }
4532 }
4533
shilu366312e2019-12-17 09:28:10 -08004534 /**
4535 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4536 * @param subId The subscription to use to check the configuration.
4537 * @param c The callback that will be used to send the result.
4538 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004539 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004540 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4541 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004542 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004543 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004544 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4545 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4546 "IMS not available on device.");
4547 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004548 final long token = Binder.clearCallingIdentity();
4549 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004550 int slotId = getSlotIndexOrException(subId);
4551 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004552
4553 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4554 if (controller != null) {
4555 ImsManager imsManager = controller.getImsManager(subId);
4556 if (imsManager != null) {
4557 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4558 } else {
4559 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4560 }
4561 } else {
4562 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4563 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004564 } catch (ImsException e) {
4565 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004566 } finally {
4567 Binder.restoreCallingIdentity(token);
4568 }
4569 }
4570
shilu366312e2019-12-17 09:28:10 -08004571 /**
4572 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4573 * @param subId The subscription to use to check the configuration.
4574 * @param c The callback that will be used to send the result.
4575 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004577 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004578 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004579 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4581 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4582 }
Meng Wangafbc5852019-09-19 17:37:13 -07004583
4584 final long token = Binder.clearCallingIdentity();
4585 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004586 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4587 if (controller != null) {
4588 ImsManager imsManager = controller.getImsManager(subId);
4589 if (imsManager != null) {
4590 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4591 } else {
4592 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4593 + " is inactive, ignoring unregister.");
4594 // If the ImsManager is not valid, just return, since the callback
4595 // will already have been removed internally.
4596 }
4597 }
Meng Wangafbc5852019-09-19 17:37:13 -07004598 } finally {
4599 Binder.restoreCallingIdentity(token);
4600 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004601 }
4602
4603 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004604 public boolean isCapable(int subId, int capability, int regTech) {
4605 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 final long token = Binder.clearCallingIdentity();
4607 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004608 int slotId = getSlotIndexOrException(subId);
4609 verifyImsMmTelConfiguredOrThrow(slotId);
4610 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4611 } catch (com.android.ims.ImsException e) {
4612 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4613 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004614 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004615 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4616 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004617 } finally {
4618 Binder.restoreCallingIdentity(token);
4619 }
4620 }
4621
4622 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004623 public boolean isAvailable(int subId, int capability, int regTech) {
4624 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004625 final long token = Binder.clearCallingIdentity();
4626 try {
4627 Phone phone = getPhone(subId);
4628 if (phone == null) return false;
4629 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004630 } catch (com.android.ims.ImsException e) {
4631 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4632 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004633 } finally {
4634 Binder.restoreCallingIdentity(token);
4635 }
4636 }
4637
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004638 /**
4639 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4640 * subscription.
4641 * @param subId The subscription to use to check the configuration.
4642 * @param callback The callback that will be used to send the result.
4643 * @param capability The MmTelFeature capability that will be used to send the result.
4644 * @param transportType The transport type of the MmTelFeature capability.
4645 */
4646 @Override
4647 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4648 int transportType) {
4649 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004650 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4651 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4652 "IMS not available on device.");
4653 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004654 final long token = Binder.clearCallingIdentity();
4655 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004656 int slotId = getSlotIndex(subId);
4657 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4658 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4659 + subId + "'");
4660 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4661 }
4662 verifyImsMmTelConfiguredOrThrow(slotId);
4663 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4664 transportType, aBoolean -> {
4665 try {
4666 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4667 } catch (RemoteException e) {
4668 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4669 + "running. Ignore");
4670 }
4671 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004672 } catch (ImsException e) {
4673 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004674 } finally {
4675 Binder.restoreCallingIdentity(token);
4676 }
4677 }
4678
shilu366312e2019-12-17 09:28:10 -08004679 /**
4680 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4681 * @param subId The subscription to use to check the configuration.
4682 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004683 @Override
4684 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004685 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004686 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004687
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 final long token = Binder.clearCallingIdentity();
4689 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004691 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (ImsException e) {
4694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 } finally {
4696 Binder.restoreCallingIdentity(token);
4697 }
4698 }
4699
4700 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004701 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004703 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 final long identity = Binder.clearCallingIdentity();
4705 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004706 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004707 // This setting doesn't require an active ImsService connection, so do not verify. The
4708 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004710 } catch (ImsException e) {
4711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
4715 }
4716
shilu366312e2019-12-17 09:28:10 -08004717 /**
4718 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4719 * @param subId The subscription to use to check the configuration.
4720 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004721 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004722 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004723 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004724 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004725 final long identity = Binder.clearCallingIdentity();
4726 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004727 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004728 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004729 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004730 } catch (ImsException e) {
4731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
4735 }
4736
4737 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004738 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004740 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004741 final long identity = Binder.clearCallingIdentity();
4742 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004743 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004744 // This setting doesn't require an active ImsService connection, so do not verify. The
4745 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004746 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004747 } catch (ImsException e) {
4748 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
shilu366312e2019-12-17 09:28:10 -08004754 /**
4755 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4756 * @param subId The subscription to use to check the configuration.
4757 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004758 @Override
4759 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004760 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004761 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004762 final long identity = Binder.clearCallingIdentity();
4763 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004764 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004765 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004766 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004767 } catch (ImsException e) {
4768 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
4772 }
4773
4774 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004775 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004777 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 final long identity = Binder.clearCallingIdentity();
4779 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004780 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004781 // This setting doesn't require an active ImsService connection, so do not verify. The
4782 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004783 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004784 } catch (ImsException e) {
4785 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 } finally {
4787 Binder.restoreCallingIdentity(identity);
4788 }
4789 }
4790
shilu366312e2019-12-17 09:28:10 -08004791 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004792 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4793 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4794 * @param subId The subscription to use to check the configuration.
4795 */
4796 @Override
4797 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004798 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004799 mApp, subId, "isCrossSimCallingEnabledByUser");
4800 final long identity = Binder.clearCallingIdentity();
4801 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004802 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004803 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004804 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004805 } catch (ImsException e) {
4806 throw new ServiceSpecificException(e.getCode());
4807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
4810 }
4811
4812 /**
4813 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4814 * Requires MODIFY_PHONE_STATE permission.
4815 * @param subId The subscription to use to check the configuration.
4816 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4817 * false otherwise
4818 */
4819 @Override
4820 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4822 "setCrossSimCallingEnabled");
4823 final long identity = Binder.clearCallingIdentity();
4824 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004825 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004826 // This setting doesn't require an active ImsService connection, so do not verify. The
4827 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004828 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004829 } catch (ImsException e) {
4830 throw new ServiceSpecificException(e.getCode());
4831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
4834 }
4835
4836 /**
shilu366312e2019-12-17 09:28:10 -08004837 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4838 * @param subId The subscription to use to check the configuration.
4839 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004841
Brad Ebinger35c841c2018-10-01 10:40:55 -07004842 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004843 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004844 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004845 final long identity = Binder.clearCallingIdentity();
4846 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004847 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004848 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004849 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004850 } catch (ImsException e) {
4851 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004852 } finally {
4853 Binder.restoreCallingIdentity(identity);
4854 }
4855 }
4856
4857 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004858 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004860 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004861 final long identity = Binder.clearCallingIdentity();
4862 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004863 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004864 // This setting doesn't require an active ImsService connection, so do not verify. The
4865 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004866 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004867 } catch (ImsException e) {
4868 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
4872 }
4873
4874 @Override
4875 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4877 "setVoWiFiNonPersistent");
4878 final long identity = Binder.clearCallingIdentity();
4879 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004880 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004881 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004882 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004883 } catch (ImsException e) {
4884 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
4888 }
4889
shilu366312e2019-12-17 09:28:10 -08004890 /**
4891 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4892 * @param subId The subscription to use to check the configuration.
4893 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004894 @Override
4895 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004896 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004897 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004898 final long identity = Binder.clearCallingIdentity();
4899 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004900 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004901 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004902 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004903 } catch (ImsException e) {
4904 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004905 } finally {
4906 Binder.restoreCallingIdentity(identity);
4907 }
4908 }
4909
4910 @Override
4911 public void setVoWiFiModeSetting(int subId, int mode) {
4912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4913 "setVoWiFiModeSetting");
4914 final long identity = Binder.clearCallingIdentity();
4915 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004916 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004917 // This setting doesn't require an active ImsService connection, so do not verify. The
4918 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004919 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004920 } catch (ImsException e) {
4921 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
4925 }
4926
4927 @Override
4928 public int getVoWiFiRoamingModeSetting(int subId) {
4929 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4930 final long identity = Binder.clearCallingIdentity();
4931 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004932 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004933 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004934 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004935 } catch (ImsException e) {
4936 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
4940 }
4941
4942 @Override
4943 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4945 "setVoWiFiRoamingModeSetting");
4946 final long identity = Binder.clearCallingIdentity();
4947 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004948 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004949 // This setting doesn't require an active ImsService connection, so do not verify. The
4950 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004952 } catch (ImsException e) {
4953 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
4957 }
4958
4959 @Override
4960 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4962 "setRttCapabilityEnabled");
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004965 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004966 // This setting doesn't require an active ImsService connection, so do not verify. The
4967 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004968 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004969 } catch (ImsException e) {
4970 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975
shilu366312e2019-12-17 09:28:10 -08004976 /**
4977 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4978 * @param subId The subscription to use to check the configuration.
4979 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 @Override
4981 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004982 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004983 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004984 final long identity = Binder.clearCallingIdentity();
4985 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004986 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004987 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004988 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004989 } catch (ImsException e) {
4990 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
4994 }
4995
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004996 @Override
4997 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4998 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004999
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005000 final long identity = Binder.clearCallingIdentity();
5001 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005002 if (!isImsAvailableOnDevice()) {
5003 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5004 "IMS not available on device.");
5005 }
5006 int slotId = getSlotIndexOrException(subId);
5007 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005008
5009 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5010 if (controller != null) {
5011 ImsManager imsManager = controller.getImsManager(subId);
5012 if (imsManager != null) {
5013 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5014 } else {
5015 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5016 }
5017 } else {
5018 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5019 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 } catch (ImsException e) {
5021 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
5025 }
5026
5027 @Override
5028 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5029 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005030
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005031 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005032 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5033 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5034 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005035 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005036 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5037 if (controller != null) {
5038 ImsManager imsManager = controller.getImsManager(subId);
5039 if (imsManager != null) {
5040 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5041 } else {
5042 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5043 + " is inactive, ignoring unregister.");
5044 // If the ImsManager is not valid, just return, since the callback will already
5045 // have been removed internally.
5046 }
5047 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
5051 }
5052
joonhunshincffb7fc2021-11-28 07:32:01 +00005053 @Override
5054 public void registerFeatureProvisioningChangedCallback(int subId,
5055 IFeatureProvisioningCallback callback) {
5056 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5057 mApp, subId, "registerFeatureProvisioningChangedCallback");
5058
5059 final long identity = Binder.clearCallingIdentity();
5060 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5061 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5062 }
5063
joonhunshin91bc1952022-04-29 08:47:15 +00005064 try {
5065 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5066 if (controller == null) {
5067 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5068 "Device does not support IMS");
5069 }
5070 controller.addFeatureProvisioningChangedCallback(subId, callback);
5071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005074 }
5075
5076 @Override
5077 public void unregisterFeatureProvisioningChangedCallback(int subId,
5078 IFeatureProvisioningCallback callback) {
5079 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5080 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5081
5082 final long identity = Binder.clearCallingIdentity();
5083 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5084 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5085 }
5086
joonhunshin91bc1952022-04-29 08:47:15 +00005087 try {
5088 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5089 if (controller == null) {
5090 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5091 return;
5092 }
5093 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005097 }
allenwtsu99c623b2020-01-03 18:24:23 +08005098
5099 private void checkModifyPhoneStatePermission(int subId, String message) {
5100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5101 message);
5102 }
5103
allenwtsu99c623b2020-01-03 18:24:23 +08005104 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005105 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005106 boolean isProvisioned) {
5107 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5108
5109 final long identity = Binder.clearCallingIdentity();
5110 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005111 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5112 if (controller == null) {
5113 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5114 return;
5115 }
5116 controller.setRcsProvisioningStatusForCapability(
5117 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005118 } finally {
5119 Binder.restoreCallingIdentity(identity);
5120 }
allenwtsu99c623b2020-01-03 18:24:23 +08005121 }
5122
5123
5124 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005125 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5126 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5127 mApp, subId, "getRcsProvisioningStatusForCapability");
5128
allenwtsu99c623b2020-01-03 18:24:23 +08005129 final long identity = Binder.clearCallingIdentity();
5130 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005131 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5132 if (controller == null) {
5133 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5134
5135 // device does not support IMS, this method will return true always.
5136 return true;
5137 }
5138 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
5142 }
5143
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005144 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005145 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5146 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005147 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005148
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 final long identity = Binder.clearCallingIdentity();
5150 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005151 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5152 if (controller == null) {
5153 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5154 return;
5155 }
5156 controller.setImsProvisioningStatusForCapability(
5157 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
5161 }
5162
5163 @Override
5164 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005165 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5166 mApp, subId, "getProvisioningStatusForCapability");
5167
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005168 final long identity = Binder.clearCallingIdentity();
5169 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005170 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5171 if (controller == null) {
5172 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005173
joonhunshin91bc1952022-04-29 08:47:15 +00005174 // device does not support IMS, this method will return true always.
5175 return true;
5176 }
5177 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
5181 }
5182
5183 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005184 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5185 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5186 mApp, subId, "isProvisioningRequiredForCapability");
5187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005190 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5191 if (controller == null) {
5192 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5193
5194 // device does not support IMS, this method will return false
5195 return false;
5196 }
5197 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005198 } finally {
5199 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005200 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005201 }
5202
5203 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005204 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5205 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5206 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005207
joonhunshincffb7fc2021-11-28 07:32:01 +00005208 final long identity = Binder.clearCallingIdentity();
5209 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005210 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5211 if (controller == null) {
5212 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5213
5214 // device does not support IMS, this method will return false
5215 return false;
5216 }
5217 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005221 }
5222
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005223 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005224 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005225 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5226 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5227 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005228 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5229 mApp, subId, "getImsProvisioningInt");
5230
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005234 int slotId = getSlotIndex(subId);
5235 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5236 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5237 + subId + "' for key:" + key);
5238 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5239 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005240
joonhunshin91bc1952022-04-29 08:47:15 +00005241 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5242 if (controller == null) {
5243 loge("getImsProvisioningInt: Device does not support IMS");
5244
5245 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5246 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5247 }
5248 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005249 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5250 return retVal;
5251 }
5252
calvinpanb5a34062021-02-08 19:59:36 +08005253 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005254 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005255 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5256 + subId + "' for key:" + key);
5257 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
5261 }
5262
5263 @Override
5264 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005265 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5266 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5267 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005268 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5269 mApp, subId, "getImsProvisioningString");
5270
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005274 int slotId = getSlotIndex(subId);
5275 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5276 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5277 + subId + "' for key:" + key);
5278 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5279 }
calvinpanb5a34062021-02-08 19:59:36 +08005280 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005281 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005282 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5283 + subId + "' for key:" + key);
5284 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
5288 }
5289
5290 @Override
5291 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005292 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5293 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5294 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5296 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005297
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005298 final long identity = Binder.clearCallingIdentity();
5299 try {
5300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005301 int slotId = getSlotIndex(subId);
5302 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5303 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5304 + subId + "' for key:" + key);
5305 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5306 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005307
joonhunshin91bc1952022-04-29 08:47:15 +00005308 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5309 if (controller == null) {
5310 loge("setImsProvisioningInt: Device does not support IMS");
5311
5312 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5313 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5314 }
5315 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005316 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5317 return retVal;
5318 }
5319
calvinpanb5a34062021-02-08 19:59:36 +08005320 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5321 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005322 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005323 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005324 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
5328 }
5329
5330 @Override
5331 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005332 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5333 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5334 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5336 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005340 int slotId = getSlotIndex(subId);
5341 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5342 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5343 + subId + "' for key:" + key);
5344 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5345 }
calvinpanb5a34062021-02-08 19:59:36 +08005346 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5347 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005348 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005349 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005350 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
5354 }
5355
Brad Ebinger919631e2021-06-02 17:46:35 -07005356 /**
5357 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5358 * for the given slot ID or no ImsResolver instance has been created.
5359 * @param slotId The slot ID that the IMS service is created for.
5360 * @throws ImsException If there is no ImsService configured for this slot.
5361 */
5362 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5363 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5364 ImsFeature.FEATURE_MMTEL)) {
5365 throw new ImsException("This subscription does not support MMTEL over IMS",
5366 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5367 }
5368 }
5369
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005370 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005371 int slotId = SubscriptionManager.getSlotIndex(subId);
5372 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005373 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5374 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005375 }
5376 return slotId;
5377 }
5378
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005379 private int getSlotIndex(int subId) {
5380 int slotId = SubscriptionManager.getSlotIndex(subId);
5381 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5382 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5383 }
5384 return slotId;
5385 }
5386
Wink Saville36469e72014-06-11 15:17:00 -07005387 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005388 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005389 */
5390 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005391 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5392 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005393 try {
5394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5395 } catch (SecurityException se) {
5396 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5397 throw new SecurityException("Package " + callingPackage + " does not belong to "
5398 + Binder.getCallingUid());
5399 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005400 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005401 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005402 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005403 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005404 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005405 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005406 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005407 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5408 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 final Phone phone = getPhone(subId);
5413 if (phone != null) {
5414 return phone.getServiceState().getDataNetworkType();
5415 } else {
5416 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5417 }
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005421 }
5422
5423 /**
5424 * Returns the data network type
5425 */
5426 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005427 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005428 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005429 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005430 }
5431
5432 /**
5433 * Returns the data network type for a subId
5434 */
5435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005436 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5437 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005438 String functionName = "getDataNetworkTypeForSubscriber";
5439 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5440 mApp, functionName)) {
5441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5442 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5443 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5444 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005445 }
5446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
5449 final Phone phone = getPhone(subId);
5450 if (phone != null) {
5451 return phone.getServiceState().getDataNetworkType();
5452 } else {
5453 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5454 }
5455 } finally {
5456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005458 }
5459
5460 /**
Wink Saville36469e72014-06-11 15:17:00 -07005461 * Returns the Voice network type for a subId
5462 */
5463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005464 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5465 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005466 String functionName = "getVoiceNetworkTypeForSubscriber";
5467 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5468 mApp, functionName)) {
5469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5470 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5471 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5472 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005473 }
5474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 final Phone phone = getPhone(subId);
5478 if (phone != null) {
5479 return phone.getServiceState().getVoiceNetworkType();
5480 } else {
5481 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5482 }
5483 } finally {
5484 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005486 }
5487
5488 /**
5489 * @return true if a ICC card is present
5490 */
5491 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005492 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005493 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005494 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005495 }
5496
5497 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005498 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005499 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005500 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005501 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 final Phone phone = PhoneFactory.getPhone(slotIndex);
5505 if (phone != null) {
5506 return phone.getIccCard().hasIccCard();
5507 } else {
5508 return false;
5509 }
5510 } finally {
5511 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005513 }
5514
5515 /**
5516 * Return if the current radio is LTE on CDMA. This
5517 * is a tri-state return value as for a period of time
5518 * the mode may be unknown.
5519 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005520 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005521 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005522 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005523 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005525 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5526 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5527 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005528 }
5529
Sanket Padawe356d7632015-06-22 14:03:32 -07005530 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005531 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5532 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005533 try {
5534 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5535 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005536 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5537 }
5538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 final Phone phone = getPhone(subId);
5542 if (phone == null) {
5543 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5544 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005545 return TelephonyProperties.lte_on_cdma_device()
5546 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 }
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005550 }
Wink Saville36469e72014-06-11 15:17:00 -07005551 }
5552
Wink Saville36469e72014-06-11 15:17:00 -07005553 /**
5554 * {@hide}
5555 * Returns Default subId, 0 in the case of single standby.
5556 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005557 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005558 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005559 }
5560
Shishir Agrawala9f32182016-04-12 12:00:16 -07005561 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005562 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005563 }
5564
Wink Savilleb564aae2014-10-23 10:18:09 -07005565 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005566 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005567 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005568
Pengquan Menge92a50d2018-09-21 15:54:48 -07005569 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005570 return getSubscriptionManagerService().isActiveSubId(subId,
5571 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005572 }
5573
Ihab Awadf2177b72013-11-25 13:33:23 -08005574 /**
5575 * @see android.telephony.TelephonyManager.WifiCallingChoices
5576 */
5577 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005580 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5582 getWhenToMakeWifiCallsDefaultPreference());
5583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005586 }
5587
5588 /**
5589 * @see android.telephony.TelephonyManager.WifiCallingChoices
5590 */
5591 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005595 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005600 }
5601
Sailesh Nepald1e68152013-12-12 19:08:02 -08005602 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005603 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005604 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005605 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005606
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005607 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5608 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5609 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005610 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005611 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005612 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005613 }
5614 return PhoneFactory.getPhone(phoneId);
5615 }
5616
Shishir Agrawal566b7612013-10-28 14:41:00 -07005617 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005618 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005619 @NonNull IccLogicalChannelRequest request) {
5620 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5621 /*message=*/ "iccOpenLogicalChannel");
5622
5623 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5624 // Verify that the callingPackage in the request belongs to the calling UID
5625 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5626
5627 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005628 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005629
Rambo Wanga1782702021-11-10 20:15:19 -08005630 private Phone getPhoneFromValidIccLogicalChannelRequest(
5631 @NonNull IccLogicalChannelRequest request, String message) {
5632 Phone phone;
5633 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, request.subId, message);
5636 phone = getPhoneFromSubId(request.subId);
5637 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5638 enforceModifyPermission();
5639 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5640 } else {
5641 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005642 }
Rambo Wanga1782702021-11-10 20:15:19 -08005643 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005644 }
5645
5646 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005647 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 final long identity = Binder.clearCallingIdentity();
5649 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005650 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005652 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5653 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005654 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5655 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 loge("The calling package is not allowed to access ISD-R.");
5657 throw new SecurityException(
5658 "The calling package is not allowed to access ISD-R.");
5659 }
Derek Tan740e1672017-06-27 14:56:27 -07005660 }
Derek Tan740e1672017-06-27 14:56:27 -07005661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005663 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5664 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 return response;
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005669 }
5670
5671 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005672 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5673 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5674 /*message=*/"iccCloseLogicalChannel");
5675
5676 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5677
5678 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005679 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005680
Rambo Wanga1782702021-11-10 20:15:19 -08005681 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5682 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005683 // before this feature is enabled, this API should only return false if
5684 // the operation fails instead of throwing runtime exception for
5685 // backward-compatibility.
5686 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5687 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 final long identity = Binder.clearCallingIdentity();
5689 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005690 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005691 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 }
Chen Xue9d737e2022-01-01 23:41:31 -08005693 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005694 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005695 Boolean success = false;
5696 if (result instanceof RuntimeException) {
5697 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005698 if (shouldThrowExceptionOnFailure) {
5699 throw (RuntimeException) result;
5700 } else {
5701 return false;
5702 }
Chen Xue9d737e2022-01-01 23:41:31 -08005703 } else if (result instanceof Boolean) {
5704 success = (Boolean) result;
5705 } else {
5706 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5707 }
Rambo Wanga1782702021-11-10 20:15:19 -08005708 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 return success;
5710 } finally {
5711 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005712 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005713 }
5714
5715 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005716 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005717 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5719 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005720 if (DBG) {
5721 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5722 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5723 + p3 + " data=" + data);
5724 }
5725 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5726 command, p1, p2, p3, data);
5727 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005728
Jordan Liu4c733742019-02-28 12:03:40 -08005729 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005730 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005731 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005732 enforceModifyPermission();
5733 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005734 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005735 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5736 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005737 }
5738 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005739 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5740 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005741 }
5742
5743 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5744 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 final long identity = Binder.clearCallingIdentity();
5746 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005747 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 return "";
5749 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005752 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5753 null /* workSource */);
5754 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 // Append the returned status code to the end of the response payload.
5757 String s = Integer.toHexString(
5758 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5759 if (response.payload != null) {
5760 s = IccUtils.bytesToHexString(response.payload) + s;
5761 }
5762 return s;
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005765 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005766 }
Jake Hambye994d462014-02-03 13:10:13 -08005767
Evan Charltonc66da362014-05-16 14:06:40 -07005768 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005769 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5770 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5772 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005774 if (DBG) {
5775 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5776 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5777 }
5778 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5779 cla, command, p1, p2, p3, data);
5780 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005781
Jordan Liu4c733742019-02-28 12:03:40 -08005782 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005783 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005784 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005785 enforceModifyPermission();
5786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5787 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005788 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005789 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5790 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005791 }
5792
5793 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005794 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5795 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005796 }
5797
5798 // open APDU basic channel assuming the caller has sufficient permissions
5799 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5800 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 final long identity = Binder.clearCallingIdentity();
5802 try {
5803 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5804 && TextUtils.equals(ISDR_AID, data)) {
5805 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005806 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5807 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 if (bestComponent == null
5809 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5810 loge("The calling package is not allowed to select ISD-R.");
5811 throw new SecurityException(
5812 "The calling package is not allowed to select ISD-R.");
5813 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005814 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005817 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5818 null /* workSource */);
5819 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 // Append the returned status code to the end of the response payload.
5822 String s = Integer.toHexString(
5823 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5824 if (response.payload != null) {
5825 s = IccUtils.bytesToHexString(response.payload) + s;
5826 }
5827 return s;
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005830 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005831 }
5832
5833 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005834 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005835 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5837 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 if (DBG) {
5842 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5843 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5844 }
5845
5846 IccIoResult response =
5847 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5848 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5849 subId);
5850
5851 if (DBG) {
5852 log("Exchange SIM_IO [R]" + response);
5853 }
5854
5855 byte[] result = null;
5856 int length = 2;
5857 if (response.payload != null) {
5858 length = 2 + response.payload.length;
5859 result = new byte[length];
5860 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5861 } else {
5862 result = new byte[length];
5863 }
5864
5865 result[length - 1] = (byte) response.sw2;
5866 result[length - 2] = (byte) response.sw1;
5867 return result;
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005870 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005871 }
5872
Nathan Haroldb3014052017-01-25 15:57:32 -08005873 /**
5874 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5875 * on a particular subscription
5876 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005877 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5878 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005880 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005881 return null;
5882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883
5884 final long identity = Binder.clearCallingIdentity();
5885 try {
5886 if (appType != TelephonyManager.APPTYPE_USIM
5887 && appType != TelephonyManager.APPTYPE_SIM) {
5888 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5889 return null;
5890 }
5891 Object response = sendRequest(
5892 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5893 if (response instanceof String[]) {
5894 return (String[]) response;
5895 }
yincheng zhao2737e882019-09-06 17:06:54 -07005896 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005898 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 } finally {
5900 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005901 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005902 }
5903
yincheng zhao2737e882019-09-06 17:06:54 -07005904 /**
5905 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5906 * subscription.
5907 *
5908 * @param subId the id of the subscription.
5909 * @param appType the uicc app type, must be USIM or SIM.
5910 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5911 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005912 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005913 * @return number of fplmns that is successfully written to the SIM.
5914 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005915 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5916 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5918 mApp, subId, "setForbiddenPlmns");
5919
yincheng zhao2737e882019-09-06 17:06:54 -07005920 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5921 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5922 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5923 }
5924 if (fplmns == null) {
5925 throw new IllegalArgumentException("Fplmn List provided is null");
5926 }
5927 for (String fplmn : fplmns) {
5928 if (!CellIdentity.isValidPlmn(fplmn)) {
5929 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5930 }
5931 }
5932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 Object response = sendRequest(
5935 CMD_SET_FORBIDDEN_PLMNS,
5936 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5937 subId);
5938 return (int) response;
5939 } finally {
5940 Binder.restoreCallingIdentity(identity);
5941 }
5942 }
5943
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005944 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005945 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5947 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
5951 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5952 if (response.payload == null) {
5953 return "";
5954 }
Evan Charltonc66da362014-05-16 14:06:40 -07005955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 // Append the returned status code to the end of the response payload.
5957 String s = Integer.toHexString(
5958 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5959 s = IccUtils.bytesToHexString(response.payload) + s;
5960 return s;
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
Evan Charltonc66da362014-05-16 14:06:40 -07005964 }
5965
Jake Hambye994d462014-02-03 13:10:13 -08005966 /**
5967 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5968 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5969 *
5970 * @param itemID the ID of the item to read
5971 * @return the NV item as a String, or null on error.
5972 */
5973 @Override
5974 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5977 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978
5979 final long identity = Binder.clearCallingIdentity();
5980 try {
5981 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005982 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5984 return value;
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
Jake Hambye994d462014-02-03 13:10:13 -08005988 }
5989
5990 /**
5991 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5992 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5993 *
5994 * @param itemID the ID of the item to read
5995 * @param itemValue the value to write, as a String
5996 * @return true on success; false on any failure
5997 */
5998 @Override
5999 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6002 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6007 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006008 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6010 return success;
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
Jake Hambye994d462014-02-03 13:10:13 -08006014 }
6015
6016 /**
6017 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6018 * Used for device configuration by some CDMA operators.
6019 *
6020 * @param preferredRoamingList byte array containing the new PRL
6021 * @return true on success; false on any failure
6022 */
6023 @Override
6024 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6026 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
6030 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6031 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6032 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6033 return success;
6034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
Jake Hambye994d462014-02-03 13:10:13 -08006037 }
6038
6039 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006040 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006041 * Used for device configuration by some CDMA operators.
6042 *
chen xu6dac5ab2018-10-26 17:39:23 -07006043 * @param slotIndex - device slot.
6044 *
Jake Hambye994d462014-02-03 13:10:13 -08006045 * @return true on success; false on any failure
6046 */
6047 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006048 public boolean resetModemConfig(int slotIndex) {
6049 Phone phone = PhoneFactory.getPhone(slotIndex);
6050 if (phone != null) {
6051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6052 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
chen xu6dac5ab2018-10-26 17:39:23 -07006054 final long identity = Binder.clearCallingIdentity();
6055 try {
6056 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6057 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6058 return success;
6059 } finally {
6060 Binder.restoreCallingIdentity(identity);
6061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 }
chen xu6dac5ab2018-10-26 17:39:23 -07006063 return false;
6064 }
6065
6066 /**
6067 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6068 *
6069 * @param slotIndex - device slot.
6070 *
6071 * @return true on success; false on any failure
6072 */
6073 @Override
6074 public boolean rebootModem(int slotIndex) {
6075 Phone phone = PhoneFactory.getPhone(slotIndex);
6076 if (phone != null) {
6077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6078 mApp, phone.getSubId(), "rebootModem");
6079
6080 final long identity = Binder.clearCallingIdentity();
6081 try {
6082 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6083 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6084 return success;
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
6087 }
6088 }
6089 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006090 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006091
Brad Ebinger51f743a2017-01-23 13:50:20 -08006092 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006093 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6094 * {@link #disableIms(int)}.
6095 * @param slotIndex device slot.
6096 */
6097 public void resetIms(int slotIndex) {
6098 enforceModifyPermission();
6099
6100 final long identity = Binder.clearCallingIdentity();
6101 try {
6102 if (mImsResolver == null) {
6103 // may happen if the does not support IMS.
6104 return;
6105 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006106 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
6110 }
6111
6112 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006113 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6114 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006115 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006116 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006117 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118
6119 final long identity = Binder.clearCallingIdentity();
6120 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006121 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006122 // may happen if the device does not support IMS.
6123 return;
6124 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006125 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 } finally {
6127 Binder.restoreCallingIdentity(identity);
6128 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006129 }
6130
6131 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006132 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6133 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006134 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006135 public void disableIms(int slotId) {
6136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137
6138 final long identity = Binder.clearCallingIdentity();
6139 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006140 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006141 // may happen if the device does not support IMS.
6142 return;
6143 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006144 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 } finally {
6146 Binder.restoreCallingIdentity(identity);
6147 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006148 }
6149
6150 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006151 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6152 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006153 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006154 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006155 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006156 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157
6158 final long identity = Binder.clearCallingIdentity();
6159 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006160 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006161 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6162 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006163 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006164 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006168 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006169 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006170 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6171 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006172 @Override
6173 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006174 enforceModifyPermission();
6175
6176 final long identity = Binder.clearCallingIdentity();
6177 try {
6178 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006179 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006180 } finally {
6181 Binder.restoreCallingIdentity(identity);
6182 }
6183 }
6184
6185 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006186 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006187 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006188 */
6189 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191
6192 final long identity = Binder.clearCallingIdentity();
6193 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006194 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006195 // may happen if the device does not support IMS.
6196 return null;
6197 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006198 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 } finally {
6200 Binder.restoreCallingIdentity(identity);
6201 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006202 }
6203
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006204 /**
6205 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006206 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006207 */
6208 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210
6211 final long identity = Binder.clearCallingIdentity();
6212 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006213 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006214 // may happen if the device does not support IMS.
6215 return null;
6216 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006217 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 } finally {
6219 Binder.restoreCallingIdentity(identity);
6220 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006221 }
6222
Brad Ebinger884c07b2018-02-15 16:17:40 -08006223 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006224 * Sets the ImsService Package Name that Telephony will bind to.
6225 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006226 * @param slotIndex the slot ID that the ImsService should bind for.
6227 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006228 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006229 * @param featureTypes An integer array of feature types associated with a packageName.
6230 * @param packageName The name of the package that the current configuration will be replaced
6231 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006232 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006233 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006234 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6235 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006238 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 final long identity = Binder.clearCallingIdentity();
6241 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006242 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006243 // may happen if the device does not support IMS.
6244 return false;
6245 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006246 Map<Integer, String> featureConfig = new HashMap<>();
6247 for (int featureType : featureTypes) {
6248 featureConfig.put(featureType, packageName);
6249 }
6250 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6251 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006255 }
6256
6257 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006258 * Clears any carrier ImsService overrides for the slot index specified that were previously
6259 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6260 *
6261 * This should only be used for testing.
6262 *
6263 * @param slotIndex the slot ID that the ImsService should bind for.
6264 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6265 */
6266 @Override
6267 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6269 "clearCarrierImsServiceOverride");
6270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006271 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006272
6273 final long identity = Binder.clearCallingIdentity();
6274 try {
6275 if (mImsResolver == null) {
6276 // may happen if the device does not support IMS.
6277 return false;
6278 }
6279 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
6283 }
6284
6285 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006286 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006287 *
6288 * @param slotId The slot that the ImsService is associated with.
6289 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6290 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006291 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006292 * @return the package name of the ImsService configuration.
6293 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006294 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6295 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006296 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006297 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6298 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 final long identity = Binder.clearCallingIdentity();
6301 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006302 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006303 // may happen if the device does not support IMS.
6304 return "";
6305 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006306 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006307 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6308 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 } finally {
6310 Binder.restoreCallingIdentity(identity);
6311 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006312 }
6313
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006314 /**
6315 * Get the MmTelFeature state associated with the requested subscription id.
6316 * @param subId The subscription that the MmTelFeature is associated with.
6317 * @param callback A callback with an integer containing the
6318 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6319 */
6320 @Override
6321 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6322 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006323 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6324 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6325 "IMS not available on device.");
6326 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006327 final long token = Binder.clearCallingIdentity();
6328 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006329 int slotId = getSlotIndex(subId);
6330 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6331 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6332 + subId + "'");
6333 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6334 }
6335 verifyImsMmTelConfiguredOrThrow(slotId);
6336 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6337 try {
6338 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6339 } catch (RemoteException e) {
6340 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6341 + "Ignore");
6342 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006343 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006344 } catch (ImsException e) {
6345 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006346 } finally {
6347 Binder.restoreCallingIdentity(token);
6348 }
6349 }
6350
Daniel Brightbb5840b2021-01-12 15:48:18 -08006351 /**
6352 * Sets the ims registration state on all valid {@link Phone}s.
6353 */
6354 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006355 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356
6357 final long identity = Binder.clearCallingIdentity();
6358 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006359 // NOTE: Before S, this method only set the default phone.
6360 for (final Phone phone : PhoneFactory.getPhones()) {
6361 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6362 phone.setImsRegistrationState(registered);
6363 }
6364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
Wink Saville36469e72014-06-11 15:17:00 -07006368 }
6369
6370 /**
Stuart Scott54788802015-03-30 13:18:01 -07006371 * Set the network selection mode to automatic.
6372 *
6373 */
6374 @Override
6375 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6377 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378
6379 final long identity = Binder.clearCallingIdentity();
6380 try {
shilufc958392020-01-20 11:36:01 -08006381 if (!isActiveSubscription(subId)) {
6382 return;
6383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006385 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6386 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
Stuart Scott54788802015-03-30 13:18:01 -07006390 }
6391
Jack Yud10cdd42020-09-28 20:28:01 -07006392 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006393 * Ask the radio to connect to the input network and change selection mode to manual.
6394 *
6395 * @param subId the id of the subscription.
6396 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6397 * the operator to attach to.
6398 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6399 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6400 * normal network selection next time.
6401 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006402 */
6403 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006404 public boolean setNetworkSelectionModeManual(
6405 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6407 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006408
Jack Yu285100e2022-12-02 22:48:35 -08006409 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006410 if (!isActiveSubscription(subId)) {
6411 return false;
6412 }
6413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006415 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006417 if (DBG) {
6418 log("setNetworkSelectionModeManual: subId: " + subId
6419 + " operator: " + operatorInfo);
6420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006425 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006426 /**
shilu84f6e8b2019-12-19 13:58:01 -08006427 * Get the manual network selection
6428 *
6429 * @param subId the id of the subscription.
6430 *
6431 * @return the previously saved user selected PLMN
6432 */
6433 @Override
6434 public String getManualNetworkSelectionPlmn(int subId) {
6435 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006436 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6437 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006438
6439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006442 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006443 }
6444
6445 final Phone phone = getPhone(subId);
6446 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006447 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006448 }
6449 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6450 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006451 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
6455 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006456
6457 /**
6458 * Scans for available networks.
6459 */
6460 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006461 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6462 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6464 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006465 LocationAccessPolicy.LocationPermissionResult locationResult =
6466 LocationAccessPolicy.checkLocationPermission(mApp,
6467 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6468 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006469 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006470 .setCallingPid(Binder.getCallingPid())
6471 .setCallingUid(Binder.getCallingUid())
6472 .setMethod("getCellNetworkScanResults")
6473 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006474 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6475 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006476 .build());
6477 switch (locationResult) {
6478 case DENIED_HARD:
6479 throw new SecurityException("Not allowed to access scan results -- location");
6480 case DENIED_SOFT:
6481 return null;
6482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483
Pengquan Menga1bb6272018-09-06 09:59:22 -07006484 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 try {
6486 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006487 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006492 }
6493
6494 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006495 * Get the call forwarding info, given the call forwarding reason.
6496 */
6497 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006498 public void getCallForwarding(int subId, int callForwardingReason,
6499 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006500 enforceReadPrivilegedPermission("getCallForwarding");
6501 long identity = Binder.clearCallingIdentity();
6502 try {
6503 if (DBG) {
6504 log("getCallForwarding: subId " + subId
6505 + " callForwardingReason" + callForwardingReason);
6506 }
Hall Liu27d24262020-09-18 19:04:59 -07006507
6508 Phone phone = getPhone(subId);
6509 if (phone == null) {
6510 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006511 callback.onError(
6512 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006513 } catch (RemoteException e) {
6514 // ignore
6515 }
6516 return;
6517 }
6518
6519 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6520 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6521 @Override
6522 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6523 try {
6524 callback.onCallForwardingInfoAvailable(info);
6525 } catch (RemoteException e) {
6526 // ignore
6527 }
6528 }
6529
6530 @Override
6531 public void onError(int error) {
6532 try {
6533 callback.onError(error);
6534 } catch (RemoteException e) {
6535 // ignore
6536 }
6537 }
6538 });
6539 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
6543 }
6544
6545 /**
6546 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6547 * reason, the number to forward, and the timeout before the forwarding is attempted.
6548 */
6549 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006550 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6551 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006552 enforceModifyPermission();
6553 long identity = Binder.clearCallingIdentity();
6554 try {
6555 if (DBG) {
6556 log("setCallForwarding: subId " + subId
6557 + " callForwardingInfo" + callForwardingInfo);
6558 }
Hall Liu27d24262020-09-18 19:04:59 -07006559
6560 Phone phone = getPhone(subId);
6561 if (phone == null) {
6562 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006563 callback.accept(
6564 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006565 } catch (RemoteException e) {
6566 // ignore
6567 }
6568 return;
6569 }
6570
6571 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6572 FunctionalUtils.ignoreRemoteException(callback::accept));
6573
6574 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
6578 }
6579
6580 /**
Hall Liu27d24262020-09-18 19:04:59 -07006581 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006582 */
6583 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006584 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006585 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006586 long identity = Binder.clearCallingIdentity();
6587 try {
Hall Liu27d24262020-09-18 19:04:59 -07006588 Phone phone = getPhone(subId);
6589 if (phone == null) {
6590 try {
6591 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6592 } catch (RemoteException e) {
6593 // ignore
6594 }
6595 return;
6596 }
SongFerngWang0e767992021-03-31 22:08:45 +08006597 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6598 PersistableBundle c = configManager.getConfigForSubId(subId);
6599 boolean requireUssd = c.getBoolean(
6600 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006601
Shuo Qian4a594052020-01-23 11:59:30 -08006602 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006603 if (requireUssd) {
6604 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6605 getSubscriptionCarrierId(subId));
6606 String newUssdCommand = "";
6607 try {
6608 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006609 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006610 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6611 } catch (NullPointerException e) {
6612 loge("Failed to generate USSD number" + e);
6613 }
6614 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6615 mMainThreadHandler, callback, carrierXmlParser,
6616 CarrierXmlParser.SsEntry.SSAction.QUERY);
6617 final String ussdCommand = newUssdCommand;
6618 Executors.newSingleThreadExecutor().execute(() -> {
6619 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6620 });
6621 } else {
6622 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6623 callback::accept);
6624 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6625 }
Shuo Qian4a594052020-01-23 11:59:30 -08006626 } finally {
6627 Binder.restoreCallingIdentity(identity);
6628 }
6629 }
6630
6631 /**
Hall Liu27d24262020-09-18 19:04:59 -07006632 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006633 */
6634 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006635 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006636 enforceModifyPermission();
6637 long identity = Binder.clearCallingIdentity();
6638 try {
Hall Liu27d24262020-09-18 19:04:59 -07006639 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6640
6641 Phone phone = getPhone(subId);
6642 if (phone == null) {
6643 try {
6644 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6645 } catch (RemoteException e) {
6646 // ignore
6647 }
6648 return;
6649 }
6650
SongFerngWang0e767992021-03-31 22:08:45 +08006651 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6652 PersistableBundle c = configManager.getConfigForSubId(subId);
6653 boolean requireUssd = c.getBoolean(
6654 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006655
SongFerngWang0e767992021-03-31 22:08:45 +08006656 if (DBG) log("getCallWaitingStatus: subId " + subId);
6657 if (requireUssd) {
6658 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6659 getSubscriptionCarrierId(subId));
6660 CarrierXmlParser.SsEntry.SSAction ssAction =
6661 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6662 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6663 String newUssdCommand = "";
6664 try {
6665 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006666 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006667 .makeCommand(ssAction, null);
6668 } catch (NullPointerException e) {
6669 loge("Failed to generate USSD number" + e);
6670 }
6671 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6672 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6673 final String ussdCommand = newUssdCommand;
6674 Executors.newSingleThreadExecutor().execute(() -> {
6675 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6676 });
6677 } else {
6678 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6679 FunctionalUtils.ignoreRemoteException(callback::accept));
6680
6681 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6682 }
Shuo Qian4a594052020-01-23 11:59:30 -08006683 } finally {
6684 Binder.restoreCallingIdentity(identity);
6685 }
6686 }
6687
6688 /**
yinxub1bed742017-04-17 11:45:04 -07006689 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006690 *
yinxub1bed742017-04-17 11:45:04 -07006691 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006692 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6693 * location related information which will be sent if the caller already possess
6694 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006695 * @param request contains the radio access networks with bands/channels to scan
6696 * @param messenger callback messenger for scan results or errors
6697 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006698 * @return the id of the requested scan which can be used to stop the scan.
6699 */
6700 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006701 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6702 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006703 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6705 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006706 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006707 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6708 if (!renounceFineLocationAccess) {
6709 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006710 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6711 .setCallingPackage(callingPackage)
6712 .setCallingFeatureId(callingFeatureId)
6713 .setCallingPid(Binder.getCallingPid())
6714 .setCallingUid(Binder.getCallingUid())
6715 .setMethod("requestNetworkScan")
6716 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6717 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6718 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6719 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006720 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006721 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006722 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6723 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006724 if (e != null) {
6725 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6726 throw e;
6727 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006728 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006729 return TelephonyScanManager.INVALID_SCAN_ID;
6730 }
6731 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 }
Hall Liu912dfd32019-04-25 14:02:26 -07006733 int callingUid = Binder.getCallingUid();
6734 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006735 final long identity = Binder.clearCallingIdentity();
6736 try {
6737 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006738 renounceFineLocationAccess, request, messenger, binder,
6739 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006740 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006741 } finally {
6742 Binder.restoreCallingIdentity(identity);
6743 }
yinxu504e1392017-04-12 16:03:22 -07006744 }
6745
Hall Liub2ac8ef2019-02-28 15:56:23 -08006746 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006747 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006748 boolean hasCarrierPriv;
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6752 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6753 } finally {
6754 Binder.restoreCallingIdentity(identity);
6755 }
Hall Liu558027f2019-05-15 19:14:05 -07006756 boolean hasNetworkScanPermission =
6757 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006758 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006759
6760 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6761 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6762 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006763 }
6764
6765 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6766 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006767 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6768 return new SecurityException("Specific channels must not be"
6769 + " scanned without location access.");
6770 }
6771 }
6772 }
6773
Hall Liub2ac8ef2019-02-28 15:56:23 -08006774 return null;
6775 }
6776
yinxu504e1392017-04-12 16:03:22 -07006777 /**
6778 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006779 *
6780 * @param subId id of the subscription
6781 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006782 */
6783 @Override
6784 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6786 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787
Hall Liu912dfd32019-04-25 14:02:26 -07006788 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 final long identity = Binder.clearCallingIdentity();
6790 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006791 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
yinxu504e1392017-04-12 16:03:22 -07006795 }
6796
6797 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006798 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006799 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006800 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006801 */
6802 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006803 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006804 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006805 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006806 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006810 if (DBG) log("getAllowedNetworkTypesBitmask");
6811 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6812 int networkTypesBitmask = (result != null ? result[0] : -1);
6813 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6814 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006818 }
6819
6820 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006821 * Get the allowed network types for certain reason.
6822 *
6823 * @param subId the id of the subscription.
6824 * @param reason the reason the allowed network type change is taking place
6825 * @return the allowed network types.
6826 */
6827 @Override
6828 public long getAllowedNetworkTypesForReason(int subId,
6829 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006830 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006831 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006832 final long identity = Binder.clearCallingIdentity();
6833 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006834 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837 }
6838 }
6839
6840 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006841 * Enable/Disable E-UTRA-NR Dual Connectivity
6842 * @param subId subscription id of the sim card
6843 * @param nrDualConnectivityState expected NR dual connectivity state
6844 * This can be passed following states
6845 * <ol>
6846 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6847 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6848 * <li>Disable NR dual connectivity and force secondary cell to be released
6849 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6850 * </ol>
6851 * @return operation result.
6852 */
6853 @Override
6854 public int setNrDualConnectivityState(int subId,
6855 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6857 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006858 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006859 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6860 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6861 }
6862
Sooraj Sasindran37444802020-08-11 10:40:43 -07006863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6867 nrDualConnectivityState, subId,
6868 workSource);
6869 if (DBG) log("enableNRDualConnectivity result: " + result);
6870 return result;
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
6874 }
6875
6876 /**
6877 * Is E-UTRA-NR Dual Connectivity enabled
6878 * @return true if dual connectivity is enabled else false
6879 */
6880 @Override
6881 public boolean isNrDualConnectivityEnabled(int subId) {
6882 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006883 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006884 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006885 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006886 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6887 return false;
6888 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
6892 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6893 null, subId, workSource);
6894 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6895 return isEnabled;
6896 } finally {
6897 Binder.restoreCallingIdentity(identity);
6898 }
6899 }
6900
6901 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006902 * Set the allowed network types of the device and
6903 * provide the reason triggering the allowed network change.
6904 *
6905 * @param subId the id of the subscription.
6906 * @param reason the reason the allowed network type change is taking place
6907 * @param allowedNetworkTypes the allowed network types.
6908 * @return true on success; false on any failure.
6909 */
6910 @Override
6911 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006912 @TelephonyManager.AllowedNetworkTypesReason int reason,
6913 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6915 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006916 // If the caller only has carrier privileges, then they should not be able to override
6917 // any network types which were set for security reasons.
6918 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6919 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006920 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006921 throw new SecurityException(
6922 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006923 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006924 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006925 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006926 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006927 return false;
6928 }
6929 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6930 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006931 return false;
6932 }
6933
Jack Yu5b494332023-01-23 18:18:04 +00006934 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6935 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006936
Jack Yue37dd262022-12-16 11:53:37 -08006937 Phone phone = getPhone(subId);
6938 if (phone == null) {
6939 return false;
6940 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006941
Jack Yue37dd262022-12-16 11:53:37 -08006942 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006943 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006944 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006945 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006946
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006947 final long identity = Binder.clearCallingIdentity();
6948 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006949 Boolean success = (Boolean) sendRequest(
6950 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6951 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6952
6953 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6954 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 }
6959
6960 /**
Miaoa84611c2019-03-15 09:21:10 +08006961 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006962 *
Miaoa84611c2019-03-15 09:21:10 +08006963 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006964 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006965 * @hide
6966 */
6967 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006968 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006969 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006971 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 try {
Miaoa84611c2019-03-15 09:21:10 +08006973 if (phone != null) {
6974 return phone.hasMatchedTetherApnSetting();
6975 } else {
6976 return false;
6977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 } finally {
6979 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006980 }
Junda Liu475951f2014-11-07 16:45:03 -08006981 }
6982
6983 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006984 * Get the user enabled state of Mobile Data.
6985 *
6986 * TODO: remove and use isUserDataEnabled.
6987 * This can't be removed now because some vendor codes
6988 * calls through ITelephony directly while they should
6989 * use TelephonyManager.
6990 *
6991 * @return true on enabled
6992 */
6993 @Override
6994 public boolean getDataEnabled(int subId) {
6995 return isUserDataEnabled(subId);
6996 }
6997
6998 /**
6999 * Get whether mobile data is enabled per user setting.
7000 *
7001 * There are other factors deciding whether mobile data is actually enabled, but they are
7002 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007003 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007004 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7005 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007006 *
7007 * @return {@code true} if data is enabled else {@code false}
7008 */
7009 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007010 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007011 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007012 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007013 try {
7014 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7015 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007016 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007017 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7018 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007019 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007021 mApp, subId, functionName);
7022
Robert Greenwalt646120a2014-05-23 11:54:03 -07007023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
Jack Yu285100e2022-12-02 22:48:35 -08007027 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7029 Phone phone = PhoneFactory.getPhone(phoneId);
7030 if (phone != null) {
7031 boolean retVal = phone.isUserDataEnabled();
7032 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7033 return retVal;
7034 } else {
7035 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7036 return false;
7037 }
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007040 }
7041 }
7042
7043 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007044 * Checks if the device is capable of mobile data by considering whether whether the
7045 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7046 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007047 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007048 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007049 */
7050 @Override
7051 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007052 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007053 try {
7054 try {
7055 mApp.enforceCallingOrSelfPermission(
7056 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007057 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007058 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007059 try {
7060 mApp.enforceCallingOrSelfPermission(
7061 android.Manifest.permission.READ_PHONE_STATE,
7062 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007063 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007064 mApp.enforceCallingOrSelfPermission(
7065 permission.READ_BASIC_PHONE_STATE, functionName);
7066 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007067 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007068 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007069 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071
7072 final long identity = Binder.clearCallingIdentity();
7073 try {
Jack Yu285100e2022-12-02 22:48:35 -08007074 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 Phone phone = PhoneFactory.getPhone(phoneId);
7076 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007077 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007078 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 return retVal;
7080 } else {
7081 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7082 return false;
7083 }
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007086 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007087 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007088
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007089 /**
7090 * Check if data is enabled for a specific reason
7091 * @param subId Subscription index
7092 * @param reason the reason the data enable change is taking place
7093 * @return {@code true} if the overall data is enabled; {@code false} if not.
7094 */
7095 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007096 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007097 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007098 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007099 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007100 try {
7101 mApp.enforceCallingOrSelfPermission(
7102 android.Manifest.permission.ACCESS_NETWORK_STATE,
7103 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007104 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007105 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7106 functionName);
7107 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007108 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007109 try {
7110 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007111 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007112 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007114 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007115 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007116 }
7117
7118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
Jack Yu285100e2022-12-02 22:48:35 -08007121 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007122 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007123 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007124 + " reason=" + reason);
7125 }
7126 Phone phone = PhoneFactory.getPhone(phoneId);
7127 if (phone != null) {
7128 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007129 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007130 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007131 return retVal;
7132 } else {
7133 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007134 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007135 + subId + " retVal=false");
7136 }
7137 return false;
7138 }
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
7142 }
7143
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007144 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007145 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007146 // No permission needed; this only lets the caller inspect their own status.
7147 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007148 }
Junda Liu29340342014-07-10 15:23:27 -07007149
7150 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007151 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007152 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007153 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7154 }
7155
7156 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7157 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007158 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007159 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007160 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7161 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007162 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7163 if (cpt == null) {
7164 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007165 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7166 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007167 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007168 }
7169
7170 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007171 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007172 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007173 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007175 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007176 Phone phone = getPhone(subId);
7177 if (phone == null) {
7178 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7179 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7180 }
7181 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7182 if (cpt == null) {
7183 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007184 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7185 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007186 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007187 }
7188
7189 @Override
7190 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007191 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007192 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7193 }
7194
7195 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007196 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007197 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007198 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007199 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007200 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7201 Phone phone = PhoneFactory.getPhone(phoneId);
7202 if (phone == null) {
7203 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007204 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007205 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7206 if (cpt == null) {
7207 continue;
7208 }
7209 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007210 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7211 break;
7212 }
7213 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007214 return result;
Junda Liu29340342014-07-10 15:23:27 -07007215 }
Derek Tan89e89d42014-07-08 17:00:10 -07007216
7217 @Override
Junda Liue64de782015-04-16 17:19:16 -07007218 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007219 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007220 Phone phone = PhoneFactory.getPhone(phoneId);
7221 if (phone == null) {
7222 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007223 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007224 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7225 if (cpt == null) {
7226 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007227 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007228 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007229 }
7230
Amith Yamasani6e118872016-02-19 12:53:51 -08007231 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007232 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007233 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007234 Phone phone = PhoneFactory.getPhone(phoneId);
7235 if (phone == null) {
7236 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007237 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007238 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7239 if (cpt == null) {
7240 return Collections.emptyList();
7241 }
7242 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007243 }
7244
chen xuf7e9fe82019-05-09 19:31:02 -07007245 @Override
7246 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007247 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007248 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007249 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007250 try {
7251 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7252 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7253 }
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007256 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007257 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007258 }
7259
Rambo Wang6812ffb2022-03-15 16:54:17 -07007260 @Override
7261 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7262 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7263
7264 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7265 if (phone == null) {
7266 return null;
7267 }
7268 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7269 if (cpt == null) {
7270 return null;
7271 }
7272 return cpt.getCarrierServicePackageName();
7273 }
7274
Wink Savilleb564aae2014-10-23 10:18:09 -07007275 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007276 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007277 UiccPort port = phone == null ? null : phone.getUiccPort();
7278 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007279 return null;
7280 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007281 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007282 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007283 return null;
7284 }
7285 return iccId;
7286 }
7287
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007288 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007289 public void setCallComposerStatus(int subId, int status) {
7290 enforceModifyPermission();
7291
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
7294 Phone phone = getPhone(subId);
7295 if (phone != null) {
7296 Phone defaultPhone = phone.getImsPhone();
7297 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7298 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7299 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007300 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7301 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007302 }
7303 }
Shuo Qian284ae752020-12-22 19:10:14 -08007304 } catch (ImsException e) {
7305 throw new ServiceSpecificException(e.getCode());
7306 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007307 Binder.restoreCallingIdentity(identity);
7308 }
7309 }
7310
7311 @Override
7312 public int getCallComposerStatus(int subId) {
7313 enforceReadPrivilegedPermission("getCallComposerStatus");
7314
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 Phone phone = getPhone(subId);
7318 if (phone != null) {
7319 Phone defaultPhone = phone.getImsPhone();
7320 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7321 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7322 return imsPhone.getCallComposerStatus();
7323 }
7324 }
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
7328 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7329 }
7330
7331 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007332 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7333 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007334 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007335 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 final long identity = Binder.clearCallingIdentity();
7338 try {
7339 final String iccId = getIccId(subId);
7340 final Phone phone = getPhone(subId);
7341 if (phone == null) {
7342 return false;
7343 }
7344 final String subscriberId = phone.getSubscriberId();
7345
7346 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007347 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 + subscriberId + " to " + number);
7349 }
7350
7351 if (TextUtils.isEmpty(iccId)) {
7352 return false;
7353 }
7354
7355 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7356
7357 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7358 if (alphaTag == null) {
7359 editor.remove(alphaTagPrefKey);
7360 } else {
7361 editor.putString(alphaTagPrefKey, alphaTag);
7362 }
7363
7364 // Record both the line number and IMSI for this ICCID, since we need to
7365 // track all merged IMSIs based on line number
7366 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7367 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7368 if (number == null) {
7369 editor.remove(numberPrefKey);
7370 editor.remove(subscriberPrefKey);
7371 } else {
7372 editor.putString(numberPrefKey, number);
7373 editor.putString(subscriberPrefKey, subscriberId);
7374 }
7375
7376 editor.commit();
7377 return true;
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007380 }
Derek Tan7226c842014-07-02 17:42:23 -07007381 }
7382
7383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007384 public String getLine1NumberForDisplay(int subId, String callingPackage,
7385 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007386 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007388 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007389 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007390 return null;
7391 }
Derek Tan97ebb422014-09-05 16:55:38 -07007392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 final long identity = Binder.clearCallingIdentity();
7394 try {
7395 String iccId = getIccId(subId);
7396 if (iccId != null) {
7397 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7398 if (DBG_MERGE) {
7399 log("getLine1NumberForDisplay returning "
7400 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7401 }
7402 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7405 return null;
7406 } finally {
7407 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007408 }
Derek Tan7226c842014-07-02 17:42:23 -07007409 }
7410
7411 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007412 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7413 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007415 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007416 return null;
7417 }
Derek Tan97ebb422014-09-05 16:55:38 -07007418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 final long identity = Binder.clearCallingIdentity();
7420 try {
7421 String iccId = getIccId(subId);
7422 if (iccId != null) {
7423 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7424 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7425 }
7426 return null;
7427 } finally {
7428 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007429 }
Derek Tan7226c842014-07-02 17:42:23 -07007430 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007431
7432 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007433 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7434 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007435 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7436 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007438 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007440 return null;
7441 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007442
Jordan Liub49b04b2019-05-06 14:45:15 -07007443 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7444 // the process, where TelephonyManager was instantiated.
7445 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007446 final long identity = Binder.clearCallingIdentity();
7447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007448 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 final TelephonyManager tele = TelephonyManager.from(context);
7450 final SubscriptionManager sub = SubscriptionManager.from(context);
7451
7452 // Figure out what subscribers are currently active
7453 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454
Jordan Liub49b04b2019-05-06 14:45:15 -07007455 // Only consider subs which match the current subId
7456 // This logic can be simplified. See b/131189269 for progress.
7457 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007458 activeSubscriberIds.add(tele.getSubscriberId(subId));
7459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460
7461 // First pass, find a number override for an active subscriber
7462 String mergeNumber = null;
7463 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7464 for (String key : prefs.keySet()) {
7465 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7466 final String subscriberId = (String) prefs.get(key);
7467 if (activeSubscriberIds.contains(subscriberId)) {
7468 final String iccId = key.substring(
7469 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7470 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7471 mergeNumber = (String) prefs.get(numberKey);
7472 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007473 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 + " for active subscriber " + subscriberId);
7475 }
7476 if (!TextUtils.isEmpty(mergeNumber)) {
7477 break;
7478 }
7479 }
7480 }
7481 }
7482
7483 // Shortcut when no active merged subscribers
7484 if (TextUtils.isEmpty(mergeNumber)) {
7485 return null;
7486 }
7487
7488 // Second pass, find all subscribers under that line override
7489 final ArraySet<String> result = new ArraySet<>();
7490 for (String key : prefs.keySet()) {
7491 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7492 final String number = (String) prefs.get(key);
7493 if (mergeNumber.equals(number)) {
7494 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7495 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7496 final String subscriberId = (String) prefs.get(subscriberKey);
7497 if (!TextUtils.isEmpty(subscriberId)) {
7498 result.add(subscriberId);
7499 }
7500 }
7501 }
7502 }
7503
7504 final String[] resultArray = result.toArray(new String[result.size()]);
7505 Arrays.sort(resultArray);
7506 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007507 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7509 }
7510 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007511 } finally {
7512 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007513 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007514 }
7515
7516 @Override
zoey chen38003472019-12-13 17:16:31 +08007517 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7518 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007519
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 final TelephonyManager telephonyManager = mApp.getSystemService(
7523 TelephonyManager.class);
7524 String subscriberId = telephonyManager.getSubscriberId(subId);
7525 if (subscriberId == null) {
7526 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007527 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007528 + subId);
7529 }
7530 return null;
7531 }
7532
Jack Yu3beaf9d2023-04-14 09:17:27 -07007533 final SubscriptionInfo info = getSubscriptionManagerService()
7534 .getSubscriptionInfo(subId);
7535 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007536 // If it doesn't belong to any group, return just subscriberId of itself.
7537 if (groupUuid == null) {
7538 return new String[]{subscriberId};
7539 }
7540
7541 // Get all subscriberIds from the group.
7542 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007543 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7544 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7545 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007546 for (SubscriptionInfo subInfo : groupInfos) {
7547 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7548 if (subscriberId != null) {
7549 mergedSubscriberIds.add(subscriberId);
7550 }
7551 }
7552
7553 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7554 } finally {
7555 Binder.restoreCallingIdentity(identity);
7556
7557 }
7558 }
7559
7560 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007561 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007563 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 final Phone phone = getPhone(subId);
7568 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007572 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007573
7574 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007575 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007576 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7577 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007578 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7579 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 final Phone phone = getPhone(subId);
7584 if (phone == null) {
7585 return false;
7586 }
7587 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7588 cdmaNonRoamingList);
7589 } finally {
7590 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007591 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007592 }
7593
7594 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007595 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007596 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007597 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007598 if (phone == null) {
7599 return raf;
7600 }
7601
Shuo Qiandee53402020-05-29 14:08:15 -07007602 try {
7603 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007604 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007605 mApp, phone.getSubId(), "getRadioAccessFamily");
7606 } catch (SecurityException e) {
7607 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7608 throw e;
7609 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 final long identity = Binder.clearCallingIdentity();
7612 try {
chen xub97461a2018-10-26 14:17:57 -07007613 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 } finally {
7615 Binder.restoreCallingIdentity(identity);
7616 }
chen xub97461a2018-10-26 14:17:57 -07007617 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007618 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007619
7620 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007621 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007622 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007623 try {
7624 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7625 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007626 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007627 }
7628 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007629 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007630 }
7631 RoleManager rm = mApp.getSystemService(RoleManager.class);
7632 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7633 if (!dialerRoleHolders.contains(callingPackage)) {
7634 throw new SecurityException("App must be the dialer role holder to"
7635 + " upload a call composer pic");
7636 }
7637
7638 Executors.newSingleThreadExecutor().execute(() -> {
7639 ByteArrayOutputStream output = new ByteArrayOutputStream(
7640 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7641 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7642 boolean readUntilEnd = false;
7643 int totalBytesRead = 0;
7644 byte[] buffer = new byte[16 * 1024];
7645 while (true) {
7646 int numRead;
7647 try {
7648 numRead = input.read(buffer);
7649 } catch (IOException e) {
7650 try {
7651 fd.checkError();
7652 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7653 null);
7654 } catch (IOException e1) {
7655 // This means that the other side closed explicitly with an error. If this
7656 // happens, log and ignore.
7657 loge("Remote end of call composer picture pipe closed: " + e1);
7658 }
7659 break;
7660 }
7661 if (numRead == -1) {
7662 readUntilEnd = true;
7663 break;
7664 }
7665 totalBytesRead += numRead;
7666 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7667 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7668 try {
7669 input.close();
7670 } catch (IOException e) {
7671 // ignore
7672 }
7673 break;
7674 }
7675 output.write(buffer, 0, numRead);
7676 }
7677 // Generally, the remote end will close the file descriptors. The only case where we
7678 // close is above, where the picture size is too big.
7679
7680 try {
7681 fd.checkError();
7682 } catch (IOException e) {
7683 loge("Remote end for call composer closed with an error: " + e);
7684 return;
7685 }
7686
Hall Liuaa4211e2021-01-20 15:43:39 -08007687 if (!readUntilEnd) {
7688 loge("Did not finish reading entire image; aborting");
7689 return;
7690 }
Hall Liu82694d52020-12-11 18:22:04 -08007691
Hall Liuaa4211e2021-01-20 15:43:39 -08007692 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7693 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7694 new CallComposerPictureTransfer.Factory() {},
7695 imageData,
7696 (result) -> {
7697 if (result.first != null) {
7698 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7699 Bundle outputResult = new Bundle();
7700 outputResult.putParcelable(
7701 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7702 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7703 outputResult);
7704 } else {
7705 callback.send(result.second, null);
7706 }
7707 }
7708 );
Hall Liu82694d52020-12-11 18:22:04 -08007709 });
7710 }
7711
7712 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007713 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007714 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007715 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716
7717 final long identity = Binder.clearCallingIdentity();
7718 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007719 ImsManager.getInstance(defaultPhone.getContext(),
7720 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 } finally {
7722 Binder.restoreCallingIdentity(identity);
7723 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007724 }
7725
7726 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007727 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007728 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7730 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007731 return false;
7732 }
Svet Ganovb320e182015-04-16 12:30:10 -07007733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 final long identity = Binder.clearCallingIdentity();
7735 try {
7736 // Check the user preference and the system-level IMS setting. Even if the user has
7737 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7738 // In the long run, we may instead need to check if there exists a connection service
7739 // which can support video calling.
7740 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 return imsManager.isVtEnabledByPlatform()
7743 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7744 && imsManager.isVtEnabledByUser();
7745 } finally {
7746 Binder.restoreCallingIdentity(identity);
7747 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007748 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007749
Andrew Leea1239f22015-03-02 17:44:07 -08007750 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007751 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7752 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007754 mApp, subId, callingPackage, callingFeatureId,
7755 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 return false;
7757 }
7758
7759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 CarrierConfigManager configManager =
7762 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
Andrew Leea1239f22015-03-02 17:44:07 -08007768 }
7769
7770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007771 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007773 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 return false;
7775 }
7776
7777 final long identity = Binder.clearCallingIdentity();
7778 try {
7779 CarrierConfigManager configManager =
7780 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007781 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7783 } finally {
7784 Binder.restoreCallingIdentity(identity);
7785 }
Andrew Leea1239f22015-03-02 17:44:07 -08007786 }
7787
Andrew Lee9431b832015-03-09 18:46:45 -07007788 @Override
7789 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007790 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007791 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007792 }
7793
7794 @Override
7795 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 final long identity = Binder.clearCallingIdentity();
7797 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007798 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 } finally {
7800 Binder.restoreCallingIdentity(identity);
7801 }
Andrew Lee9431b832015-03-09 18:46:45 -07007802 }
7803
Hall Liuf6668912018-10-31 17:05:23 -07007804 /**
7805 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7806 * support for the feature and device firmware support.
7807 *
7808 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7809 */
7810 @Override
7811 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007813 final Phone phone = getPhone(subscriptionId);
7814 if (phone == null) {
7815 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7816 return false;
7817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007819 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7821 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007822 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 return isCarrierSupported && isDeviceSupported;
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
Hall Liu98187582018-01-22 19:15:32 -08007827 }
7828
Hall Liuf6668912018-10-31 17:05:23 -07007829 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007830 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7831 * RTT setting, will return true if the device and carrier both support RTT.
7832 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007833 */
7834 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 final long identity = Binder.clearCallingIdentity();
7836 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007837 boolean isRttSupported = isRttSupported(subscriptionId);
7838 boolean isUserRttSettingOn = Settings.Secure.getInt(
7839 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7840 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7841 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7842 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007846 }
7847
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007848 @Deprecated
7849 @Override
7850 public String getDeviceId(String callingPackage) {
7851 return getDeviceIdWithFeature(callingPackage, null);
7852 }
7853
Sanket Padawe7310cc72015-01-14 09:53:20 -08007854 /**
7855 * Returns the unique device ID of phone, for example, the IMEI for
7856 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7857 *
7858 * <p>Requires Permission:
7859 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7860 */
7861 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007862 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007863 try {
7864 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7865 } catch (SecurityException se) {
7866 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7867 throw new SecurityException("Package " + callingPackage + " does not belong to "
7868 + Binder.getCallingUid());
7869 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007870 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007871 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007872 return null;
7873 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007874 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007875 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007876 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007877 return null;
7878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879
7880 final long identity = Binder.clearCallingIdentity();
7881 try {
7882 return phone.getDeviceId();
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007886 }
7887
Ping Sunc67b7c22016-03-02 19:16:45 +08007888 /**
7889 * {@hide}
7890 * Returns the IMS Registration Status on a particular subid
7891 *
7892 * @param subId
7893 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007894 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007895 Phone phone = getPhone(subId);
7896 if (phone != null) {
7897 return phone.isImsRegistered();
7898 } else {
7899 return false;
7900 }
7901 }
7902
Santos Cordon7a1885b2015-02-03 11:15:19 -08007903 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007904 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007905 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007907 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007908 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7909 }
7910 final long identity = Binder.clearCallingIdentity();
7911 try {
7912 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7913 } finally {
7914 Binder.restoreCallingIdentity(identity);
7915 }
7916 }
7917
7918 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007919 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007920 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007921 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007922 mApp,
7923 subscriptionId,
7924 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7925 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 Phone phone = getPhone(subscriptionId);
7929 if (phone == null) {
7930 return null;
7931 }
7932 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7933 } finally {
7934 Binder.restoreCallingIdentity(identity);
7935 }
7936 }
7937
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007938 /**
7939 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007940 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007941 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 final long identity = Binder.clearCallingIdentity();
7943 try {
7944 Phone phone = getPhone(subId);
7945 if (phone != null) {
7946 return phone.isWifiCallingEnabled();
7947 } else {
7948 return false;
7949 }
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007952 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007953 }
7954
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007955 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007956 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007957 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007958 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 Phone phone = getPhone(subId);
7962 if (phone != null) {
7963 return phone.isVideoEnabled();
7964 } else {
7965 return false;
7966 }
7967 } finally {
7968 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007969 }
7970 }
7971
7972 /**
7973 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7974 * defined in {@link ImsRegistrationImplBase}.
7975 */
7976 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 Phone phone = getPhone(subId);
7980 if (phone != null) {
7981 return phone.getImsRegistrationTech();
7982 } else {
7983 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7984 }
7985 } finally {
7986 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007987 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007988 }
7989
Stuart Scott8eef64f2015-04-08 15:13:54 -07007990 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007991 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007992 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007993 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7994 return;
7995 }
Kai Shif70f46f2021-03-03 13:59:46 -08007996 Phone defaultPhone = getDefaultPhone();
7997 if (defaultPhone != null) {
7998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7999 mApp, getDefaultPhone().getSubId(), "factoryReset");
8000 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008001 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008002
Svet Ganovcc087f82015-05-12 20:35:54 -07008003 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008004 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8005 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008006 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008007 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008008 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008009 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008010 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008011 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008012 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008013 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008014 // There has been issues when Sms raw table somehow stores orphan
8015 // fragments. They lead to garbled message when new fragments come
8016 // in and combined with those stale ones. In case this happens again,
8017 // user can reset all network settings which will clean up this table.
8018 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008019 // Clean up IMS settings as well here.
8020 int slotId = getSlotIndex(subId);
8021 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8022 ImsManager.getInstance(mApp, slotId).factoryReset();
8023 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008024
Kai Shif70f46f2021-03-03 13:59:46 -08008025 if (defaultPhone == null) {
8026 return;
8027 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008028 // Erase modem config if erase modem on network setting is enabled.
8029 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8030 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8031 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008032 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008033 }
Kai Shif70f46f2021-03-03 13:59:46 -08008034
8035 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008036 } finally {
8037 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008038 }
8039 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008040
SongFerngWangfd89b102021-05-27 22:44:54 +08008041 @VisibleForTesting
8042 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8043 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8044 return;
8045 }
8046 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8047 RILConstants.PREFERRED_NETWORK_MODE);
8048 SubscriptionManager.setSubscriptionProperty(subId,
8049 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8050 "user=" + defaultNetworkType);
8051 phone.loadAllowedNetworksFromSubscriptionDatabase();
8052 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8053 defaultNetworkType, null);
8054 }
8055
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008056 private void cleanUpSmsRawTable(Context context) {
8057 ContentResolver resolver = context.getContentResolver();
8058 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8059 resolver.delete(uri, null, null);
8060 }
8061
Narayan Kamath1c496c22015-04-16 14:40:19 +01008062 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008063 public String getSimLocaleForSubscriber(int subId) {
8064 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8065 final Phone phone = getPhone(subId);
8066 if (phone == null) {
8067 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008068 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 final long identity = Binder.clearCallingIdentity();
8071 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008072 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8073 phone.getContext().getOpPackageName(),
8074 phone.getContext().getAttributionTag());
8075 if (info == null) {
8076 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8077 return null;
chen xu6291c472019-02-04 12:55:53 -08008078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 // Try and fetch the locale from the carrier properties or from the SIM language
8080 // preferences (EF-PL and EF-LI)...
8081 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008082 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008083 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8084 if (localeFromDefaultSim != null) {
8085 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8086 if (DBG) log("Using locale from subId: " + subId + " locale: "
8087 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008088 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008089 } else {
8090 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 }
8092 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094 // The SIM language preferences only store a language (e.g. fr = French), not an
8095 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8096 // the SIM and carrier preferences does not include a country we add the country
8097 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008098 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008100 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008101 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 }
8103
8104 if (DBG) log("No locale found - returning null");
8105 return null;
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
8108 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008109 }
8110
tom hsu0b59d292022-09-29 23:49:21 +08008111 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008112 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008113 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008114 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008115 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008116 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8117 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008118 Locale.forLanguageTag(localeTag).getCountry())) {
8119 return localeTag;
8120 }
8121 }
8122 return inputLocale.toLanguageTag();
8123 }
8124
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 /**
8126 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8127 */
8128 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008129 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008130 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008131 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008132
Gary Jian3aa9a762022-01-24 16:41:19 +08008133 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8134 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008135
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008136 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008137 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8138 * representing the state of the modem.
8139 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008140 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8141 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008142 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008143 */
8144 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008145 public void requestModemActivityInfo(ResultReceiver result) {
8146 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008147 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148
8149 final long identity = Binder.clearCallingIdentity();
8150 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008151 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152 } finally {
8153 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008154 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008155 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008156
Gary Jian76280a42022-12-07 16:18:33 +08008157 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008158 // less than total activity duration.
8159 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8160 if (info == null) {
8161 return false;
8162 }
8163 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008164 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008165 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8166
Hall Liu49656c02020-10-09 19:00:11 -07008167 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8168
Siddharth Rayb8114062018-06-17 15:02:38 -07008169 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008170 && (info.getSleepTimeMillis() <= activityDurationMs)
8171 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008172 }
8173
Gary Jian3aa9a762022-01-24 16:41:19 +08008174 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8175 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8176 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8177 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8178
8179 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8180 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8181 }
8182
8183 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8184 mLastModemActivityInfo.setReceiveTimeMillis(
8185 rat,
8186 freq,
8187 info.getReceiveTimeMillis(rat, freq)
8188 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8189 }
8190
8191 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8192 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8193 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8194 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8195
8196 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8197 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8198 }
8199 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8200 mLastModemActivityInfo.setReceiveTimeMillis(
8201 rat,
8202 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8203 }
8204
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008205 /**
8206 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8207 * @param info recent ModemActivityInfo
8208 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008209 private void mergeModemActivityInfo(ModemActivityInfo info) {
8210 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008211 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008212 boolean matched;
8213 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8214 matched = false;
8215 int rat = info.getSpecificInfoRat(i);
8216 int freq = info.getSpecificInfoFrequencyRange(i);
8217 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8218 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8219 //if it already exists
8220 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8221 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8222 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8223 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8224 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8225 updateLastModemActivityInfo(info, rat, freq);
8226 matched = true;
8227 }
8228 } else {
8229 updateLastModemActivityInfo(info, rat);
8230 matched = true;
8231 }
8232 }
8233 }
8234
8235 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008236 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008237 new ActivityStatsTechSpecificInfo(
8238 rat,
8239 freq,
8240 info.getTransmitTimeMillis(rat, freq),
8241 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008242 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008243 }
8244 }
8245 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8246 mLastModemActivitySpecificInfo =
8247 new ActivityStatsTechSpecificInfo[merged.size()];
8248 merged.toArray(mLastModemActivitySpecificInfo);
8249
8250 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8251 mLastModemActivityInfo.setSleepTimeMillis(
8252 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008253 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008254 mLastModemActivityInfo.setIdleTimeMillis(
8255 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008256 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008257
8258 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008259 new ModemActivityInfo(
8260 mLastModemActivityInfo.getTimestampMillis(),
8261 mLastModemActivityInfo.getSleepTimeMillis(),
8262 mLastModemActivityInfo.getIdleTimeMillis(),
8263 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008264 }
8265
8266 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8267 ActivityStatsTechSpecificInfo[] info) {
8268 int infoSize = info.length;
8269 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8270 for (int i = 0; i < infoSize; i++) {
8271 ret[i] = new ActivityStatsTechSpecificInfo(
8272 info[i].getRat(), info[i].getFrequencyRange(),
8273 info[i].getTransmitTimeMillis(),
8274 (int) info[i].getReceiveTimeMillis());
8275 }
8276 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008277 }
8278
Jack Yu85bd38a2015-11-09 11:34:32 -08008279 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008280 * Returns the service state information on specified subscription.
8281 */
8282 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008283 public ServiceState getServiceStateForSubscriber(int subId,
8284 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8285 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008287 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008288 return null;
8289 }
8290
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008291 boolean hasFinePermission = false;
8292 boolean hasCoarsePermission = false;
8293 if (!renounceFineLocationAccess) {
8294 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8295 LocationAccessPolicy.checkLocationPermission(mApp,
8296 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8297 .setCallingPackage(callingPackage)
8298 .setCallingFeatureId(callingFeatureId)
8299 .setCallingPid(Binder.getCallingPid())
8300 .setCallingUid(Binder.getCallingUid())
8301 .setMethod("getServiceStateForSubscriber")
8302 .setLogAsInfo(true)
8303 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8304 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8305 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8306 .build());
8307 hasFinePermission =
8308 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8309 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008310
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008311 if (!renounceCoarseLocationAccess) {
8312 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8313 LocationAccessPolicy.checkLocationPermission(mApp,
8314 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8315 .setCallingPackage(callingPackage)
8316 .setCallingFeatureId(callingFeatureId)
8317 .setCallingPid(Binder.getCallingPid())
8318 .setCallingUid(Binder.getCallingUid())
8319 .setMethod("getServiceStateForSubscriber")
8320 .setLogAsInfo(true)
8321 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8322 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8323 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8324 .build());
8325 hasCoarsePermission =
8326 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8327 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008328
Jack Yu479f40e2020-10-27 21:29:25 -07008329 final Phone phone = getPhone(subId);
8330 if (phone == null) {
8331 return null;
8332 }
8333
Jordan Liu0f2bc442020-11-18 16:47:37 -08008334 final long identity = Binder.clearCallingIdentity();
8335
Jack Yu479f40e2020-10-27 21:29:25 -07008336 boolean isCallingPackageDataService = phone.getDataServicePackages()
8337 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008339 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008340 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8341 .getSubscriptionInfoInternal(subId);
8342 if (subInfo == null || !subInfo.isActive()) {
8343 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8344 + "subId=" + subId);
8345 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008346 }
8347
Hall Liuf19c44f2018-11-27 14:38:17 -08008348 ServiceState ss = phone.getServiceState();
8349
8350 // Scrub out the location info in ServiceState depending on what level of access
8351 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008352 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008353 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8354 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 } finally {
8356 Binder.restoreCallingIdentity(identity);
8357 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008358 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008359
8360 /**
8361 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8362 *
8363 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8364 * voicemail ringtone.
8365 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8366 * PhoneAccount.
8367 */
8368 @Override
8369 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8373 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008374 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008381 }
8382
8383 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008384 * Sets the per-account voicemail ringtone.
8385 *
8386 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8387 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8388 *
8389 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8390 * voicemail ringtone.
8391 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8392 * PhoneAccount.
8393 */
8394 @Override
8395 public void setVoicemailRingtoneUri(String callingPackage,
8396 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008397 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008399 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8400 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8402 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8403 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8409 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008410 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411 }
8412 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008415 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008416 }
8417
8418 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008419 * Returns whether vibration is set for voicemail notification in Phone settings.
8420 *
8421 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8422 * voicemail vibration setting.
8423 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8424 */
8425 @Override
8426 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8430 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008431 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8435 } finally {
8436 Binder.restoreCallingIdentity(identity);
8437 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008438 }
8439
Youhan Wange64578a2016-05-02 15:32:42 -07008440 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008441 * Sets the per-account voicemail vibration.
8442 *
8443 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8444 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8445 *
8446 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8447 * voicemail vibration setting.
8448 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8449 * specific PhoneAccount.
8450 */
8451 @Override
8452 public void setVoicemailVibrationEnabled(String callingPackage,
8453 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008454 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008456 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8457 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8459 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8460 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008461 }
8462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8466 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008467 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468 }
8469 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008472 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008473 }
8474
8475 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008476 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8477 *
8478 * @throws SecurityException if the caller does not have the required permission
8479 */
arunvoddud7401012022-12-15 16:08:12 +00008480 @VisibleForTesting
8481 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008482 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008483 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008484 }
8485
8486 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008487 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8488 * permission.
8489 *
8490 * @throws SecurityException if the caller does not have the required permission
8491 */
8492 private void enforceSendSmsPermission() {
8493 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8494 }
8495
8496 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008497 * Make sure either called from same process as self (phone) or IPC caller has interact across
8498 * users permission.
8499 *
8500 * @throws SecurityException if the caller does not have the required permission
8501 */
8502 private void enforceInteractAcrossUsersPermission(String message) {
8503 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8504 }
8505
8506 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008507 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008508 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008509 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008510 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008511 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008515 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 if (componentName == null) {
8517 throw new SecurityException(
8518 "Caller not current active visual voicemail package[null]");
8519 }
8520 String vvmPackage = componentName.getPackageName();
8521 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008522 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523 }
8524 } finally {
8525 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008526 }
8527 }
8528
8529 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008530 * Return the application ID for the app type.
8531 *
8532 * @param subId the subscription ID that this request applies to.
8533 * @param appType the uicc app type.
8534 * @return Application ID for specificied app type, or null if no uicc.
8535 */
8536 @Override
8537 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008538 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008539 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540
8541 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008542 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 if (phone == null) {
8544 return null;
8545 }
8546 String aid = null;
8547 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008548 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008549 .getApplicationByType(appType).getAid();
8550 } catch (Exception e) {
8551 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8552 }
8553 return aid;
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008556 }
Youhan Wange64578a2016-05-02 15:32:42 -07008557 }
8558
Youhan Wang4001d252016-05-11 10:29:41 -07008559 /**
8560 * Return the Electronic Serial Number.
8561 *
8562 * @param subId the subscription ID that this request applies to.
8563 * @return ESN or null if error.
8564 */
8565 @Override
8566 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008567 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008568 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569
8570 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008571 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008572 if (phone == null) {
8573 return null;
8574 }
8575 String esn = null;
8576 try {
8577 esn = phone.getEsn();
8578 } catch (Exception e) {
8579 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8580 }
8581 return esn;
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008584 }
Youhan Wang4001d252016-05-11 10:29:41 -07008585 }
8586
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008587 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008588 * Return the Preferred Roaming List Version.
8589 *
8590 * @param subId the subscription ID that this request applies to.
8591 * @return PRLVersion or null if error.
8592 */
8593 @Override
8594 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008595 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008596 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597
8598 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008599 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600 if (phone == null) {
8601 return null;
8602 }
8603 String cdmaPrlVersion = null;
8604 try {
8605 cdmaPrlVersion = phone.getCdmaPrlVersion();
8606 } catch (Exception e) {
8607 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8608 }
8609 return cdmaPrlVersion;
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008612 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008613 }
8614
8615 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008616 * Get snapshot of Telephony histograms
8617 * @return List of Telephony histograms
8618 * @hide
8619 */
8620 @Override
8621 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8623 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008624
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 return RIL.getTelephonyRILTimingHistograms();
8628 } finally {
8629 Binder.restoreCallingIdentity(identity);
8630 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008631 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008632
8633 /**
8634 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008635 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8636 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008637 * Require system privileges. In the future we may add this to carrier APIs.
8638 *
Michele Berionne482f8202018-11-27 18:57:59 -08008639 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008640 */
8641 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008642 @TelephonyManager.SetCarrierRestrictionResult
8643 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008644 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008645 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008646
Michele Berionne482f8202018-11-27 18:57:59 -08008647 if (carrierRestrictionRules == null) {
8648 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008649 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008651 final long identity = Binder.clearCallingIdentity();
8652 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008653 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008654 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655 } finally {
8656 Binder.restoreCallingIdentity(identity);
8657 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008658 }
8659
8660 /**
8661 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008662 * Get the allowed carrier list and the excluded carrier list, including the priority between
8663 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008664 * Require system privileges. In the future we may add this to carrier APIs.
8665 *
Michele Berionne482f8202018-11-27 18:57:59 -08008666 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008667 */
8668 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008669 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008670 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008671 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008672
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008675 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8676 if (response instanceof CarrierRestrictionRules) {
8677 return (CarrierRestrictionRules) response;
8678 }
8679 // Response is an Exception of some kind,
8680 // which is signalled to the user as a NULL retval
8681 return null;
8682 } catch (Exception e) {
8683 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8684 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008688 }
8689
fionaxu59545b42016-05-25 15:53:37 -07008690 /**
arunvoddud7401012022-12-15 16:08:12 +00008691 * Fetches the carrier restriction status of the device and sends the status to the caller
8692 * through the callback.
8693 *
8694 * @param callback The callback that will be used to send the result.
8695 * @throws SecurityException if the caller does not have the required permission/privileges or
8696 * the caller is not allowlisted.
8697 */
8698 @Override
8699 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8700 enforceReadPermission("getCarrierRestrictionStatus");
8701 int carrierId = validateCallerAndGetCarrierId(packageName);
8702 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8703 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8704 throw new SecurityException("Not an authorized caller");
8705 }
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8709 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8710 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
8714 }
8715
arunvoddu567f2b42023-04-25 17:22:00 +00008716 @Override
8717 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8718 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8719 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8720 return allowListInfo.getShaIdList(pkgName, carrierId);
8721 }
8722
arunvoddud7401012022-12-15 16:08:12 +00008723 @VisibleForTesting
8724 public int validateCallerAndGetCarrierId(String packageName) {
8725 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8726 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8727 }
8728
8729 /**
fionaxu59545b42016-05-25 15:53:37 -07008730 * Action set from carrier signalling broadcast receivers to enable/disable radio
8731 * @param subId the subscription ID that this action applies to.
8732 * @param enabled control enable or disable radio.
8733 * {@hide}
8734 */
8735 @Override
8736 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8737 enforceModifyPermission();
8738 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008739
8740 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008741 if (phone == null) {
8742 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8743 return;
8744 }
8745 try {
8746 phone.carrierActionSetRadioEnabled(enabled);
8747 } catch (Exception e) {
8748 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008749 } finally {
8750 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008751 }
8752 }
8753
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008754 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008755 * Enable or disable Voice over NR (VoNR)
8756 * @param subId the subscription ID that this action applies to.
8757 * @param enabled enable or disable VoNR.
8758 * @return operation result.
8759 */
8760 @Override
8761 public int setVoNrEnabled(int subId, boolean enabled) {
8762 enforceModifyPermission();
8763 final Phone phone = getPhone(subId);
8764
8765 final long identity = Binder.clearCallingIdentity();
8766 if (phone == null) {
8767 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8768 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8769 }
8770
8771 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8772 try {
8773 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8774 workSource);
8775 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008776
8777 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8778 if (DBG) {
8779 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8780 }
8781 SubscriptionManager.setSubscriptionProperty(
8782 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8783 (enabled ? "1" : "0"));
8784 }
8785
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008786 return result;
8787 } finally {
8788 Binder.restoreCallingIdentity(identity);
8789 }
8790 }
8791
8792 /**
8793 * Is voice over NR enabled
8794 * @return true if VoNR is enabled else false
8795 */
8796 @Override
8797 public boolean isVoNrEnabled(int subId) {
8798 enforceReadPrivilegedPermission("isVoNrEnabled");
8799 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8800 final long identity = Binder.clearCallingIdentity();
8801 try {
8802 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8803 null, subId, workSource);
8804 if (DBG) log("isVoNrEnabled: " + isEnabled);
8805 return isEnabled;
8806 } finally {
8807 Binder.restoreCallingIdentity(identity);
8808 }
8809 }
8810
8811 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008812 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8813 * network status based on which carrier apps could apply actions accordingly,
8814 * enable/disable default url handler for example.
8815 *
8816 * @param subId the subscription ID that this action applies to.
8817 * @param report control start/stop reporting the default network status.
8818 * {@hide}
8819 */
8820 @Override
8821 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8822 enforceModifyPermission();
8823 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008824
8825 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008826 if (phone == null) {
8827 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8828 return;
8829 }
8830 try {
8831 phone.carrierActionReportDefaultNetworkStatus(report);
8832 } catch (Exception e) {
8833 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008834 } finally {
8835 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008836 }
8837 }
8838
8839 /**
fionaxud9622282017-07-17 17:51:30 -07008840 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8841 * @param subId the subscription ID that this action applies to.
8842 * {@hide}
8843 */
8844 @Override
8845 public void carrierActionResetAll(int subId) {
8846 enforceModifyPermission();
8847 final Phone phone = getPhone(subId);
8848 if (phone == null) {
8849 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8850 return;
8851 }
8852 try {
8853 phone.carrierActionResetAll();
8854 } catch (Exception e) {
8855 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8856 }
8857 }
8858
8859 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008860 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8861 * bug report is being generated.
8862 */
8863 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008864 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008865 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8866 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008867 writer.println("Permission Denial: can't dump Phone from pid="
8868 + Binder.getCallingPid()
8869 + ", uid=" + Binder.getCallingUid()
8870 + "without permission "
8871 + android.Manifest.permission.DUMP);
8872 return;
8873 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008874 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008875 }
Jack Yueb89b242016-06-22 13:27:47 -07008876
Brad Ebingerdac2f002018-04-03 15:17:52 -07008877 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008878 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8879 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8880 @NonNull String[] args) {
8881 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8882 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008883 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008884 }
8885
Jack Yueb89b242016-06-22 13:27:47 -07008886 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008887 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008888 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008889 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008890 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008891 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008892 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008893 */
8894 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008895 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008896 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008897 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8898 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8899 try {
8900 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008901 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008902 } catch (SecurityException se) {
8903 enforceModifyPermission();
8904 }
8905 } else {
8906 enforceModifyPermission();
8907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908
Nate Myrenae97d192023-06-09 15:22:31 -07008909 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
8910 && null != callingPackage && opEnableMobileDataByUser()) {
8911 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
8912 callingPackage, null, null);
8913 }
8914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 final long identity = Binder.clearCallingIdentity();
8916 try {
8917 Phone phone = getPhone(subId);
8918 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008919 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8920 phone.carrierActionSetMeteredApnsEnabled(enabled);
8921 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008922 phone.getDataSettingsManager().setDataEnabled(
8923 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 }
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008928 }
8929 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008930
8931 /**
8932 * Get Client request stats
8933 * @return List of Client Request Stats
8934 * @hide
8935 */
8936 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008937 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8938 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008940 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008941 return null;
8942 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008943 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 if (phone != null) {
8948 return phone.getClientRequestStats();
8949 }
8950
8951 return null;
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
8954 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008955 }
8956
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008957 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008958 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008959 if (uid == Process.ROOT_UID && packageName == null) {
8960 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8961 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8962 // exception. ROOT_UID seems not to have a valid package name returned by
8963 // PackageManager, so just fake it here to avoid issues when running telephony shell
8964 // commands that plumb through the RIL as root, like so:
8965 // $ adb root
8966 // $ adb shell cmd phone ...
8967 packageName = "root";
8968 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008969 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008970 }
Jack Yueb4124c2017-02-16 15:32:43 -08008971
8972 /**
Grace Chen70990072017-03-24 17:21:30 -07008973 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008974 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008975 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008976 * @param state State of SIM (power down, power up, pass through)
8977 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8978 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8979 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008980 *
8981 **/
8982 @Override
Grace Chen70990072017-03-24 17:21:30 -07008983 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008984 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008985 Phone phone = PhoneFactory.getPhone(slotIndex);
8986
vagdeviaf9a5b92018-08-15 16:01:53 -07008987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008992 phone.setSimPowerState(state, null, workSource);
8993 }
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
8998
8999 /**
9000 * Set SIM card power state.
9001 *
9002 * @param slotIndex SIM slot id.
9003 * @param state State of SIM (power down, power up, pass through)
9004 * @param callback callback to trigger after success or failure
9005 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9006 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9007 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9008 *
9009 **/
9010 @Override
9011 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9012 IIntegerConsumer callback) {
9013 enforceModifyPermission();
9014 Phone phone = PhoneFactory.getPhone(slotIndex);
9015
9016 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9017
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 if (phone != null) {
9021 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9022 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009023 }
9024 } finally {
9025 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009026 }
9027 }
Shuo Qiandd210312017-04-12 22:11:33 +00009028
Tyler Gunn65d45c22017-06-05 11:22:26 -07009029 private boolean isUssdApiAllowed(int subId) {
9030 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009031 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009032 if (configManager == null) {
9033 return false;
9034 }
9035 PersistableBundle pb = configManager.getConfigForSubId(subId);
9036 if (pb == null) {
9037 return false;
9038 }
9039 return pb.getBoolean(
9040 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9041 }
9042
Shuo Qiandd210312017-04-12 22:11:33 +00009043 /**
Ling Mac28f0212023-03-24 16:07:15 -07009044 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009045 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009046 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009047 */
goneil9c5f4872017-12-05 14:07:56 -08009048 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009049 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009050 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009051 final long identity = Binder.clearCallingIdentity();
9052 try {
Ling Mac28f0212023-03-24 16:07:15 -07009053 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009054 } finally {
9055 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009056 }
9057 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009058
9059 /**
9060 * Get the current signal strength information for the given subscription.
9061 * Because this information is not updated when the device is in a low power state
9062 * it should not be relied-upon to be current.
9063 * @param subId Subscription index
9064 * @return the most recent cached signal strength info from the modem
9065 */
9066 @Override
9067 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 final long identity = Binder.clearCallingIdentity();
9069 try {
9070 Phone p = getPhone(subId);
9071 if (p == null) {
9072 return null;
9073 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075 return p.getSignalStrength();
9076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009079 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009080
Pengquan Meng77b7f132018-08-22 14:49:57 -07009081 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009082 * Get the current modem radio state for the given slot.
9083 * @param slotIndex slot index.
9084 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009085 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009086 * @return the current radio power state from the modem
9087 */
9088 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009089 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009090 Phone phone = PhoneFactory.getPhone(slotIndex);
9091 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9093 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009094 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9095 }
9096
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
9099 return phone.getRadioPowerState();
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 }
9104 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9105 }
9106
9107 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009108 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9109 *
9110 * <p>Requires one of the following permissions:
9111 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009112 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009113 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9114 * privileges.
9115 *
9116 * @param subId subscription id
9117 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9118 * {@code false}.
9119 */
9120 @Override
9121 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009122 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009123 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009124 try {
9125 mApp.enforceCallingOrSelfPermission(
9126 android.Manifest.permission.ACCESS_NETWORK_STATE,
9127 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009128 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009129 mApp.enforceCallingOrSelfPermission(
9130 permission.READ_BASIC_PHONE_STATE, functionName);
9131 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009132 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009133 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009134 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009135 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009136
Pengquan Menga1bb6272018-09-06 09:59:22 -07009137 boolean isEnabled = false;
9138 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009139 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009140 Phone phone = getPhone(subId);
9141 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009142 } finally {
9143 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009144 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009145 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009146 }
9147
9148
9149 /**
9150 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9151 *
9152 * <p> Requires permission:
9153 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9154 * privileges.
9155 *
9156 * @param subId subscription id
9157 * @param isEnabled {@code true} means enable, {@code false} means disable.
9158 */
9159 @Override
9160 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9162 mApp, subId, "setDataRoamingEnabled");
9163
Pengquan Menga1bb6272018-09-06 09:59:22 -07009164 final long identity = Binder.clearCallingIdentity();
9165 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009166 Phone phone = getPhone(subId);
9167 if (phone != null) {
9168 phone.setDataRoamingEnabled(isEnabled);
9169 }
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009172 }
9173 }
9174
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009175 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009176 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009177 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009178 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009179 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009180
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009181 boolean isAllowed = true;
9182 final long identity = Binder.clearCallingIdentity();
9183 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009184 Phone phone = getPhone(subId);
9185 if (phone != null) {
9186 isAllowed = phone.isCspPlmnEnabled();
9187 }
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 return isAllowed;
9192 }
9193
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009194 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9195 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009196 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009197 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009198 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009199 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9200 if (phone == null) {
9201 return false;
9202 }
9203 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9204 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9205 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009206 }
9207
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009208 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009209 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009210 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009211 mApp.getSystemService(AppOpsManager.class)
9212 .checkPackage(Binder.getCallingUid(), callingPackage);
9213
Jordan Liu1e142fc2019-04-22 15:10:43 -07009214 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009215 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009216 try {
9217 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009218 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009219 } catch (SecurityException e) {
9220 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9221 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009222 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009223 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009224 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009225 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009226 }
sandeepjsb6c87872021-09-27 15:34:44 +00009227 // checking compatibility, if calling app's target SDK is T and beyond.
9228 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9229 Binder.getCallingUid())) {
9230 isIccIdAccessRestricted = true;
9231 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009232 final long identity = Binder.clearCallingIdentity();
9233 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009234 UiccController uiccController = UiccController.getInstance();
9235 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009236 if (hasReadPermission) {
9237 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009238 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009239
9240 // Remove private info if the caller doesn't have access
9241 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9242 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009243 //setting the value after compatibility check
9244 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009245 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9246 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009247 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009248 if (card == null) {
9249 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009250 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009251 continue;
9252 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009253 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9254 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009255 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009256 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009257 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009258 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9259 for (UiccPortInfo portInfo : portInfos) {
9260 UiccPort port = uiccController.getUiccPortForSlot(
9261 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9262 if (port == null) {
9263 // assume no access if port is null
9264 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9265 continue;
9266 }
9267 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9268 uiccPortInfos.add(portInfo);
9269 } else {
9270 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9271 }
9272 }
9273 filteredInfos.add(new UiccCardInfo(
9274 cardInfo.isEuicc(),
9275 cardInfo.getCardId(),
9276 null,
9277 cardInfo.getPhysicalSlotIndex(),
9278 cardInfo.isRemovable(),
9279 cardInfo.isMultipleEnabledProfilesSupported(),
9280 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009281 }
9282 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009283 } finally {
9284 Binder.restoreCallingIdentity(identity);
9285 }
9286 }
9287
sandeepjsb6c87872021-09-27 15:34:44 +00009288 /**
9289 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9290 * generally private and require carrier privileges to view.
9291 *
9292 * @hide
9293 */
9294 @NonNull
9295 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9296 List<UiccPortInfo> portinfo = new ArrayList<>();
9297 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9298 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9299 }
9300 return new UiccCardInfo(
9301 cardInfo.isEuicc(),
9302 cardInfo.getCardId(),
9303 null,
9304 cardInfo.getPhysicalSlotIndex(),
9305 cardInfo.isRemovable(),
9306 cardInfo.isMultipleEnabledProfilesSupported(),
9307 portinfo
9308 );
9309 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009310
sandeepjsb6c87872021-09-27 15:34:44 +00009311 /**
9312 * @hide
9313 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9314 * These values are generally private and require carrier privileges to view.
9315 */
9316 @NonNull
9317 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9318 return new UiccPortInfo(
9319 UiccPortInfo.ICCID_REDACTED,
9320 portInfo.getPortIndex(),
9321 portInfo.getLogicalSlotIndex(),
9322 portInfo.isActive()
9323 );
9324 }
9325 @Override
9326 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009327 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009328 mApp.getSystemService(AppOpsManager.class)
9329 .checkPackage(Binder.getCallingUid(), callingPackage);
9330
sandeepjsb6c87872021-09-27 15:34:44 +00009331 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009332
Aman Guptaf3c90b32022-03-17 04:54:16 +00009333 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9334 // we are reading iccId which is PII data.
9335 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009336
9337 // checking compatibility, if calling app's target SDK is T and beyond.
9338 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9339 Binder.getCallingUid())) {
9340 isLogicalSlotAccessRestricted = true;
9341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009342 final long identity = Binder.clearCallingIdentity();
9343 try {
9344 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009345 if (slots == null || slots.length == 0) {
9346 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009347 return null;
9348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009349 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9350 for (int i = 0; i < slots.length; i++) {
9351 UiccSlot slot = slots[i];
9352 if (slot == null) {
9353 continue;
9354 }
9355
Jordan Liu7be7e652019-05-06 18:55:02 +00009356 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009357 UiccCard card = slot.getUiccCard();
9358 if (card != null) {
9359 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009360 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009361 cardId = slot.getEid();
9362 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009363 // If cardId is null, use iccId of default port as cardId.
9364 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009366 }
9367
Jordan Liu857451f2019-05-09 16:35:35 -07009368 if (cardId != null) {
9369 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9370 // if cardId is an EID, it's all digits so this is fine
9371 cardId = IccUtils.stripTrailingFs(cardId);
9372 }
9373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009374 int cardState = 0;
9375 switch (slot.getCardState()) {
9376 case CARDSTATE_ABSENT:
9377 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9378 break;
9379 case CARDSTATE_PRESENT:
9380 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9381 break;
9382 case CARDSTATE_ERROR:
9383 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9384 break;
9385 case CARDSTATE_RESTRICTED:
9386 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9387 break;
9388 default:
9389 break;
9390
9391 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009392 List<UiccPortInfo> portInfos = new ArrayList<>();
9393 int[] portIndexes = slot.getPortList();
9394 for (int portIdx : portIndexes) {
9395 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009396 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009397 portInfos.add(new UiccPortInfo(iccId, portIdx,
9398 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009400 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009401 slot.isEuicc(),
9402 cardId,
9403 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009404 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009405 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009406 //setting the value after compatibility check
9407 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009408 }
9409 return infos;
9410 } finally {
9411 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009412 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009413 }
9414
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009415 /* Returns null if doesn't have read permission or carrier privilege access. */
9416 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9417 boolean hasReadPermission) {
9418 String iccId = slot.getIccId(portIndex);
9419 if (hasReadPermission) { // if has read permission
9420 return iccId;
9421 } else {
9422 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9423 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9424 // if no read permission, checking carrier privilege access
9425 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9426 return iccId;
9427 }
9428 }
9429 }
9430 // No read permission or carrier privilege access.
9431 return UiccPortInfo.ICCID_REDACTED;
9432 }
9433
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009434 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009435 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009436 public boolean switchSlots(int[] physicalSlots) {
9437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009438
9439 final long identity = Binder.clearCallingIdentity();
9440 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009441 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9442 for (int i = 0; i < physicalSlots.length; i++) {
9443 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9444 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9445 physicalSlots[i], i));
9446 }
9447 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009448 } finally {
9449 Binder.restoreCallingIdentity(identity);
9450 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009451 }
Jack Yu4c988042018-02-27 15:30:01 -08009452
9453 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009454 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9455 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9456 enforceModifyPermission();
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009460 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009461 } finally {
9462 Binder.restoreCallingIdentity(identity);
9463 }
9464 }
9465
9466 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009467 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009468 final long identity = Binder.clearCallingIdentity();
9469 try {
9470 return UiccController.getInstance().getCardIdForDefaultEuicc();
9471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
9475
Pengquan Meng85728fb2018-03-12 16:31:21 -07009476 /**
goneil47ffb6e2018-04-06 15:40:58 -07009477 * A test API to reload the UICC profile.
9478 *
9479 * <p>Requires that the calling app has permission
9480 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9481 * @hide
9482 */
9483 @Override
9484 public void refreshUiccProfile(int subId) {
9485 enforceModifyPermission();
9486
9487 final long identity = Binder.clearCallingIdentity();
9488 try {
9489 Phone phone = getPhone(subId);
9490 if (phone == null) {
9491 return;
9492 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009493 UiccPort uiccPort = phone.getUiccPort();
9494 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009495 return;
9496 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009497 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009498 if (uiccProfile == null) {
9499 return;
9500 }
9501 uiccProfile.refresh();
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505 }
9506
9507 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009508 * Returns false if the mobile data is disabled by default, otherwise return true.
9509 */
9510 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009511 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009512 }
9513
9514 /**
9515 * Returns true if the data roaming is enabled by default, i.e the system property
9516 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9517 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9518 */
9519 private boolean getDefaultDataRoamingEnabled(int subId) {
9520 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009521 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009522 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009523 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9524 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9525 return isDataRoamingEnabled;
9526 }
9527
9528 /**
9529 * Returns the default network type for the given {@code subId}, if the default network type is
9530 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9531 */
9532 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009533 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009534 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009535 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9536 return list.get(phoneId);
9537 }
9538 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009539 }
fionaxua13278b2018-03-21 00:08:13 -07009540
9541 @Override
9542 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009543 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 final Phone phone = getPhone(subId);
9549 if (phone == null) {
9550 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9551 return;
9552 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009553 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9554 if (cpt != null) {
9555 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9556 }
9557 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009558 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9559 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009560 if (carrierPrivilegeRules == null) {
9561 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9562 } else {
9563 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009565 } finally {
9566 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009567 }
fionaxua13278b2018-03-21 00:08:13 -07009568 }
9569
9570 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009571 public void setCarrierServicePackageOverride(
9572 int subId, String carrierServicePackage, String callingPackage) {
9573 TelephonyPermissions.enforceShellOnly(
9574 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9575
Benedict Wong66477622023-02-03 23:30:57 +00009576 final long identity = Binder.clearCallingIdentity();
9577 try {
9578 final Phone phone = getPhone(subId);
9579 if (phone == null || phone.getSubId() != subId) {
9580 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9581 throw new IllegalArgumentException("No phone for subid");
9582 }
9583 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9584 if (cpt == null) {
9585 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9586 throw new IllegalStateException("No CPT for phone");
9587 }
9588 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9589 } finally {
9590 Binder.restoreCallingIdentity(identity);
9591 }
9592 }
9593
9594 @Override
fionaxua13278b2018-03-21 00:08:13 -07009595 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009596 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009597
9598 final long identity = Binder.clearCallingIdentity();
9599 try {
9600 final Phone phone = getPhone(subId);
9601 if (phone == null) {
9602 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9603 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9604 }
9605 return phone.getCarrierIdListVersion();
9606 } finally {
9607 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009608 }
fionaxua13278b2018-03-21 00:08:13 -07009609 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009610
9611 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009612 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9613 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009615 mApp, subId, callingPackage, callingFeatureId,
9616 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009617 return -1;
9618 }
9619
9620 final long identity = Binder.clearCallingIdentity();
9621 try {
9622 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009627
9628 @Override
9629 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009630 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009631 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009632 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009633
9634 final long identity = Binder.clearCallingIdentity();
9635 try {
9636 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9637 } finally {
9638 Binder.restoreCallingIdentity(identity);
9639 }
9640 }
9641
9642 @Override
9643 public boolean setCdmaRoamingMode(int subId, int mode) {
9644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9645 mApp, subId, "setCdmaRoamingMode");
9646
9647 final long identity = Binder.clearCallingIdentity();
9648 try {
9649 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
9655 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009656 public int getCdmaSubscriptionMode(int subId) {
9657 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009659 mApp, subId, "getCdmaSubscriptionMode");
9660
9661 final long identity = Binder.clearCallingIdentity();
9662 try {
9663 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9664 } finally {
9665 Binder.restoreCallingIdentity(identity);
9666 }
9667 }
9668
9669 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009670 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9672 mApp, subId, "setCdmaSubscriptionMode");
9673
9674 final long identity = Binder.clearCallingIdentity();
9675 try {
9676 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9677 } finally {
9678 Binder.restoreCallingIdentity(identity);
9679 }
9680 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009681
sqianc5eccab2018-10-19 18:46:41 -07009682 @Override
sqian8c685422019-02-22 15:55:18 -08009683 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009684 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009686 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9687 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009688 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9689 }
9690 final long identity = Binder.clearCallingIdentity();
9691 try {
sqian854d44b2018-12-12 16:48:18 -08009692 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9693 for (Phone phone: PhoneFactory.getPhones()) {
9694 if (phone.getEmergencyNumberTracker() != null
9695 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9696 emergencyNumberListInternal.put(
9697 phone.getSubId(),
9698 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9699 }
sqian11b7a0e2018-12-05 18:48:28 -08009700 }
sqian854d44b2018-12-12 16:48:18 -08009701 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009702 } finally {
9703 Binder.restoreCallingIdentity(identity);
9704 }
sqianc5eccab2018-10-19 18:46:41 -07009705 }
9706
9707 @Override
sqian8c685422019-02-22 15:55:18 -08009708 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009709 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009710 if (!exactMatch) {
9711 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009712 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009713 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009714 }
9715 final long identity = Binder.clearCallingIdentity();
9716 try {
sqian854d44b2018-12-12 16:48:18 -08009717 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009718 //Note: we ignore passed in param exactMatch. We can remove it once
9719 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009720 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009721 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009722 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009723 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009724 }
sqian11b7a0e2018-12-05 18:48:28 -08009725 }
9726 return false;
9727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
9730 }
9731
sqianf4ca7ed2019-01-15 18:32:07 -08009732 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009733 * Start emergency callback mode for GsmCdmaPhone for testing.
9734 */
9735 @Override
9736 public void startEmergencyCallbackMode() {
9737 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9738 "startEmergencyCallbackMode");
9739 enforceModifyPermission();
9740 final long identity = Binder.clearCallingIdentity();
9741 try {
9742 for (Phone phone : PhoneFactory.getPhones()) {
9743 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9744 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9745 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9746 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9747 gsmCdmaPhone.obtainMessage(
9748 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9749 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9750 }
9751 }
9752 } finally {
9753 Binder.restoreCallingIdentity(identity);
9754 }
9755 }
9756
9757 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009758 * Update emergency number list for test mode.
9759 */
9760 @Override
9761 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9763 "updateEmergencyNumberListTestMode");
9764
9765 final long identity = Binder.clearCallingIdentity();
9766 try {
9767 for (Phone phone: PhoneFactory.getPhones()) {
9768 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9769 if (tracker != null) {
9770 tracker.executeEmergencyNumberTestModeCommand(action, num);
9771 }
9772 }
9773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
9777
9778 /**
9779 * Get the full emergency number list for test mode.
9780 */
9781 @Override
9782 public List<String> getEmergencyNumberListTestMode() {
9783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9784 "getEmergencyNumberListTestMode");
9785
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
9788 Set<String> emergencyNumbers = new HashSet<>();
9789 for (Phone phone: PhoneFactory.getPhones()) {
9790 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9791 if (tracker != null) {
9792 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9793 emergencyNumbers.add(num.getNumber());
9794 }
9795 }
9796 }
9797 return new ArrayList<>(emergencyNumbers);
9798 } finally {
9799 Binder.restoreCallingIdentity(identity);
9800 }
9801 }
9802
chen xud6b45bd2018-10-30 22:27:10 -07009803 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009804 public int getEmergencyNumberDbVersion(int subId) {
9805 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9806
9807 final long identity = Binder.clearCallingIdentity();
9808 try {
9809 final Phone phone = getPhone(subId);
9810 if (phone == null) {
9811 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9812 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9813 }
9814 return phone.getEmergencyNumberDbVersion();
9815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 }
9819
9820 @Override
9821 public void notifyOtaEmergencyNumberDbInstalled() {
9822 enforceModifyPermission();
9823
9824 final long identity = Binder.clearCallingIdentity();
9825 try {
9826 for (Phone phone: PhoneFactory.getPhones()) {
9827 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9828 if (tracker != null) {
9829 tracker.updateOtaEmergencyNumberDatabase();
9830 }
9831 }
9832 } finally {
9833 Binder.restoreCallingIdentity(identity);
9834 }
9835 }
9836
9837 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009838 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009839 enforceActiveEmergencySessionPermission();
9840
9841 final long identity = Binder.clearCallingIdentity();
9842 try {
9843 for (Phone phone: PhoneFactory.getPhones()) {
9844 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9845 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009846 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9847 }
9848 }
9849 } finally {
9850 Binder.restoreCallingIdentity(identity);
9851 }
9852 }
9853
9854 @Override
9855 public void resetOtaEmergencyNumberDbFilePath() {
9856 enforceActiveEmergencySessionPermission();
9857
9858 final long identity = Binder.clearCallingIdentity();
9859 try {
9860 for (Phone phone: PhoneFactory.getPhones()) {
9861 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9862 if (tracker != null) {
9863 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009864 }
9865 }
9866 } finally {
9867 Binder.restoreCallingIdentity(identity);
9868 }
9869 }
9870
9871 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009872 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9873 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9874 Phone phone = getPhone(subId);
9875 if (phone == null) {
9876 return null;
9877 }
9878 final long identity = Binder.clearCallingIdentity();
9879 try {
9880 UiccProfile profile = UiccController.getInstance()
9881 .getUiccProfileForPhone(phone.getPhoneId());
9882 if (profile != null) {
9883 return profile.getCertsFromCarrierPrivilegeAccessRules();
9884 }
9885 } finally {
9886 Binder.restoreCallingIdentity(identity);
9887 }
9888 return null;
9889 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009890
9891 /**
9892 * Enable or disable a modem stack.
9893 */
9894 @Override
9895 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9896 enforceModifyPermission();
9897
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
9900 Phone phone = PhoneFactory.getPhone(slotIndex);
9901 if (phone == null) {
9902 return false;
9903 } else {
9904 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9905 }
9906 } finally {
9907 Binder.restoreCallingIdentity(identity);
9908 }
9909 }
Michelecea4cf22018-12-21 15:00:11 -08009910
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009911 /**
9912 * Whether a modem stack is enabled or not.
9913 */
9914 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009915 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9916 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009917 Phone phone = PhoneFactory.getPhone(slotIndex);
9918 if (phone == null) return false;
9919
9920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009921 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9922 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009923 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9924 }
9925
9926 final long identity = Binder.clearCallingIdentity();
9927 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009928 try {
9929 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9930 } catch (NoSuchElementException ex) {
9931 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9932 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009933 } finally {
9934 Binder.restoreCallingIdentity(identity);
9935 }
9936 }
9937
Michelecea4cf22018-12-21 15:00:11 -08009938 @Override
Michele0ea7d782019-03-19 14:58:42 -07009939 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009940 enforceModifyPermission();
9941
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009945 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009946 .commit();
9947 } finally {
9948 Binder.restoreCallingIdentity(identity);
9949 }
9950 }
9951
9952 @Override
Michele0ea7d782019-03-19 14:58:42 -07009953 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009954 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009956 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9957 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009958 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009959 }
Michelecea4cf22018-12-21 15:00:11 -08009960
9961 final long identity = Binder.clearCallingIdentity();
9962 try {
Michele0ea7d782019-03-19 14:58:42 -07009963 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009964 } finally {
9965 Binder.restoreCallingIdentity(identity);
9966 }
9967 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009968
Michele0ea7d782019-03-19 14:58:42 -07009969 @TelephonyManager.IsMultiSimSupportedResult
9970 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009971 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9972 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9973 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009974 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9975 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009976 }
9977 // Check if the hardware supports multisim functionality. If usage of multisim is not
9978 // supported by the modem, indicate that it is restricted.
9979 PhoneCapability staticCapability =
9980 mPhoneConfigurationManager.getStaticPhoneCapability();
9981 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009982 loge("isMultiSimSupportedInternal: no static configuration available");
9983 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009984 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009985 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009986 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9987 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009988 }
9989 // Check if support of multiple SIMs is restricted by carrier
9990 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009991 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009992 }
9993
Michele0ea7d782019-03-19 14:58:42 -07009994 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009995 }
9996
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009997 /**
9998 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009999 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10000 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10001 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010002 * @param numOfSims number of active sims we want to switch to
10003 */
10004 @Override
10005 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010006 if (numOfSims == 1) {
10007 enforceModifyPermission();
10008 } else {
10009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10010 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10011 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010012 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010013
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010014 try {
Michele30b57b22019-03-01 12:01:14 -080010015 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010016 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010017 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10018 return;
10019 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010020 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 }
10025
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010026 @Override
10027 public boolean isApplicationOnUicc(int subId, int appType) {
10028 enforceReadPrivilegedPermission("isApplicationOnUicc");
10029 Phone phone = getPhone(subId);
10030 if (phone == null) {
10031 return false;
10032 }
10033 final long identity = Binder.clearCallingIdentity();
10034 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010035 UiccPort uiccPort = phone.getUiccPort();
10036 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010037 return false;
10038 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010039 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010040 if (uiccProfile == null) {
10041 return false;
10042 }
10043 if (TelephonyManager.APPTYPE_SIM <= appType
10044 && appType <= TelephonyManager.APPTYPE_ISIM) {
10045 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10046 }
10047 return false;
10048 } finally {
10049 Binder.restoreCallingIdentity(identity);
10050 }
10051 }
10052
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010053 /**
chen xub4baa772019-04-03 10:23:41 -070010054 * Get whether making changes to modem configurations will trigger reboot.
10055 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010056 */
10057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010058 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10059 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010061 mApp, subId, callingPackage, callingFeatureId,
10062 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010063 return false;
10064 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010065 final long identity = Binder.clearCallingIdentity();
10066 try {
10067 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10068 } finally {
10069 Binder.restoreCallingIdentity(identity);
10070 }
10071 }
10072
Nathan Harold29f5f052019-02-15 13:41:57 -080010073 private void updateModemStateMetrics() {
10074 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10075 // TODO: check the state for each modem if the api is ready.
10076 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10077 }
10078
Pengquan Meng3889a572019-01-23 11:16:29 -080010079 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010080 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010081 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010082 // Verify that the callingPackage belongs to the calling UID
10083 mApp.getSystemService(AppOpsManager.class)
10084 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010085 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010086 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010087 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010088 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10089 if (slotInfos != null) {
10090 for (int i = 0; i < slotInfos.length; i++) {
10091 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10092 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10093 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10094 portInfo.getLogicalSlotIndex()));
10095 }
10096 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010097 }
10098 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010099 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010100 } finally {
10101 Binder.restoreCallingIdentity(identity);
10102 }
10103 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010104
10105 /**
10106 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010107 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010108 */
jimsunf9ec1622022-09-13 21:18:43 +080010109 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010110 @Override
10111 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010112 return getHalVersion(HAL_SERVICE_RADIO);
10113 }
10114
10115 /**
10116 * Get the HAL Version of a specific service
10117 */
10118 @Override
10119 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010120 Phone phone = getDefaultPhone();
10121 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010122 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010123 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10124 return hv.major * 100 + hv.minor;
10125 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010126
10127 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010128 * Get the current calling package name.
10129 * @return the current calling package name
10130 */
10131 @Override
10132 public String getCurrentPackageName() {
10133 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10134 }
10135
10136 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010137 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10138 * corresponding network requests on a subId.
10139 *
10140 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010141 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010142 * 2) APN is un-metered for this subscription, or
10143 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010144 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010145 *
10146 * @return whether data is allowed for a apn type.
10147 *
10148 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010149 */
10150 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010151 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010152 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10153 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010154
10155 // Now that all security checks passes, perform the operation as ourselves.
10156 final long identity = Binder.clearCallingIdentity();
10157 try {
10158 Phone phone = getPhone(subId);
10159 if (phone == null) return false;
10160
Jack Yu27422a52022-03-21 10:38:05 -070010161 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010162 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010163 isMetered = phone.getDataNetworkController().getDataConfigManager()
10164 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10165 phone.getServiceState().getDataRoaming());
10166 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010167 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010168 } finally {
10169 Binder.restoreCallingIdentity(identity);
10170 }
10171 }
10172
10173 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010174 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010175 enforceReadPrivilegedPermission("isApnMetered");
10176
10177 // Now that all security checks passes, perform the operation as ourselves.
10178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 Phone phone = getPhone(subId);
10181 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010182 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10183 DataUtils.apnTypeToNetworkCapability(apnType),
10184 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010185 } finally {
10186 Binder.restoreCallingIdentity(identity);
10187 }
10188 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010189
10190 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010191 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10192 int subscriptionId, IBooleanConsumer resultCallback) {
10193 enforceModifyPermission();
10194 long token = Binder.clearCallingIdentity();
10195 try {
10196 Phone phone = getPhone(subscriptionId);
10197 if (phone == null) {
10198 try {
10199 if (resultCallback != null) {
10200 resultCallback.accept(false);
10201 }
10202 } catch (RemoteException e) {
10203 // ignore
10204 }
10205 return;
10206 }
10207 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10208 Pair.create(specifiers, (x) -> {
10209 try {
10210 if (resultCallback != null) {
10211 resultCallback.accept(x);
10212 }
10213 } catch (RemoteException e) {
10214 // ignore
10215 }
10216 });
10217 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10218 } finally {
10219 Binder.restoreCallingIdentity(token);
10220 }
10221 }
10222
10223 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010224 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10225 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010226 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010227 mApp, subId, "getSystemSelectionChannels");
10228 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10229 final long identity = Binder.clearCallingIdentity();
10230 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010231 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10232 if (result instanceof IllegalStateException) {
10233 throw (IllegalStateException) result;
10234 }
10235 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010236 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10237 return specifiers;
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010244 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010245 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010246 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010247 }
10248
10249 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010250 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10251 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010252 if (callingPackage == null) {
10253 callingPackage = getCurrentPackageName();
10254 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010255 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10256 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010257 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10258 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010259 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10260 }
10261 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10262 Intent intent = new Intent();
10263 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10264 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10265 // Bring up choose default SMS subscription dialog right now
10266 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10267 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10268 mApp.startActivity(intent);
10269 }
chen xud5ca2d52019-05-28 15:20:57 -070010270
10271 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010272 public void showSwitchToManagedProfileDialog() {
10273 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010274 try {
10275 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10276 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10277 // for work telephony.
10278 Intent intent = new Intent(Intent.ACTION_SENDTO);
10279 intent.setData(Uri.parse("smsto:"));
10280 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10281 mApp.startActivity(intent);
10282 } catch (ActivityNotFoundException e) {
10283 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10284 Intent intent = new Intent();
10285 intent.setClass(mApp, ErrorDialogActivity.class);
10286 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10287 mApp.startActivity(intent);
10288 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010289 }
10290
10291 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010292 public String getMmsUAProfUrl(int subId) {
10293 //TODO investigate if this API should require proper permission check in R b/133791609
10294 final long identity = Binder.clearCallingIdentity();
10295 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010296 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10297 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10298 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10299 return carrierUAProfUrl;
10300 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010301 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10302 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
10306 }
10307
10308 @Override
10309 public String getMmsUserAgent(int subId) {
10310 //TODO investigate if this API should require proper permission check in R b/133791609
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010313 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10314 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10315 if (!TextUtils.isEmpty(carrierUserAgent)) {
10316 return carrierUserAgent;
10317 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010318 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10319 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010320 } finally {
10321 Binder.restoreCallingIdentity(identity);
10322 }
10323 }
Jack Yub07d4972019-05-28 16:12:25 -070010324
10325 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010326 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10327 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010328
Jack Yub07d4972019-05-28 16:12:25 -070010329 final long identity = Binder.clearCallingIdentity();
10330 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010331 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010332 if (phone == null) return false;
10333
Ling Maf188d502022-09-16 15:22:36 -070010334 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010335 } finally {
10336 Binder.restoreCallingIdentity(identity);
10337 }
10338 }
10339
10340 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010341 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010342 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010343 enforceModifyPermission();
10344
changbettyd5c246e2019-12-24 15:40:37 +080010345 final long identity = Binder.clearCallingIdentity();
10346 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010347 Phone phone = getPhone(subscriptionId);
10348 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010349
Ling Maf188d502022-09-16 15:22:36 -070010350 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010351 } finally {
10352 Binder.restoreCallingIdentity(identity);
10353 }
10354 }
10355
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010356 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010357 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010358 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10359 * otherwise.
10360 */
10361 @Override
10362 public void setCepEnabled(boolean isCepEnabled) {
10363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10364
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
10367 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10368 for (Phone phone : PhoneFactory.getPhones()) {
10369 Phone defaultPhone = phone.getImsPhone();
10370 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10371 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10372 ImsPhoneCallTracker imsPhoneCallTracker =
10373 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10374 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10375 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10376 + imsPhone.getMsisdn());
10377 }
10378 }
10379 } finally {
10380 Binder.restoreCallingIdentity(identity);
10381 }
10382 }
allenwtsu46dcc572020-01-08 18:24:03 +080010383
10384 /**
10385 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10386 *
10387 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10388 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10389 * before being read.
10390 */
10391 @Override
10392 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10393 isCompressed) {
10394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10395 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10397 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10398 }
10399 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010400 // ProvisioningManager can not handle ServiceSpecificException.
10401 // Throw the IllegalStateException and annotate ProvisioningManager.
10402 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010403 }
10404
10405 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010406 try {
Hui Wang761a6682020-10-31 05:12:53 +000010407 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10408 } finally {
10409 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010410 }
10411 }
zoey chene02881a2019-12-30 16:11:23 +080010412
10413 @Override
10414 public boolean isIccLockEnabled(int subId) {
10415 enforceReadPrivilegedPermission("isIccLockEnabled");
10416
10417 // Now that all security checks passes, perform the operation as ourselves.
10418 final long identity = Binder.clearCallingIdentity();
10419 try {
10420 Phone phone = getPhone(subId);
10421 if (phone != null && phone.getIccCard() != null) {
10422 return phone.getIccCard().getIccLockEnabled();
10423 } else {
10424 return false;
10425 }
10426 } finally {
10427 Binder.restoreCallingIdentity(identity);
10428 }
10429 }
10430
10431 /**
10432 * Set the ICC pin lock enabled or disabled.
10433 *
10434 * @return an integer representing the status of IccLock enabled or disabled in the following
10435 * three cases:
10436 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10437 * successfully.
10438 * - Positive number and zero for remaining password attempts.
10439 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10440 *
10441 */
10442 @Override
10443 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10444 enforceModifyPermission();
10445
10446 Phone phone = getPhone(subId);
10447 if (phone == null) {
10448 return 0;
10449 }
10450 // Now that all security checks passes, perform the operation as ourselves.
10451 final long identity = Binder.clearCallingIdentity();
10452 try {
10453 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10454 new Pair<Boolean, String>(enabled, password), phone, null);
10455 return attemptsRemaining;
10456
10457 } catch (Exception e) {
10458 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10459 } finally {
10460 Binder.restoreCallingIdentity(identity);
10461 }
10462 return 0;
10463 }
10464
10465 /**
10466 * Change the ICC password used in ICC pin lock.
10467 *
10468 * @return an integer representing the status of IccLock changed in the following three cases:
10469 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10470 * - Positive number and zero for remaining password attempts.
10471 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10472 *
10473 */
10474 @Override
10475 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10476 enforceModifyPermission();
10477
10478 Phone phone = getPhone(subId);
10479 if (phone == null) {
10480 return 0;
10481 }
10482 // Now that all security checks passes, perform the operation as ourselves.
10483 final long identity = Binder.clearCallingIdentity();
10484 try {
10485 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10486 new Pair<String, String>(oldPassword, newPassword), phone, null);
10487 return attemptsRemaining;
10488
10489 } catch (Exception e) {
10490 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 return 0;
10495 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010496
10497 /**
10498 * Request for receiving user activity notification
10499 */
10500 @Override
10501 public void requestUserActivityNotification() {
10502 if (!mNotifyUserActivity.get()
10503 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10504 mNotifyUserActivity.set(true);
10505 }
10506 }
10507
10508 /**
10509 * Called when userActivity is signalled in the power manager.
10510 * This is safe to call from any thread, with any window manager locks held or not.
10511 */
10512 @Override
10513 public void userActivity() {
10514 // ***************************************
10515 // * Inherited from PhoneWindowManager *
10516 // ***************************************
10517 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10518 // WITH ITS LOCKS HELD.
10519 //
10520 // This code must be VERY careful about the locks
10521 // it acquires.
10522 // In fact, the current code acquires way too many,
10523 // and probably has lurking deadlocks.
10524
10525 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10526 throw new SecurityException("Only the OS may call notifyUserActivity()");
10527 }
10528
10529 if (mNotifyUserActivity.getAndSet(false)) {
10530 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10531 USER_ACTIVITY_NOTIFICATION_DELAY);
10532 }
10533 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010534
10535 @Override
10536 public boolean canConnectTo5GInDsdsMode() {
10537 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10538 }
Jack Yud10cdd42020-09-28 20:28:01 -070010539
10540 @Override
10541 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10542 String callingFeatureId) {
10543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10544 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10545 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10546 }
10547
10548 Phone phone = getPhone(subId);
10549 if (phone == null) {
10550 throw new RuntimeException("phone is not available");
10551 }
10552 // Now that all security checks passes, perform the operation as ourselves.
10553 final long identity = Binder.clearCallingIdentity();
10554 try {
10555 return phone.getEquivalentHomePlmns();
10556 } finally {
10557 Binder.restoreCallingIdentity(identity);
10558 }
10559 }
Daniel Bright59e67312020-11-13 11:49:37 -080010560
10561 @Override
10562 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010563 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10564 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010565 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010566 if (radioInterfaceCapabilities == null) {
10567 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010568 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010569 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010570 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010571
Hui Wang641e81c2020-10-12 12:14:23 -070010572 @Override
10573 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10574 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010575 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10576 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10577 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10578 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10579 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010580 if (DBG) {
10581 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10582 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10583 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10584 }
10585
10586 if (!SubscriptionManager.isValidSubscriptionId(subId)
10587 || appType < TelephonyManager.APPTYPE_UNKNOWN
10588 || appType > TelephonyManager.APPTYPE_ISIM
10589 || nafUrl == null || securityProtocol == null || callback == null) {
10590 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10591 if (callback != null) {
10592 try {
10593 callback.onAuthenticationFailure(
10594 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10595 } catch (RemoteException exception) {
10596 log("Fail to notify onAuthenticationFailure due to " + exception);
10597 }
10598 return;
10599 }
10600 }
10601
10602 final long token = Binder.clearCallingIdentity();
10603 try {
10604 getGbaManager(subId).bootstrapAuthenticationRequest(
10605 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010606 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010607 } finally {
10608 Binder.restoreCallingIdentity(token);
10609 }
10610 }
10611
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010612 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010613 * Attempts to set the radio power state for all phones for thermal reason.
10614 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010615 * requested radio power state will actually be set. See {@link
10616 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10617 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010618 * @param enable {@code true} if trying to turn radio on.
10619 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10620 * false}.
10621 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010622 private boolean setRadioPowerForThermal(boolean enable) {
10623 boolean isPhoneAvailable = false;
10624 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10625 Phone phone = PhoneFactory.getPhone(i);
10626 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010627 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010628 isPhoneAvailable = true;
10629 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010630 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010631
10632 // return true if successfully informed the phone object about the thermal radio power
10633 // request.
10634 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010635 }
10636
10637 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010638 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010639 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10640 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10641 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10642 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10643 throw new IllegalArgumentException("modem does not support data throttling");
10644 }
10645
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010646 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10647 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010648 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010649 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10650 }
10651
Sarah Chinecc78c42022-03-31 21:16:48 -070010652 setDataEnabledForReason(
10653 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010654
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010655 if (isDataThrottlingSupported) {
10656 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010657 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010658 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10659 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10660 } else if (thermalMitigationResult
10661 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010662 log("Modem likely does not support data throttling on secondary carrier. Data " +
10663 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10664 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010665 }
10666 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010667 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010668
10669 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010670 }
10671
Jack Nudelman644b91a2021-03-12 14:09:48 -080010672 private static List<String> getThermalMitigationAllowlist(Context context) {
10673 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10674 for (String pckg : context.getResources()
10675 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10676 sThermalMitigationAllowlistedPackages.add(pckg);
10677 }
10678 }
10679
10680 return sThermalMitigationAllowlistedPackages;
10681 }
10682
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010683 private boolean isAnyPhoneInEmergencyState() {
10684 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10685 if (tm.isInEmergencyCall()) {
10686 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10687 return true;
10688 }
10689 for (Phone phone : PhoneFactory.getPhones()) {
10690 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10691 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010692 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10693 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010694 return true;
10695 }
10696 }
10697
10698 return false;
10699 }
10700
Jack Nudelman644b91a2021-03-12 14:09:48 -080010701 /**
10702 * Used by shell commands to add an authorized package name for thermal mitigation.
10703 * @param packageName name of package to be allowlisted
10704 * @param context
10705 */
10706 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10707 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10708 sThermalMitigationAllowlistedPackages.add(packageName);
10709 }
10710
10711 /**
10712 * Used by shell commands to remove an authorized package name for thermal mitigation.
10713 * @param packageName name of package to remove from allowlist
10714 * @param context
10715 */
10716 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10717 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10718 sThermalMitigationAllowlistedPackages.remove(packageName);
10719 }
10720
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010721 /**
10722 * Thermal mitigation request to control functionalities at modem.
10723 *
10724 * @param subId the id of the subscription.
10725 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010726 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010727 *
10728 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10729 */
10730 @Override
10731 @ThermalMitigationResult
10732 public int sendThermalMitigationRequest(
10733 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010734 ThermalMitigationRequest thermalMitigationRequest,
10735 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010736 enforceModifyPermission();
10737
Jack Nudelman644b91a2021-03-12 14:09:48 -080010738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10739 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10740 .contains(callingPackage)) {
10741 throw new SecurityException("Calling package must be configured in the device config. "
10742 + "calling package: " + callingPackage);
10743 }
10744
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10746 final long identity = Binder.clearCallingIdentity();
10747
10748 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10749 try {
10750 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10751 switch (thermalMitigationAction) {
10752 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10753 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010754 handleDataThrottlingRequest(subId,
10755 thermalMitigationRequest.getDataThrottlingRequest(),
10756 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010757 break;
10758 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10759 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10760 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10761 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10762 }
10763
10764 // Ensure that radio is on. If not able to power on due to phone being
10765 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010766 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010767 thermalMitigationResult =
10768 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10769 break;
10770 }
10771
10772 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010773 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010774 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10775 break;
10776 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10777 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10778 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10779 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10780 }
10781
10782 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10783 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010784 Phone phone = getPhone(subId);
10785 if (phone == null) {
10786 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010787 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010788 break;
10789 }
10790
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010791 TelephonyConnectionService service =
10792 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010793 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010794 Log.e(LOG_TAG, "An emergency call is pending");
10795 thermalMitigationResult =
10796 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10797 break;
10798 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010799 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010800 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010801 break;
10802 }
10803 } else {
10804 thermalMitigationResult =
10805 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10806 break;
10807 }
10808
10809 // Turn radio off. If not able to power off due to phone being unavailable,
10810 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010811 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010812 thermalMitigationResult =
10813 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10814 break;
10815 }
10816 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010817 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010818 break;
10819 default:
10820 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10821 + "not exist. Requested action: " + thermalMitigationAction);
10822 }
10823 } catch (IllegalArgumentException e) {
10824 throw e;
10825 } catch (Exception e) {
10826 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10827 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831
10832 if (DBG) {
10833 log("thermalMitigationRequest returning with thermalMitigationResult: "
10834 + thermalMitigationResult);
10835 }
10836
10837 return thermalMitigationResult;
10838 }
Hui Wang641e81c2020-10-12 12:14:23 -070010839
10840 /**
10841 * Set the GbaService Package Name that Telephony will bind to.
10842 *
10843 * @param subId The sim that the GbaService is associated with.
10844 * @param packageName The name of the package to be replaced with.
10845 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10846 */
10847 @Override
10848 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10849 enforceModifyPermission();
10850
10851 final long identity = Binder.clearCallingIdentity();
10852 try {
10853 return getGbaManager(subId).overrideServicePackage(packageName);
10854 } finally {
10855 Binder.restoreCallingIdentity(identity);
10856 }
10857 }
10858
10859 /**
10860 * Return the package name of the currently bound GbaService.
10861 *
10862 * @param subId The sim that the GbaService is associated with.
10863 * @return the package name of the GbaService configuration, null if GBA is not supported.
10864 */
10865 @Override
10866 public String getBoundGbaService(int subId) {
10867 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10868
10869 final long identity = Binder.clearCallingIdentity();
10870 try {
10871 return getGbaManager(subId).getServicePackage();
10872 } finally {
10873 Binder.restoreCallingIdentity(identity);
10874 }
10875 }
10876
10877 /**
10878 * Set the release time for telephony to unbind GbaService.
10879 *
10880 * @param subId The sim that the GbaService is associated with.
10881 * @param interval The release time to unbind GbaService by millisecond.
10882 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10883 */
10884 @Override
10885 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10886 enforceModifyPermission();
10887
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 return getGbaManager(subId).overrideReleaseTime(interval);
10891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
10895
10896 /**
10897 * Return the release time for telephony to unbind GbaService.
10898 *
10899 * @param subId The sim that the GbaService is associated with.
10900 * @return The release time to unbind GbaService by millisecond.
10901 */
10902 @Override
10903 public int getGbaReleaseTime(int subId) {
10904 enforceReadPrivilegedPermission("getGbaReleaseTime");
10905
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 return getGbaManager(subId).getReleaseTime();
10909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
10913
10914 private GbaManager getGbaManager(int subId) {
10915 GbaManager instance = GbaManager.getInstance(subId);
10916 if (instance == null) {
10917 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10918 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10919 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10920 }
10921 return instance;
10922 }
Hui Wang761a6682020-10-31 05:12:53 +000010923
10924 /**
10925 * indicate whether the device and the carrier can support
10926 * RCS VoLTE single registration.
10927 */
10928 @Override
10929 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010930 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10931 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10932 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10933 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010934
10935 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10936 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10937 }
10938
10939 final long identity = Binder.clearCallingIdentity();
10940 try {
10941 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10942 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010943 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10944 if (isCapable != null) {
10945 return isCapable;
10946 }
Hui Wang761a6682020-10-31 05:12:53 +000010947 }
Hui Wang67af90e2021-06-04 16:57:15 -070010948 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10949 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010950 } finally {
10951 Binder.restoreCallingIdentity(identity);
10952 }
10953 }
10954
10955 /**
10956 * Register RCS provisioning callback.
10957 */
10958 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010959 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010960 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010961 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010962 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010963 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10964 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010965
10966 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10967 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10968 }
10969 if (!isImsAvailableOnDevice()) {
10970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10971 "IMS not available on device.");
10972 }
10973
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010976 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010977 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010978 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10979 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010980 }
Hui Wang761a6682020-10-31 05:12:53 +000010981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
10985
10986 /**
10987 * Unregister RCS provisioning callback.
10988 */
10989 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010990 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010991 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010992 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010993 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010994 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10995 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010996
10997 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10998 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10999 }
11000 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011001 // operation failed silently
11002 Rlog.w(LOG_TAG, "IMS not available on device.");
11003 return;
Hui Wang761a6682020-10-31 05:12:53 +000011004 }
11005
11006 final long identity = Binder.clearCallingIdentity();
11007 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011008 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011009 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011010 } finally {
11011 Binder.restoreCallingIdentity(identity);
11012 }
11013 }
11014
11015 /**
11016 * trigger RCS reconfiguration.
11017 */
11018 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011019 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11020 "triggerRcsReconfiguration",
11021 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011022
11023 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11024 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11025 }
11026 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011027 // ProvisioningManager can not handle ServiceSpecificException.
11028 // Throw the IllegalStateException and annotate ProvisioningManager.
11029 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011030 }
11031
11032 final long identity = Binder.clearCallingIdentity();
11033 try {
11034 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11035 } finally {
11036 Binder.restoreCallingIdentity(identity);
11037 }
11038 }
11039
11040 /**
11041 * Provide the client configuration parameters of the RCS application.
11042 */
11043 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011044 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11045 "setRcsClientConfiguration",
11046 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011047
11048 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11049 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11050 }
11051 if (!isImsAvailableOnDevice()) {
11052 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11053 "IMS not available on device.");
11054 }
11055
11056 final long identity = Binder.clearCallingIdentity();
11057
11058 try {
11059 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11060 if (configBinder == null) {
11061 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011062 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11063 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011064 } else {
11065 configBinder.setRcsClientConfiguration(rcc);
11066 }
joonhunshin3e154242021-09-17 06:33:39 +000011067
11068 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11069 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011070 } catch (RemoteException e) {
11071 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011072 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11073 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011074 } finally {
11075 Binder.restoreCallingIdentity(identity);
11076 }
11077 }
11078
11079 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011080 * Enables or disables the test mode for RCS VoLTE single registration.
11081 */
11082 @Override
11083 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11085 "setRcsSingleRegistrationTestModeEnabled");
11086
11087 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11088 }
11089
11090 /**
11091 * Gets the test mode for RCS VoLTE single registration.
11092 */
11093 @Override
11094 public boolean getRcsSingleRegistrationTestModeEnabled() {
11095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11096 "getRcsSingleRegistrationTestModeEnabled");
11097
11098 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11099 }
11100
11101 /**
Hui Wang761a6682020-10-31 05:12:53 +000011102 * Overrides the config of RCS VoLTE single registration enabled for the device.
11103 */
11104 @Override
11105 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11106 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11107 "setDeviceSingleRegistrationEnabledOverride");
11108 enforceModifyPermission();
11109
11110 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11111 : Boolean.parseBoolean(enabledStr);
11112 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011113 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011114 }
11115
11116 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011117 * Sends a device to device communication message. Only usable via shell.
11118 * @param message message to send.
11119 * @param value message value.
11120 */
11121 @Override
11122 public void sendDeviceToDeviceMessage(int message, int value) {
11123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011124 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011125 enforceModifyPermission();
11126
11127 final long identity = Binder.clearCallingIdentity();
11128 try {
11129 TelephonyConnectionService service =
11130 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11131 if (service == null) {
11132 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11133 return;
11134 }
11135 service.sendTestDeviceToDeviceMessage(message, value);
11136 } finally {
11137 Binder.restoreCallingIdentity(identity);
11138 }
11139 }
11140
Tyler Gunnbabbda02021-02-10 11:05:02 -080011141 /**
11142 * Sets the specified device to device transport active.
11143 * @param transport The transport to set active.
11144 */
11145 @Override
11146 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11148 "setActiveDeviceToDeviceTransport");
11149 enforceModifyPermission();
11150
11151 final long identity = Binder.clearCallingIdentity();
11152 try {
11153 TelephonyConnectionService service =
11154 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11155 if (service == null) {
11156 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11157 return;
11158 }
11159 service.setActiveDeviceToDeviceTransport(transport);
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 }
Tyler Gunn92479152021-01-20 16:30:10 -080011164
Tyler Gunnd4339262021-05-03 14:46:49 -070011165 @Override
11166 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11167 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11168 "setDeviceToDeviceForceEnabled");
11169
11170 final long identity = Binder.clearCallingIdentity();
11171 try {
11172 Arrays.stream(PhoneFactory.getPhones()).forEach(
11173 p -> {
11174 Phone thePhone = p.getImsPhone();
11175 if (thePhone != null && thePhone instanceof ImsPhone) {
11176 ImsPhone imsPhone = (ImsPhone) thePhone;
11177 CallTracker tracker = imsPhone.getCallTracker();
11178 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11179 ImsPhoneCallTracker imsPhoneCallTracker =
11180 (ImsPhoneCallTracker) tracker;
11181 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11182 }
11183 }
11184 }
11185 );
11186 } finally {
11187 Binder.restoreCallingIdentity(identity);
11188 }
11189 }
11190
Tyler Gunn92479152021-01-20 16:30:10 -080011191 /**
Hui Wang761a6682020-10-31 05:12:53 +000011192 * Gets the config of RCS VoLTE single registration enabled for the device.
11193 */
11194 @Override
11195 public boolean getDeviceSingleRegistrationEnabled() {
11196 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11197 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11198 }
11199
11200 /**
11201 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11202 */
11203 @Override
11204 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11205 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11206 "setCarrierSingleRegistrationEnabledOverride");
11207 enforceModifyPermission();
11208
11209 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11210 : Boolean.parseBoolean(enabledStr);
11211 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11212 subId, enabled);
11213 }
11214
11215 /**
11216 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11217 */
11218 @Override
11219 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11220 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11221 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11222 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011223
11224 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011225 * Overrides the ims feature validation result
11226 */
11227 @Override
11228 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11229 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11230 "setImsFeatureValidationOverride");
11231
11232 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11233 : Boolean.parseBoolean(enabledStr);
11234 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11235 subId, enabled);
11236 }
11237
11238 /**
11239 * Gets the ims feature validation override value
11240 */
11241 @Override
11242 public boolean getImsFeatureValidationOverride(int subId) {
11243 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11244 "getImsFeatureValidationOverride");
11245 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11246 }
11247
11248 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011249 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11250 * their mobile plan.
11251 */
11252 @Override
11253 public String getMobileProvisioningUrl() {
11254 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11255 final long identity = Binder.clearCallingIdentity();
11256 try {
11257 return getDefaultPhone().getMobileProvisioningUrl();
11258 } finally {
11259 Binder.restoreCallingIdentity(identity);
11260 }
11261 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011262
James.cf Linbcdf8b32021-01-14 16:44:13 +080011263 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011264 * Get the EAB contact from the EAB database.
11265 */
11266 @Override
11267 public String getContactFromEab(String contact) {
11268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11269 enforceModifyPermission();
11270 final long identity = Binder.clearCallingIdentity();
11271 try {
11272 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11273 } finally {
11274 Binder.restoreCallingIdentity(identity);
11275 }
11276 }
11277
11278 /**
Calvin Pana1434322021-07-01 19:27:01 +080011279 * Get the EAB capability from the EAB database.
11280 */
11281 @Override
11282 public String getCapabilityFromEab(String contact) {
11283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11284 enforceModifyPermission();
11285 final long identity = Binder.clearCallingIdentity();
11286 try {
11287 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11288 } finally {
11289 Binder.restoreCallingIdentity(identity);
11290 }
11291 }
11292
11293 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011294 * Remove the EAB contacts from the EAB database.
11295 */
11296 @Override
11297 public int removeContactFromEab(int subId, String contacts) {
11298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11299 enforceModifyPermission();
11300 final long identity = Binder.clearCallingIdentity();
11301 try {
11302 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11303 } finally {
11304 Binder.restoreCallingIdentity(identity);
11305 }
11306 }
11307
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011308 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011309 public boolean getDeviceUceEnabled() {
11310 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11311 final long identity = Binder.clearCallingIdentity();
11312 try {
11313 return mApp.getDeviceUceEnabled();
11314 } finally {
11315 Binder.restoreCallingIdentity(identity);
11316 }
11317 }
11318
11319 @Override
11320 public void setDeviceUceEnabled(boolean isEnabled) {
11321 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11322 final long identity = Binder.clearCallingIdentity();
11323 try {
11324 mApp.setDeviceUceEnabled(isEnabled);
11325 } finally {
11326 Binder.restoreCallingIdentity(identity);
11327 }
11328 }
11329
Brad Ebinger14d467f2021-02-12 06:18:28 +000011330 /**
11331 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11332 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11333 */
11334 // Used for SHELL command only right now.
11335 @Override
11336 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11337 List<String> featureTags) {
11338 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11339 "addUceRegistrationOverrideShell");
11340 final long identity = Binder.clearCallingIdentity();
11341 try {
11342 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11343 new ArraySet<>(featureTags));
11344 } catch (ImsException e) {
11345 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11346 } finally {
11347 Binder.restoreCallingIdentity(identity);
11348 }
11349 }
11350
11351 /**
11352 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11353 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11354 */
11355 // Used for SHELL command only right now.
11356 @Override
11357 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11358 List<String> featureTags) {
11359 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11360 "removeUceRegistrationOverrideShell");
11361 final long identity = Binder.clearCallingIdentity();
11362 try {
11363 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11364 new ArraySet<>(featureTags));
11365 } catch (ImsException e) {
11366 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11367 } finally {
11368 Binder.restoreCallingIdentity(identity);
11369 }
11370 }
11371
11372 /**
11373 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11374 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11375 */
11376 // Used for SHELL command only right now.
11377 @Override
11378 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11380 "clearUceRegistrationOverrideShell");
11381 final long identity = Binder.clearCallingIdentity();
11382 try {
11383 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11384 } catch (ImsException e) {
11385 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11386 } finally {
11387 Binder.restoreCallingIdentity(identity);
11388 }
11389 }
11390
11391 /**
11392 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11393 */
11394 // Used for SHELL command only right now.
11395 @Override
11396 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11398 "getLatestRcsContactUceCapabilityShell");
11399 final long identity = Binder.clearCallingIdentity();
11400 try {
11401 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11402 } catch (ImsException e) {
11403 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11404 } finally {
11405 Binder.restoreCallingIdentity(identity);
11406 }
11407 }
11408
11409 /**
11410 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11411 * device does not have an active PUBLISH.
11412 */
11413 // Used for SHELL command only right now.
11414 @Override
11415 public String getLastUcePidfXmlShell(int subId) {
11416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11417 final long identity = Binder.clearCallingIdentity();
11418 try {
11419 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11420 } catch (ImsException e) {
11421 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11422 } finally {
11423 Binder.restoreCallingIdentity(identity);
11424 }
11425 }
11426
James.cf Line8713a42021-04-29 16:04:26 +080011427 /**
11428 * Remove UCE requests cannot be sent to the network status.
11429 */
11430 // Used for SHELL command only right now.
11431 @Override
11432 public boolean removeUceRequestDisallowedStatus(int subId) {
11433 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11434 final long identity = Binder.clearCallingIdentity();
11435 try {
11436 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11437 } catch (ImsException e) {
11438 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11439 } finally {
11440 Binder.restoreCallingIdentity(identity);
11441 }
11442 }
11443
James.cf Lin18bb9002021-05-25 01:37:38 +080011444 /**
11445 * Remove UCE requests cannot be sent to the network status.
11446 */
11447 // Used for SHELL command only.
11448 @Override
11449 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11450 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11451 final long identity = Binder.clearCallingIdentity();
11452 try {
11453 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11454 } catch (ImsException e) {
11455 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11456 } finally {
11457 Binder.restoreCallingIdentity(identity);
11458 }
11459 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011460
James.cf Lin4b784aa2021-01-31 03:25:15 +080011461 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011462 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11463 String callingPackage) {
11464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11465 mApp, subId, "setSignalStrengthUpdateRequest");
11466
11467 final int callingUid = Binder.getCallingUid();
11468 // Verify that tha callingPackage belongs to the calling UID
11469 mApp.getSystemService(AppOpsManager.class)
11470 .checkPackage(callingUid, callingPackage);
11471
Rambo Wang3607f502021-02-01 21:51:40 -080011472 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011473
11474 final long identity = Binder.clearCallingIdentity();
11475 try {
11476 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11477 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11478
11479 if (result instanceof IllegalStateException) {
11480 throw (IllegalStateException) result;
11481 }
11482 } finally {
11483 Binder.restoreCallingIdentity(identity);
11484 }
11485 }
11486
11487 @Override
11488 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11489 String callingPackage) {
11490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11491 mApp, subId, "clearSignalStrengthUpdateRequest");
11492
11493 final int callingUid = Binder.getCallingUid();
11494 // Verify that tha callingPackage belongs to the calling UID
11495 mApp.getSystemService(AppOpsManager.class)
11496 .checkPackage(callingUid, callingPackage);
11497
11498 final long identity = Binder.clearCallingIdentity();
11499 try {
11500 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11501 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11502
11503 if (result instanceof IllegalStateException) {
11504 throw (IllegalStateException) result;
11505 }
11506 } finally {
11507 Binder.restoreCallingIdentity(identity);
11508 }
11509 }
11510
Rambo Wang3607f502021-02-01 21:51:40 -080011511 private static void validateSignalStrengthUpdateRequest(Context context,
11512 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011513 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11514 // phone/system process do not have further restriction on request
11515 return;
11516 }
11517
11518 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011519 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011520 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011521 context.enforceCallingOrSelfPermission(
11522 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11523 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011524 }
11525
11526 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011527 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011528 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011529 || info.isEnabled()) {
11530 throw new IllegalArgumentException(
11531 "Only system can set hide fields in SignalThresholdInfo");
11532 }
11533
11534 // Thresholds length for each RAN need in range. This has been validated in
11535 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11536 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11537 final int[] thresholds = info.getThresholds();
11538 Objects.requireNonNull(thresholds);
11539 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11540 || thresholds.length
11541 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11542 throw new IllegalArgumentException(
11543 "thresholds length is out of range: " + thresholds.length);
11544 }
11545 }
11546 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011547
11548 /**
11549 * Gets the current phone capability.
11550 *
11551 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11552 * @return the PhoneCapability which describes the data connection capability of modem.
11553 * It's used to evaluate possible phone config change, for example from single
11554 * SIM device to multi-SIM device.
11555 */
11556 @Override
11557 public PhoneCapability getPhoneCapability() {
11558 enforceReadPrivilegedPermission("getPhoneCapability");
11559 final long identity = Binder.clearCallingIdentity();
11560 try {
11561 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11562 } finally {
11563 Binder.restoreCallingIdentity(identity);
11564 }
11565 }
Michele Berionne5e411512020-11-13 02:36:59 +000011566
11567 /**
11568 * Prepare TelephonyManager for an unattended reboot. The reboot is
11569 * required to be done shortly after the API is invoked.
11570 */
11571 @Override
11572 @TelephonyManager.PrepareUnattendedRebootResult
11573 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011574 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011575 enforceRebootPermission();
11576
11577 final long identity = Binder.clearCallingIdentity();
11578 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011579 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011580 } finally {
11581 Binder.restoreCallingIdentity(identity);
11582 }
11583 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011584
11585 /**
11586 * Request to get the current slicing configuration including URSP rules and
11587 * NSSAIs (configured, allowed and rejected).
11588 *
11589 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11590 */
11591 @Override
11592 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011593 TelephonyPermissions
11594 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11595 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011596
11597 final long identity = Binder.clearCallingIdentity();
11598 try {
11599 Phone phone = getDefaultPhone();
11600 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11601 } finally {
11602 Binder.restoreCallingIdentity(identity);
11603 }
11604 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011605
11606 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011607 * Check whether the given premium capability is available for purchase from the carrier.
11608 *
11609 * @param capability The premium capability to check.
11610 * @param subId The subId to check the premium capability for.
11611 *
11612 * @return Whether the given premium capability is available to purchase.
11613 */
11614 @Override
11615 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11616 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11617 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11618 log("Premium capability "
11619 + TelephonyManager.convertPremiumCapabilityToString(capability)
11620 + " is not available for purchase due to missing permissions.");
11621 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11622 + "permission READ_BASIC_PHONE_STATE.");
11623 }
11624
11625 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011626 if (phone == null) {
11627 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11628 return false;
11629 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011630 final long identity = Binder.clearCallingIdentity();
11631 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011632 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011633 .isPremiumCapabilityAvailableForPurchase(capability);
11634 } finally {
11635 Binder.restoreCallingIdentity(identity);
11636 }
11637 }
11638
11639 /**
11640 * Purchase the given premium capability from the carrier.
11641 *
11642 * @param capability The premium capability to purchase.
11643 * @param callback The result of the purchase request.
11644 * @param subId The subId to purchase the premium capability for.
11645 */
11646 @Override
11647 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11648 log("purchasePremiumCapability: capability="
11649 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11650 + getCurrentPackageName());
11651
11652 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11653 mApp, "purchasePremiumCapability")) {
11654 log("purchasePremiumCapability "
11655 + TelephonyManager.convertPremiumCapabilityToString(capability)
11656 + " failed due to missing permissions.");
11657 throw new SecurityException("purchasePremiumCapability requires permission "
11658 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011659 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11660 mApp, "purchasePremiumCapability")) {
11661 log("purchasePremiumCapability "
11662 + TelephonyManager.convertPremiumCapabilityToString(capability)
11663 + " failed due to missing permissions.");
11664 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011665 }
11666
11667 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011668 if (phone == null) {
11669 try {
11670 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11671 callback.accept(result);
11672 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11673 } catch (RemoteException e) {
11674 String logStr = "Purchase premium capability "
11675 + TelephonyManager.convertPremiumCapabilityToString(capability)
11676 + " failed due to RemoteException handling null phone: " + e;
11677 if (DBG) log(logStr);
11678 AnomalyReporter.reportAnomaly(
11679 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11680 }
11681 return;
11682 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011683
11684 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011685 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011686 callingProcess = mApp.getPackageManager().getApplicationInfo(
11687 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011688 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011689 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011690 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011691
11692 boolean isVisible = false;
11693 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11694 if (am != null) {
11695 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11696 if (processes != null) {
11697 for (ActivityManager.RunningAppProcessInfo process : processes) {
11698 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011699 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011700 if (process.processName.equals(callingProcess) && process.importance
11701 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11702 isVisible = true;
11703 break;
11704 }
11705 }
11706 }
11707 }
11708
11709 if (!isVisible) {
11710 try {
11711 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11712 callback.accept(result);
11713 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11714 } catch (RemoteException e) {
11715 String logStr = "Purchase premium capability "
11716 + TelephonyManager.convertPremiumCapabilityToString(capability)
11717 + " failed due to RemoteException handling background application: " + e;
11718 if (DBG) log(logStr);
11719 AnomalyReporter.reportAnomaly(
11720 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11721 }
11722 return;
11723 }
11724
Sarah Chin71b3a852022-09-28 15:54:19 -070011725 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011726 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011727 }
11728
11729 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011730 * Register an IMS connection state callback
11731 */
11732 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011733 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11734 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011735 if (feature == ImsFeature.FEATURE_MMTEL) {
11736 // ImsMmTelManager
11737 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11738 TelephonyPermissions
11739 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11740 mApp, subId, "registerImsStateCallback");
11741 } else if (feature == ImsFeature.FEATURE_RCS) {
11742 // ImsRcsManager or SipDelegateManager
11743 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11744 Binder.getCallingUid(), "registerImsStateCallback",
11745 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11746 Manifest.permission.READ_PRECISE_PHONE_STATE,
11747 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11748 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11749 }
11750
11751 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11752 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11753 "IMS not available on device.");
11754 }
11755
11756 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11757 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11758 }
11759
11760 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11761 if (controller == null) {
11762 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11763 "IMS not available on device.");
11764 }
11765
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011766 if (callingPackage == null) {
11767 callingPackage = getCurrentPackageName();
11768 }
11769
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011770 final long token = Binder.clearCallingIdentity();
11771 try {
11772 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011773 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011774 } catch (ImsException e) {
11775 throw new ServiceSpecificException(e.getCode());
11776 } finally {
11777 Binder.restoreCallingIdentity(token);
11778 }
11779 }
11780
11781 /**
11782 * Unregister an IMS connection state callback
11783 */
11784 @Override
11785 public void unregisterImsStateCallback(IImsStateCallback cb) {
11786 final long token = Binder.clearCallingIdentity();
11787 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11788 if (controller == null) {
11789 return;
11790 }
11791 try {
11792 controller.unregisterImsStateCallback(cb);
11793 } finally {
11794 Binder.restoreCallingIdentity(token);
11795 }
11796 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011797
11798 /**
11799 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11800 *
11801 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11802 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11803 * SecurityException.
11804 * If there is current registered network this value will be same as the registered cell
11805 * identity. If the device goes out of service the previous cell identity is cached and
11806 * will be returned. If the cache age of the Cell identity is more than 24 hours
11807 * it will be cleared and null will be returned.
11808 *
11809 */
11810 @Override
11811 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11812 String callingFeatureId) {
11813 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11814 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11815 LocationAccessPolicy.checkLocationPermission(mApp,
11816 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11817 .setCallingPackage(callingPackage)
11818 .setCallingFeatureId(callingFeatureId)
11819 .setCallingPid(Binder.getCallingPid())
11820 .setCallingUid(Binder.getCallingUid())
11821 .setMethod("getLastKnownCellIdentity")
11822 .setLogAsInfo(true)
11823 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11824 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11825 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11826 .build());
11827
11828 boolean hasFinePermission =
11829 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11830 if (!hasFinePermission
11831 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11832 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011833 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011834 }
11835
11836 final long identity = Binder.clearCallingIdentity();
11837 try {
Ling Mac28f0212023-03-24 16:07:15 -070011838 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011839 if (sst == null) return null;
11840 return sst.getLastKnownCellIdentity();
11841 } finally {
11842 Binder.restoreCallingIdentity(identity);
11843 }
11844 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011845
jimsun3b9ccac2021-10-26 15:01:23 +080011846 /**
11847 * Sets the modem service class Name that Telephony will bind to.
11848 *
11849 * @param serviceName The class name of the modem service.
11850 * @return true if the operation is succeed, otherwise false.
11851 */
11852 public boolean setModemService(String serviceName) {
11853 Log.d(LOG_TAG, "setModemService - " + serviceName);
11854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011856 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11857 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011858 return mPhoneConfigurationManager.setModemService(serviceName);
11859 }
11860
11861 /**
11862 * Return the class name of the currently bounded modem service.
11863 *
11864 * @return the class name of the modem service.
11865 */
11866 public String getModemService() {
11867 String result;
11868 Log.d(LOG_TAG, "getModemService");
11869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11870 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011871 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011872 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11873 "getModemService");
11874 result = mPhoneConfigurationManager.getModemService();
11875 Log.d(LOG_TAG, "result = " + result);
11876 return result;
11877 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011878
11879 @Override
11880 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11881 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11882 mApp.enforceCallingOrSelfPermission(
11883 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11885
11886 final long identity = Binder.clearCallingIdentity();
11887 try {
11888 Phone phone = getPhone(subId);
11889 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011890 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11891 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011892 phone.setVoiceServiceStateOverride(hasService);
11893 } finally {
11894 Binder.restoreCallingIdentity(identity);
11895 }
11896 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011897
11898 /**
11899 * set removable eSIM as default eUICC.
11900 *
11901 * @hide
11902 */
11903 @Override
11904 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11905 enforceModifyPermission();
11906 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11907
11908 final long identity = Binder.clearCallingIdentity();
11909 try {
11910 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11911 } finally {
11912 Binder.restoreCallingIdentity(identity);
11913 }
11914 }
11915
11916 /**
11917 * Returns whether the removable eSIM is default eUICC or not.
11918 *
11919 * @hide
11920 */
11921 @Override
11922 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11923 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11924 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11925
11926 final long identity = Binder.clearCallingIdentity();
11927 try {
11928 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11929 } finally {
11930 Binder.restoreCallingIdentity(identity);
11931 }
11932 }
11933
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011934 /**
11935 * Get the component name of the default app to direct respond-via-message intent for the
11936 * user associated with this subscription, update the cache if there is no respond-via-message
11937 * application currently configured for this user.
11938 * @return component name of the app and class to direct Respond Via Message intent to, or
11939 * {@code null} if the functionality is not supported.
11940 * @hide
11941 */
11942 @Override
11943 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11944 boolean updateIfNeeded) {
11945 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011946
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011947 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11948
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011949 UserHandle userHandle = null;
11950 final long identity = Binder.clearCallingIdentity();
11951 try {
11952 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11953 } finally {
11954 Binder.restoreCallingIdentity(identity);
11955 }
11956 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11957 updateIfNeeded, userHandle);
11958 }
Jack Yuf5badd92022-12-08 00:50:53 -080011959
11960 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011961 * Set whether the device is able to connect with null ciphering or integrity
11962 * algorithms. This is a global setting and will apply to all active subscriptions
11963 * and all new subscriptions after this.
11964 *
11965 * @param enabled when true, null cipher and integrity algorithms are allowed.
11966 * @hide
11967 */
11968 @Override
11969 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11970 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11971 enforceModifyPermission();
11972 checkForNullCipherAndIntegritySupport();
11973
11974 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11975 // for listening to these preference changes and applying them immediately.
11976 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11977 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11978 editor.apply();
11979
11980 for (Phone phone: PhoneFactory.getPhones()) {
11981 phone.handleNullCipherEnabledChange();
11982 }
11983 }
11984
11985
11986 /**
11987 * Get whether the device is able to connect with null ciphering or integrity
11988 * algorithms. Note that this retrieves the phone-global preference and not
11989 * the state of the radio.
11990 *
11991 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11992 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11993 * version for this feature.
11994 * @hide
11995 */
11996 @Override
11997 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11998 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11999 enforceReadPermission();
12000 checkForNullCipherAndIntegritySupport();
12001 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12002 }
12003
12004 private void checkForNullCipherAndIntegritySupport() {
12005 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12006 throw new UnsupportedOperationException(
12007 "Null cipher and integrity operations require HAL 2.1 or above");
12008 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012009 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12010 throw new UnsupportedOperationException(
12011 "Null cipher and integrity operations unsupported by modem");
12012 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012013 }
12014
Gil Cukierman06403e12023-11-29 16:33:03 +000012015 private void checkForIdentifierDisclosureNotificationSupport() {
12016 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12017 throw new UnsupportedOperationException(
12018 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12019 + "above");
12020 }
12021 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12022 throw new UnsupportedOperationException(
12023 "Cellular identifier disclosure transparency operations unsupported by modem");
12024 }
12025 }
12026
Michael Groover826b71d2023-12-21 22:08:06 -060012027 private void checkForNullCipherNotificationSupport() {
12028 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12029 throw new UnsupportedOperationException(
12030 "Null cipher notification operations require HAL 2.2 or above");
12031 }
12032 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12033 throw new UnsupportedOperationException(
12034 "Null cipher notification operations unsupported by modem");
12035 }
12036 }
12037
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012038 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012039 * Get the SIM state for the slot index.
12040 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12041 *
12042 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12043 */
12044 @Override
12045 @SimState
12046 public int getSimStateForSlotIndex(int slotIndex) {
12047 IccCardConstants.State simState;
12048 if (slotIndex < 0) {
12049 simState = IccCardConstants.State.UNKNOWN;
12050 } else {
12051 Phone phone = null;
12052 try {
12053 phone = PhoneFactory.getPhone(slotIndex);
12054 } catch (IllegalStateException e) {
12055 // ignore
12056 }
12057 if (phone == null) {
12058 simState = IccCardConstants.State.UNKNOWN;
12059 } else {
12060 IccCard icc = phone.getIccCard();
12061 if (icc == null) {
12062 simState = IccCardConstants.State.UNKNOWN;
12063 } else {
12064 simState = icc.getState();
12065 }
12066 }
12067 }
12068 return simState.ordinal();
12069 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012070
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012071 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12072 boolean enableLogcat,
12073 long logcatStartTimestampMillis, boolean enableTelecomDump,
12074 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012075 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12076 TelephonyManager.EmergencyCallDiagnosticParams edp =
12077 new TelephonyManager.EmergencyCallDiagnosticParams();
12078 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12079 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12080 edp.setTelecomDumpSysCollection(enableTelecomDump);
12081 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12082 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12083 Executors.newCachedThreadPool(), db,
12084 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12085 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012086 }
12087
12088 /**
12089 * Request telephony to persist state for debugging emergency call failures.
12090 *
12091 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12092 * @param enableLogcat whether to collect logcat output
12093 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12094 * @param enableTelecomDump whether to collect telecom dumpsys
12095 * @param enableTelephonyDump whether to collect telephony dumpsys
12096 */
12097 @Override
12098 @RequiresPermission(android.Manifest.permission.DUMP)
12099 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12100 long logcatStartTimestampMillis, boolean enableTelecomDump,
12101 boolean enableTelephonyDump) {
12102 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12103 "persistEmergencyCallDiagnosticData");
12104 final long identity = Binder.clearCallingIdentity();
12105 try {
12106 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12107 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12108
12109 } finally {
12110 Binder.restoreCallingIdentity(identity);
12111 }
12112 }
12113
Hui Wang9b5793a2022-12-05 14:38:06 -060012114 /**
12115 * Get current cell broadcast ranges.
12116 */
12117 @Override
12118 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12119 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12120 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12121 "getCellBroadcastIdRanges");
12122 final long identity = Binder.clearCallingIdentity();
12123 try {
12124 return getPhone(subId).getCellBroadcastIdRanges();
12125 } finally {
12126 Binder.restoreCallingIdentity(identity);
12127 }
12128 }
12129
12130 /**
12131 * Set reception of cell broadcast messages with the list of the given ranges
12132 *
12133 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12134 */
12135 @Override
12136 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12137 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12138 @Nullable IIntegerConsumer callback) {
12139 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12140 "setCellBroadcastIdRanges");
12141 final long identity = Binder.clearCallingIdentity();
12142 try {
12143 Phone phone = getPhoneFromSubId(subId);
12144 if (DBG) {
12145 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12146 }
12147 phone.setCellBroadcastIdRanges(ranges, result -> {
12148 if (callback != null) {
12149 try {
12150 callback.accept(result);
12151 } catch (RemoteException e) {
12152 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12153 }
12154 }
12155 });
12156 } finally {
12157 Binder.restoreCallingIdentity(identity);
12158 }
12159 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012160
12161 /**
12162 * Returns whether the device supports the domain selection service.
12163 *
12164 * @return {@code true} if the device supports the domain selection service.
12165 */
12166 @Override
12167 public boolean isDomainSelectionSupported() {
12168 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12169 "isDomainSelectionSupported");
12170
12171 final long identity = Binder.clearCallingIdentity();
12172 try {
12173 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12174 } finally {
12175 Binder.restoreCallingIdentity(identity);
12176 }
12177 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012178
12179 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012180 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12181 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12182 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012183 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012184 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012185 * @param enableSatellite {@code true} to enable the satellite modem and
12186 * {@code false} to disable.
12187 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12188 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012189 *
12190 * @throws SecurityException if the caller doesn't have the required permission.
12191 */
12192 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012193 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12194 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012195 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012196 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12197 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012198 }
12199
12200 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012201 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012202 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012203 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012204 * @param result The result receiver that returns whether the satellite modem is enabled
12205 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012206 *
12207 * @throws SecurityException if the caller doesn't have the required permission.
12208 */
12209 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012210 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12211 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012212 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012213 }
12214
12215 /**
Sarah Chin43457982023-02-15 17:50:38 -080012216 * Request to get whether the satellite service demo mode is enabled.
12217 *
12218 * @param subId The subId of the subscription to check whether the satellite demo mode
12219 * is enabled for.
12220 * @param result The result receiver that returns whether the satellite demo mode is enabled
12221 * if the request is successful or an error code if the request failed.
12222 *
12223 * @throws SecurityException if the caller doesn't have the required permission.
12224 */
12225 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012226 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12227 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12228 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012229 }
12230
12231 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012232 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012233 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012234 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012235 * @param result The result receiver that returns whether the satellite service is supported on
12236 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012237 */
12238 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012239 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012240 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012241 }
12242
12243 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012244 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012245 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012246 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012247 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12248 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012249 *
12250 * @throws SecurityException if the caller doesn't have required permission.
12251 */
12252 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012253 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12254 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012255 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012256 }
12257
12258 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012259 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012260 * This can be called by the pointing UI when the user starts pointing to the satellite.
12261 * Modem should continue to report the pointing input as the device or satellite moves.
12262 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012263 * @param subId The subId of the subscription to start satellite transmission updates for.
12264 * @param resultCallback The callback to get the result of the request.
12265 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012266 *
12267 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012268 */
12269 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012270 public void startSatelliteTransmissionUpdates(int subId,
12271 @NonNull IIntegerConsumer resultCallback,
12272 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12273 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12274 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012275 }
12276
12277 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012278 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012279 * This can be called by the pointing UI when the user stops pointing to the satellite.
12280 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012281 * @param subId The subId of the subscription to stop satellite transmission updates for.
12282 * @param resultCallback The callback to get the result of the request.
12283 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12284 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012285 *
12286 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012287 */
12288 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012289 public void stopSatelliteTransmissionUpdates(int subId,
12290 @NonNull IIntegerConsumer resultCallback,
12291 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12292 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12293 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012294 }
12295
12296 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012297 * Register the subscription with a satellite provider.
12298 * This is needed to register the subscription if the provider allows dynamic registration.
12299 *
12300 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012301 * @param token The token to be used as a unique identifier for provisioning with satellite
12302 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012303 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012304 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012305 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012306 * @return The signal transport used by the caller to cancel the provision request,
12307 * or {@code null} if the request failed.
12308 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012309 * @throws SecurityException if the caller doesn't have the required permission.
12310 */
12311 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012312 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012313 @NonNull String token, @NonNull byte[] provisionData,
12314 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012315 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012316 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12317 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012318 }
12319
12320 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012321 * Unregister the device/subscription with the satellite provider.
12322 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012323 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012324 * should report as deprovisioned.
12325 *
12326 * @param subId The subId of the subscription to be deprovisioned.
12327 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012328 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012329 *
12330 * @throws SecurityException if the caller doesn't have the required permission.
12331 */
12332 @Override
12333 public void deprovisionSatelliteService(int subId,
12334 @NonNull String token, @NonNull IIntegerConsumer callback) {
12335 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012336 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012337 }
12338
12339 /**
Sarah Chin43457982023-02-15 17:50:38 -080012340 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012341 *
Sarah Chin43457982023-02-15 17:50:38 -080012342 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012343 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012344 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012345 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012346 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012347 * @throws SecurityException if the caller doesn't have the required permission.
12348 */
12349 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012350 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12351 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012352 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012353 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012354 }
12355
12356 /**
Sarah Chin43457982023-02-15 17:50:38 -080012357 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012358 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012359 *
Sarah Chin43457982023-02-15 17:50:38 -080012360 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012361 * @param callback The callback that was passed to
12362 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012363 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012364 * @throws SecurityException if the caller doesn't have the required permission.
12365 */
12366 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012367 public void unregisterForSatelliteProvisionStateChanged(
12368 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012369 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012370 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012371 }
12372
12373 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012374 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012375 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012376 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012377 * @param result The result receiver that returns whether the device is provisioned with a
12378 * satellite provider if the request is successful or an error code if the
12379 * request failed.
12380 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012381 * @throws SecurityException if the caller doesn't have the required permission.
12382 */
12383 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012384 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12385 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012386 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012387 }
12388
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012389 /**
Sarah Chin43457982023-02-15 17:50:38 -080012390 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012391 *
Sarah Chin43457982023-02-15 17:50:38 -080012392 * @param subId The subId of the subscription to register for satellite modem state changed.
12393 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012394 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012395 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012396 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012397 * @throws SecurityException if the caller doesn't have the required permission.
12398 */
12399 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012400 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012401 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012402 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012403 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012404 }
12405
12406 /**
Sarah Chin43457982023-02-15 17:50:38 -080012407 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012408 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012409 *
Sarah Chin43457982023-02-15 17:50:38 -080012410 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012411 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012412 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012413 *
12414 * @throws SecurityException if the caller doesn't have the required permission.
12415 */
12416 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012417 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012418 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012419 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012420 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012421 }
12422
12423 /**
12424 * Register to receive incoming datagrams over satellite.
12425 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012426 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012427 * @param callback The callback to handle incoming datagrams over satellite.
12428 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012429 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012430 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012431 * @throws SecurityException if the caller doesn't have the required permission.
12432 */
12433 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012434 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012435 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012436 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012437 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012438 }
12439
12440 /**
12441 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012442 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012443 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012444 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12445 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012446 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012447 *
12448 * @throws SecurityException if the caller doesn't have the required permission.
12449 */
12450 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012451 public void unregisterForSatelliteDatagram(int subId,
12452 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012453 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012454 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012455 }
12456
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012457 /**
12458 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012459 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012460 * This method requests modem to check if there are any pending datagrams to be received over
12461 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012462 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012463 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012464 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012465 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012466 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012467 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012468 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012469 @Override
12470 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012471 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012472 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012473 }
12474
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012475 /**
12476 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012477 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012478 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12479 * input to this method. Datagram received here will be passed down to modem without any
12480 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012481 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012482 * @param subId The subId of the subscription to send satellite datagrams for.
12483 * @param datagramType datagram type indicating whether the datagram is of type
12484 * SOS_SMS or LOCATION_SHARING.
12485 * @param datagram encoded gateway datagram which is encrypted by the caller.
12486 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012487 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12488 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012489 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012490 *
12491 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012492 */
12493 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012494 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12495 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12496 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012497 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012498 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12499 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012500 }
12501
Sarah Chindf715ec2023-02-13 13:46:24 -080012502 /**
12503 * Request to get whether satellite communication is allowed for the current location.
12504 *
12505 * @param subId The subId of the subscription to check whether satellite communication is
12506 * allowed for the current location for.
12507 * @param result The result receiver that returns whether satellite communication is allowed
12508 * for the current location if the request is successful or an error code
12509 * if the request failed.
12510 *
12511 * @throws SecurityException if the caller doesn't have the required permission.
12512 */
12513 @Override
12514 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12515 @NonNull ResultReceiver result) {
12516 enforceSatelliteCommunicationPermission(
12517 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012518 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12519 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012520 }
12521
12522 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012523 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012524 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012525 * @param subId The subId to get the time after which the satellite will be visible for.
12526 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012527 * be visible if the request is successful or an error code if the request failed.
12528 *
12529 * @throws SecurityException if the caller doesn't have the required permission.
12530 */
12531 @Override
12532 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12533 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012534 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012535 }
12536
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012537 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012538 * Inform that Device is aligned to satellite for demo mode.
12539 *
12540 * @param subId The subId to get the time after which the satellite will be visible for.
12541 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12542 * {@code false} Device fails to align with the satellite for demo mode.
12543 *
12544 * @throws SecurityException if the caller doesn't have required permission.
12545 */
12546 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12547
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012548 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012549 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012550 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012551 }
12552
12553 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012554 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12555 * by modem.
12556 *
12557 * @param subId The subId of the subscription to request for.
12558 * @param reason Reason for disallowing satellite communication for carrier.
12559 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12560 * operation.
12561 *
12562 * @throws SecurityException if the caller doesn't have required permission.
12563 */
12564 public void addSatelliteAttachRestrictionForCarrier(int subId,
12565 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12566 @NonNull IIntegerConsumer callback) {
12567 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12568 final long identity = Binder.clearCallingIdentity();
12569 try {
12570 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12571 } finally {
12572 Binder.restoreCallingIdentity(identity);
12573 }
12574 }
12575
12576 /**
12577 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12578 * by modem.
12579 *
12580 * @param subId The subId of the subscription to request for.
12581 * @param reason Reason for disallowing satellite communication.
12582 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12583 * operation.
12584 *
12585 * @throws SecurityException if the caller doesn't have required permission.
12586 */
12587 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12588 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12589 @NonNull IIntegerConsumer callback) {
12590 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12591 final long identity = Binder.clearCallingIdentity();
12592 try {
12593 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12594 callback);
12595 } finally {
12596 Binder.restoreCallingIdentity(identity);
12597 }
12598 }
12599
12600 /**
12601 * Get reasons for disallowing satellite communication, as requested by
12602 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12603 *
12604 * @param subId The subId of the subscription to request for.
12605 *
12606 * @return Integer array of reasons for disallowing satellite communication.
12607 *
12608 * @throws SecurityException if the caller doesn't have the required permission.
12609 */
12610 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12611 int subId) {
12612 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12613 final long identity = Binder.clearCallingIdentity();
12614 try {
12615 Set<Integer> reasonSet =
12616 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12617 return reasonSet.stream().mapToInt(i->i).toArray();
12618 } finally {
12619 Binder.restoreCallingIdentity(identity);
12620 }
12621 }
12622
12623 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012624 * Request to get the signal strength of the satellite connection.
12625 *
12626 * @param subId The subId of the subscription to request for.
12627 * @param result Result receiver to get the error code of the request and the current signal
12628 * strength of the satellite connection.
12629 *
12630 * @throws SecurityException if the caller doesn't have required permission.
12631 */
12632 @Override
12633 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12634 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12635 final long identity = Binder.clearCallingIdentity();
12636 try {
12637 mSatelliteController.requestNtnSignalStrength(subId, result);
12638 } finally {
12639 Binder.restoreCallingIdentity(identity);
12640 }
12641 }
12642
12643 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012644 * Registers for NTN signal strength changed from satellite modem. If the registration operation
12645 * is not successful, a {@link ServiceSpecificException} that contains
12646 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012647 *
12648 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012649 * @param callback The callback to handle the NTN signal strength changed event. If the
12650 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
12651 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
12652 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
12653 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012654 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012655 * @throws SecurityException If the caller doesn't have the required permission.
12656 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012657 */
12658 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012659 public void registerForNtnSignalStrengthChanged(int subId,
12660 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000012661 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12662 final long identity = Binder.clearCallingIdentity();
12663 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000012664 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000012665 } finally {
12666 Binder.restoreCallingIdentity(identity);
12667 }
12668 }
12669
12670 /**
12671 * Unregisters for NTN signal strength changed from satellite modem.
12672 * If callback was not registered before, the request will be ignored.
12673 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000012674 * @param subId The subId of the subscription to unregister for listening NTN signal strength
12675 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012676 * @param callback The callback that was passed to
12677 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12678 *
12679 * @throws SecurityException if the caller doesn't have the required permission.
12680 */
12681 @Override
12682 public void unregisterForNtnSignalStrengthChanged(
12683 int subId, @NonNull INtnSignalStrengthCallback callback) {
12684 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12685 final long identity = Binder.clearCallingIdentity();
12686 try {
12687 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12688 } finally {
12689 Binder.restoreCallingIdentity(identity);
12690 }
12691 }
12692
12693 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000012694 * Registers for satellite capabilities change event from the satellite service.
12695 *
12696 * @param subId The subId of the subscription to request for.
12697 * @param callback The callback to handle the satellite capabilities changed event.
12698 *
12699 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12700 *
12701 * @throws SecurityException if the caller doesn't have required permission.
12702 */
12703 @Override
12704 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
12705 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12706 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
12707 final long identity = Binder.clearCallingIdentity();
12708 try {
12709 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
12710 } finally {
12711 Binder.restoreCallingIdentity(identity);
12712 }
12713 }
12714
12715 /**
12716 * Unregisters for satellite capabilities change event from the satellite service.
12717 * If callback was not registered before, the request will be ignored.
12718 *
12719 * @param subId The subId of the subscription to unregister for satellite capabilities change.
12720 * @param callback The callback that was passed to.
12721 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
12722 *
12723 * @throws SecurityException if the caller doesn't have required permission.
12724 */
12725 @Override
12726 public void unregisterForSatelliteCapabilitiesChanged(
12727 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12728 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
12729 final long identity = Binder.clearCallingIdentity();
12730 try {
12731 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
12732 } finally {
12733 Binder.restoreCallingIdentity(identity);
12734 }
12735 }
12736
12737 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012738 * This API can be used by only CTS to update satellite vendor service package name.
12739 *
12740 * @param servicePackageName The package name of the satellite vendor service.
12741 * @return {@code true} if the satellite vendor service is set successfully,
12742 * {@code false} otherwise.
12743 */
12744 public boolean setSatelliteServicePackageName(String servicePackageName) {
12745 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12746 TelephonyPermissions.enforceShellOnly(
12747 Binder.getCallingUid(), "setSatelliteServicePackageName");
12748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12749 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12750 "setSatelliteServicePackageName");
12751 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12752 }
12753
12754 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012755 * This API can be used by only CTS to update satellite gateway service package name.
12756 *
12757 * @param servicePackageName The package name of the satellite gateway service.
12758 * @return {@code true} if the satellite gateway service is set successfully,
12759 * {@code false} otherwise.
12760 */
12761 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12762 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12763 TelephonyPermissions.enforceShellOnly(
12764 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12766 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12767 "setSatelliteGatewayServicePackageName");
12768 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12769 }
12770
12771 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012772 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12773 *
12774 * @param packageName The package name of the satellite pointing UI app.
12775 * @param className The class name of the satellite pointing UI app.
12776 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12777 * {@code false} otherwise.
12778 */
12779 public boolean setSatellitePointingUiClassName(
12780 @Nullable String packageName, @Nullable String className) {
12781 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12782 + ", className=" + className);
12783 TelephonyPermissions.enforceShellOnly(
12784 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12786 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12787 "setSatelliteGatewayServicePackageName");
12788 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12789 }
12790
12791 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012792 * This API can be used by only CTS to update the timeout duration in milliseconds that
12793 * satellite should stay at listening mode to wait for the next incoming page before disabling
12794 * listening mode.
12795 *
12796 * @param timeoutMillis The timeout duration in millisecond.
12797 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12798 */
12799 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12800 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12801 TelephonyPermissions.enforceShellOnly(
12802 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12804 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12805 "setSatelliteListeningTimeoutDuration");
12806 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12807 }
12808
12809 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012810 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12811 * the device is aligned with the satellite for demo mode
12812 *
12813 * @param timeoutMillis The timeout duration in millisecond.
12814 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12815 */
12816 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12817 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12818 TelephonyPermissions.enforceShellOnly(
12819 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12821 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12822 "setDeviceAlignedTimeoutDuration");
12823 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12824 }
12825
12826 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070012827 * This API can be used in only testing to override connectivity status in monitoring emergency
12828 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
12829 *
12830 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
12831 * of the following values to enable the override:
12832 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
12833 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
12834 * To disable the override, use -1 for handoverType.
12835 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
12836 * delaySeconds after the emergency call starts.
12837 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
12838 */
12839 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
12840 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
12841 TelephonyPermissions.enforceShellOnly(
12842 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
12843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12844 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12845 "setEmergencyCallToSatelliteHandoverType");
12846 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
12847 handoverType, delaySeconds);
12848 }
12849
12850 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000012851 * This API can be used by only CTS to override the cached value for the device overlay config
12852 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
12853 * outgoing satellite datagrams should be sent to modem in demo mode.
12854 *
12855 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
12856 * satellite modem or not.
12857 *
12858 * @return {@code true} if the operation is successful, {@code false} otherwise.
12859 */
12860 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
12861 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
12862 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
12863 + "disabled");
12864 return false;
12865 }
12866 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
12867 TelephonyPermissions.enforceShellOnly(
12868 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
12869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12870 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12871 "setShouldSendDatagramToModemInDemoMode");
12872 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
12873 shouldSendToModemInDemoMode);
12874 }
12875
12876 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000012877 * Enable or disable notifications sent for cellular identifier disclosure events.
12878 *
12879 * Disclosure events are defined as instances where a device has sent a cellular identifier
12880 * on the Non-access stratum (NAS) before a security context is established. As a result the
12881 * identifier is sent in the clear, which has privacy implications for the user.
12882 *
12883 * @param enable if notifications about disclosure events should be enabled
12884 * @throws SecurityException if the caller does not have the required privileges
12885 * @throws UnsupportedOperationException if the modem does not support this feature.
12886 */
12887 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000012888 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000012889 enforceModifyPermission();
12890 checkForIdentifierDisclosureNotificationSupport();
12891
12892 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12893 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
12894 editor.apply();
12895
12896 // Each phone instance is responsible for updating its respective modem immediately
12897 // after we've made a preference change.
12898 for (Phone phone : PhoneFactory.getPhones()) {
12899 phone.handleIdentifierDisclosureNotificationPreferenceChange();
12900 }
12901 }
12902
12903 /**
12904 * Get whether or not cellular identifier disclosure notifications are enabled.
12905 *
12906 * @throws SecurityException if the caller does not have the required privileges
12907 * @throws UnsupportedOperationException if the modem does not support this feature.
12908 */
12909 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000012910 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000012911 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
12912 checkForIdentifierDisclosureNotificationSupport();
12913 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
12914 }
12915
12916 /**
Michael Groover826b71d2023-12-21 22:08:06 -060012917 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
12918 * are in use by the cellular modem.
12919 *
12920 * @throws IllegalStateException if the Telephony process is not currently available
12921 * @throws SecurityException if the caller does not have the required privileges
12922 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
12923 * and integrity algorithms in use
12924 * @hide
12925 */
12926 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
12927 public void setEnableNullCipherNotifications(boolean enable) {
12928 enforceModifyPermission();
12929 checkForNullCipherNotificationSupport();
12930
12931 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12932 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
12933 editor.apply();
12934
12935 // Each phone instance is responsible for updating its respective modem immediately
12936 // after a preference change.
12937 for (Phone phone : PhoneFactory.getPhones()) {
12938 phone.handleNullCipherNotificationPreferenceChanged();
12939 }
12940 }
12941
12942 /**
12943 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
12944 * cellular modem.
12945 *
12946 * @throws IllegalStateException if the Telephony process is not currently available
12947 * @throws SecurityException if the caller does not have the required privileges
12948 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
12949 * and integrity algorithms in use
12950 * @hide
12951 */
12952 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
12953 public boolean isNullCipherNotificationsEnabled() {
12954 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
12955 checkForNullCipherNotificationSupport();
12956 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
12957 }
12958
12959 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012960 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12961 *
12962 * <p>This method behaves in one of the following ways:
12963 * <ul>
12964 * <li>return true : if the calling package has the appop permission {@link
12965 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12966 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12967 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12968 * Owner device identifier access check, or the calling package has carrier privileges</>
12969 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12970 * </ul>
12971 */
12972 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12973 String callingPackage, @Nullable String callingFeatureId, String message) {
12974 for (Phone phone : PhoneFactory.getPhones()) {
12975 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12976 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12977 return true;
12978 }
12979 }
12980 return false;
12981 }
arunvoddud7401012022-12-15 16:08:12 +000012982
12983 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012984 * @return The subscription manager service instance.
12985 */
12986 public SubscriptionManagerService getSubscriptionManagerService() {
12987 return SubscriptionManagerService.getInstance();
12988 }
12989
12990 /**
arunvoddud7401012022-12-15 16:08:12 +000012991 * Class binds the consumer[callback] and carrierId.
12992 */
12993 private static class CallerCallbackInfo {
12994 private final Consumer<Integer> mConsumer;
12995 private final int mCarrierId;
12996
12997 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12998 mConsumer = consumer;
12999 mCarrierId = carrierId;
13000 }
13001
13002 public Consumer<Integer> getConsumer() {
13003 return mConsumer;
13004 }
13005
13006 public int getCarrierId() {
13007 return mCarrierId;
13008 }
13009 }
Jack Yufa8ed012023-02-11 15:42:28 -080013010}