blob: 1ed6350139ff7bdd9635f0227286de553eb4e943 [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;
jimsunf9ec1622022-09-13 21:18:43 +080020import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080021
Shuo Qianccbaf742021-02-22 18:32:21 -080022import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
23import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070024import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070025import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000026import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070027
Brad Ebinger34c09a52021-02-17 23:23:21 +000028import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080030import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070031import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000032import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080034import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070035import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000036import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080037import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000038import android.compat.annotation.ChangeId;
39import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070040import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070041import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.content.Context;
43import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070044import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070045import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080054import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Looper;
56import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070057import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080058import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070059import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070060import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080061import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080062import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070063import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070064import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080065import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070067import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070069import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070070import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080071import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070072import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090073import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080074import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080075import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070076import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080077import android.telephony.AccessNetworkConstants;
78import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070079import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070080import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080081import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070082import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080083import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070084import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080085import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060086import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070087import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080088import android.telephony.CellIdentityCdma;
89import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070091import android.telephony.CellInfoGsm;
92import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070093import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080094import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070095import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070096import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070097import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080098import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070099import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700101import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800102import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800103import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700104import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800105import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800107import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800108import android.telephony.SignalStrengthUpdateRequest;
109import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800110import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800112import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700113import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700114import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800115import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800116import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800117import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800118import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000119import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000120import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000121import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700122import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700123import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800124import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800125import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700126import android.telephony.gba.GbaAuthRequest;
127import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700128import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000130import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000131import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700132import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000133import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700134import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800135import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700136import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800137import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700138import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000139import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700140import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800141import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800142import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700145import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800147import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Andrew Lee312e8172014-10-23 17:01:36 -0700149import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800150import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800151import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800152import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800153import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700155import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700156import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800157import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800158import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800161import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700162import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800163import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800164import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800165import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700166import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000167import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700168import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800169import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800172import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800173import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700174import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700175import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700176import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700178import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800179import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700180import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700181import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700182import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700183import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800184import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800185import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700186import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000187import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700188import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700189import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800190import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800191import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700193import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800194import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700195import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800196import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700197import com.android.internal.telephony.imsphone.ImsPhone;
198import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000199import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800200import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800201import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
202import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700203import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204import com.android.internal.telephony.uicc.IccIoResult;
205import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800206import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700207import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800208import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000210import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800211import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000212import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800213import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000214import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700215import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700216import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800217import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800218import com.android.phone.callcomposer.CallComposerPictureManager;
219import com.android.phone.callcomposer.CallComposerPictureTransfer;
220import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700221import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700222import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700223import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800224import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700225import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700226import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800227import com.android.services.telephony.TelecomAccountRegistry;
228import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800229import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800230
Hall Liu82694d52020-12-11 18:22:04 -0800231import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700232import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800233import java.io.IOException;
234import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700235import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000238import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800239import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800240import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800241import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800242import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100243import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800244import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700245import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800246import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800247import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700248import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800249import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800250import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800251import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
253/**
254 * Implementation of the ITelephony interface.
255 */
Santos Cordon117fee72014-05-16 17:56:12 -0700256public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257 private static final String LOG_TAG = "PhoneInterfaceManager";
258 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
259 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261
262 // Message codes used with mMainThreadHandler
263 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700264 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
265 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700266 private static final int CMD_OPEN_CHANNEL = 9;
267 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
268 private static final int CMD_CLOSE_CHANNEL = 11;
269 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800270 private static final int CMD_NV_READ_ITEM = 13;
271 private static final int EVENT_NV_READ_ITEM_DONE = 14;
272 private static final int CMD_NV_WRITE_ITEM = 15;
273 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
274 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
275 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700276 private static final int CMD_RESET_MODEM_CONFIG = 19;
277 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800278 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
279 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800280 private static final int CMD_SEND_ENVELOPE = 25;
281 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000282 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
283 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700284 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
285 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
286 private static final int CMD_EXCHANGE_SIM_IO = 31;
287 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800288 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
289 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700290 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
291 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700292 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
293 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700294 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
295 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
296 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
297 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700298 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
299 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
300 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
301 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700302 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800303 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
304 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000305 private static final int CMD_SWITCH_SLOTS = 50;
306 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700307 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
308 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
309 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
310 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
311 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
312 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
313 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
314 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700315 private static final int CMD_GET_ALL_CELL_INFO = 60;
316 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
317 private static final int CMD_GET_CELL_LOCATION = 62;
318 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700319 private static final int CMD_MODEM_REBOOT = 64;
320 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700321 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
322 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800323 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
324 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700325 private static final int CMD_GET_MODEM_STATUS = 70;
326 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700327 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
328 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700329 private static final int CMD_ERASE_MODEM_CONFIG = 74;
330 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800331 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
332 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
333 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
334 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800335 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
336 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800337 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800338 private static final int CMD_GET_CALL_FORWARDING = 83;
339 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
340 private static final int CMD_SET_CALL_FORWARDING = 85;
341 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
342 private static final int CMD_GET_CALL_WAITING = 87;
343 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
344 private static final int CMD_SET_CALL_WAITING = 89;
345 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700346 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
347 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
348 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
349 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700350 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
351 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800352 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
353 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800354 private static final int CMD_SET_DATA_THROTTLING = 99;
355 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800356 private static final int CMD_SET_SIM_POWER = 101;
357 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800358 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
359 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
360 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
361 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800362 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
363 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000364 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800365 private static final int CMD_GET_SLICING_CONFIG = 110;
366 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800367 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700368 private static final int CMD_ENABLE_VONR = 113;
369 private static final int EVENT_ENABLE_VONR_DONE = 114;
370 private static final int CMD_IS_VONR_ENABLED = 115;
371 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700372 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
373 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800375 // Parameters of select command.
376 private static final int SELECT_COMMAND = 0xA4;
377 private static final int SELECT_P1 = 0x04;
378 private static final int SELECT_P2 = 0;
379 private static final int SELECT_P3 = 0x10;
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 /** The singleton instance. */
382 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800383 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Wink Saville3ab207e2014-11-20 13:07:20 -0800385 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800386 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800387 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700388 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800389 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700390 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800391 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800392 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800393 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700394 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800395 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000396 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397
Peter Wangdafb9ac2020-01-15 14:13:38 -0800398 /** User Activity */
399 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800400 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
401
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700402 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
403
Derek Tan97ebb422014-09-05 16:55:38 -0700404 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
405 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800406 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800407 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700408
Michelecea4cf22018-12-21 15:00:11 -0800409 // String to store multi SIM allowed
410 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
411
Derek Tan740e1672017-06-27 14:56:27 -0700412 // The AID of ISD-R.
413 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
414
yinxub1bed742017-04-17 11:45:04 -0700415 private NetworkScanRequestTracker mNetworkScanRequestTracker;
416
David Kelly5e06a7f2018-03-12 14:10:59 +0000417 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
418 private static final int MANUFACTURER_CODE_LENGTH = 8;
419
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800420 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800421 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800422
Sarah Chin2ec39f62022-08-31 17:03:26 -0700423 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
424 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
425
Derek Tan89e89d42014-07-08 17:00:10 -0700426 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700427 * Experiment flag to enable erase modem config on reset network, default value is false
428 */
429 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
430 "reset_network_erase_modem_config_enabled";
431
Rambo Wang0f050d82021-02-12 11:43:36 -0800432 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800433
sandeepjsb6c87872021-09-27 15:34:44 +0000434 /**
435 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
436 * one ICCID active at the same time.
437 * Apps should use below API signatures if targeting SDK is T and beyond.
438 *
439 * @hide
440 */
441 @ChangeId
442 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
443 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800444
Naina Nallurid63128d2019-09-17 14:10:30 -0700445 /**
Chen Xu540470b2021-12-14 17:15:47 -0800446 * Apps targeting on Android T and beyond will get exception whenever icc close channel
447 * operation fails.
448 */
449 @ChangeId
450 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
451 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
452
453 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 * A request object to use for transmitting data to an ICC.
455 */
456 private static final class IccAPDUArgument {
457 public int channel, cla, command, p1, p2, p3;
458 public String data;
459
460 public IccAPDUArgument(int channel, int cla, int command,
461 int p1, int p2, int p3, String data) {
462 this.channel = channel;
463 this.cla = cla;
464 this.command = command;
465 this.p1 = p1;
466 this.p2 = p2;
467 this.p3 = p3;
468 this.data = data;
469 }
470 }
471
472 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700473 * A request object to use for transmitting data to an ICC.
474 */
475 private static final class ManualNetworkSelectionArgument {
476 public OperatorInfo operatorInfo;
477 public boolean persistSelection;
478
479 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
480 this.operatorInfo = operatorInfo;
481 this.persistSelection = persistSelection;
482 }
483 }
484
Sarah Chin71b3a852022-09-28 15:54:19 -0700485 private static final class PurchasePremiumCapabilityArgument {
486 public @TelephonyManager.PremiumCapability int capability;
487 public @NonNull String appName;
488 public @NonNull IIntegerConsumer callback;
489
490 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
491 @NonNull String appName, @NonNull IIntegerConsumer callback) {
492 this.capability = capability;
493 this.appName = appName;
494 this.callback = callback;
495 }
496 }
497
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700498 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
500 * request after sending. The main thread will notify the request when it is complete.
501 */
502 private static final class MainThreadRequest {
503 /** The argument to use for the request */
504 public Object argument;
505 /** The result of the request that is run on the main thread */
506 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800507 // The subscriber id that this request applies to. Defaults to
508 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
509 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510
Nathan Harold92bed182018-10-12 18:16:49 -0700511 // In cases where subId is unavailable, the caller needs to specify the phone.
512 public Phone phone;
513
vagdeviaf9a5b92018-08-15 16:01:53 -0700514 public WorkSource workSource;
515
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 public MainThreadRequest(Object argument) {
517 this.argument = argument;
518 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800519
Nathan Harold92bed182018-10-12 18:16:49 -0700520 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
521 this.argument = argument;
522 if (phone != null) {
523 this.phone = phone;
524 }
525 this.workSource = workSource;
526 }
527
vagdeviaf9a5b92018-08-15 16:01:53 -0700528 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800529 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800530 if (subId != null) {
531 this.subId = subId;
532 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700533 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 }
536
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800537 private static final class IncomingThirdPartyCallArgs {
538 public final ComponentName component;
539 public final String callId;
540 public final String callerDisplayName;
541
542 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
543 String callerDisplayName) {
544 this.component = component;
545 this.callId = callId;
546 this.callerDisplayName = callerDisplayName;
547 }
548 }
549
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 /**
551 * A handler that processes messages on the main thread in the phone process. Since many
552 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
553 * inbound binder threads to the main thread in the phone process. The Binder thread
554 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
555 * on, which will be notified when the operation completes and will contain the result of the
556 * request.
557 *
558 * <p>If a MainThreadRequest object is provided in the msg.obj field,
559 * note that request.result must be set to something non-null for the calling thread to
560 * unblock.
561 */
562 private final class MainThreadHandler extends Handler {
563 @Override
564 public void handleMessage(Message msg) {
565 MainThreadRequest request;
566 Message onCompleted;
567 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000568 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800570 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571
572 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 case CMD_HANDLE_USSD_REQUEST: {
574 request = (MainThreadRequest) msg.obj;
575 final Phone phone = getPhoneFromRequest(request);
576 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800577 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700579
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 if (!isUssdApiAllowed(request.subId)) {
581 // Carrier does not support use of this API, return failure.
582 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
583 UssdResponse response = new UssdResponse(ussdRequest, null);
584 Bundle returnData = new Bundle();
585 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
586 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700587
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 request.result = true;
589 notifyRequester(request);
590 return;
591 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700592
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 try {
594 request.result = phone != null
595 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
596 } catch (CallStateException cse) {
597 request.result = false;
598 }
599 // Wake up the requesting thread
600 notifyRequester(request);
601 break;
pkanwar32d516d2016-10-14 19:37:38 -0700602 }
603
Yorke Lee716f67e2015-06-17 15:39:16 -0700604 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700606 final Phone phone = getPhoneFromRequest(request);
607 request.result = phone != null ?
608 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
609 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700610 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000618 uiccPort = getUiccPortFromRequest(request);
619 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800621 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800625 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000626 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800627 iccArgument.channel, iccArgument.cla, iccArgument.command,
628 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
629 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 break;
632
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 ar = (AsyncResult) msg.obj;
635 request = (MainThreadRequest) ar.userObj;
636 if (ar.exception == null && ar.result != null) {
637 request.result = ar.result;
638 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800639 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.result == null) {
641 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800642 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800644 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
646 loge("iccTransmitApduLogicalChannel: Unknown exception");
647 }
648 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
653 request = (MainThreadRequest) msg.obj;
654 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000655 uiccPort = getUiccPortFromRequest(request);
656 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800658 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 } else {
661 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800662 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000663 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800664 iccArgument.cla, iccArgument.command, iccArgument.p1,
665 iccArgument.p2,
666 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 }
668 break;
669
670 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
671 ar = (AsyncResult) msg.obj;
672 request = (MainThreadRequest) ar.userObj;
673 if (ar.exception == null && ar.result != null) {
674 request.result = ar.result;
675 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800676 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 if (ar.result == null) {
678 loge("iccTransmitApduBasicChannel: Empty response");
679 } else if (ar.exception instanceof CommandException) {
680 loge("iccTransmitApduBasicChannel: CommandException: " +
681 ar.exception);
682 } else {
683 loge("iccTransmitApduBasicChannel: Unknown exception");
684 }
685 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 break;
688
689 case CMD_EXCHANGE_SIM_IO:
690 request = (MainThreadRequest) msg.obj;
691 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 uiccPort = getUiccPortFromRequest(request);
693 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800695 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
699 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000700 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
702 iccArgument.data, onCompleted);
703 }
704 break;
705
706 case EVENT_EXCHANGE_SIM_IO_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
709 if (ar.exception == null && ar.result != null) {
710 request.result = ar.result;
711 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800712 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 break;
716
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 case CMD_SEND_ENVELOPE:
718 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000719 uiccPort = getUiccPortFromRequest(request);
720 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800722 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700723 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 } else {
725 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800726 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800728 break;
729
730 case EVENT_SEND_ENVELOPE_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800735 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800736 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700737 if (ar.result == null) {
738 loge("sendEnvelopeWithStatus: Empty response");
739 } else if (ar.exception instanceof CommandException) {
740 loge("sendEnvelopeWithStatus: CommandException: " +
741 ar.exception);
742 } else {
743 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
744 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800747 break;
748
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 case CMD_OPEN_CHANNEL:
750 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000751 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800752 IccLogicalChannelRequest openChannelRequest =
753 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000754 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700755 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800756 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800757 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700759 } else {
760 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800761 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
762 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700763 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 break;
765
766 case EVENT_OPEN_CHANNEL_DONE:
767 ar = (AsyncResult) msg.obj;
768 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700769 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700771 int[] result = (int[]) ar.result;
772 int channelId = result[0];
773 byte[] selectResponse = null;
774 if (result.length > 1) {
775 selectResponse = new byte[result.length - 1];
776 for (int i = 1; i < result.length; ++i) {
777 selectResponse[i - 1] = (byte) result[i];
778 }
779 }
780 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800782
783 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700784 if (uiccPort == null) {
785 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
786 } else {
787 IccLogicalChannelRequest channelRequest =
788 (IccLogicalChannelRequest) request.argument;
789 channelRequest.channel = channelId;
790 uiccPort.onLogicalChannelOpened(channelRequest);
791 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 if (ar.result == null) {
794 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700796 if (ar.exception != null) {
797 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
798 }
799
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700800 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700801 if (ar.exception instanceof CommandException) {
802 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800803 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700804 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700805 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700806 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700807 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700808 }
809 }
810 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800811 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700813 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700814 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 break;
816
817 case CMD_CLOSE_CHANNEL:
818 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000819 uiccPort = getUiccPortFromRequest(request);
820 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700821 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800822 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800823 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800824 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700825 } else {
826 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000827 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700828 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700829 break;
830
831 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 if (ar.exception == null) {
835 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800836 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700837 if (uiccPort == null) {
838 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
839 } else {
840 final int channelId = (Integer) request.argument;
841 uiccPort.onLogicalChannelClosed(channelId);
842 }
Chen Xu540470b2021-12-14 17:15:47 -0800843 } else {
844 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800845 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800846 if (ar.exception instanceof CommandException) {
847 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
848 CommandException.Error error =
849 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800850 if (error == CommandException.Error.INVALID_ARGUMENTS) {
851 // should only throw exceptions from the binder threads.
852 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800853 "iccCloseLogicalChannel: invalid argument ");
854 }
855 } else {
856 loge("iccCloseLogicalChannel: Unknown exception");
857 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800858 request.result = (exception != null) ? exception :
859 new IllegalStateException(
860 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800861 }
862 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800863 break;
864
865 case CMD_NV_READ_ITEM:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800868 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
869 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800870 break;
871
872 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700873 ar = (AsyncResult) msg.obj;
874 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800875 if (ar.exception == null && ar.result != null) {
876 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800878 request.result = "";
879 if (ar.result == null) {
880 loge("nvReadItem: Empty response");
881 } else if (ar.exception instanceof CommandException) {
882 loge("nvReadItem: CommandException: " +
883 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700884 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800885 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700886 }
887 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700888 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700889 break;
890
Jake Hambye994d462014-02-03 13:10:13 -0800891 case CMD_NV_WRITE_ITEM:
892 request = (MainThreadRequest) msg.obj;
893 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
894 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800895 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700896 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800897 break;
898
899 case EVENT_NV_WRITE_ITEM_DONE:
900 handleNullReturnEvent(msg, "nvWriteItem");
901 break;
902
903 case CMD_NV_WRITE_CDMA_PRL:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800907 break;
908
909 case EVENT_NV_WRITE_CDMA_PRL_DONE:
910 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
911 break;
912
chen xu6dac5ab2018-10-26 17:39:23 -0700913 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800914 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700915 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
chen xu6dac5ab2018-10-26 17:39:23 -0700919 case EVENT_RESET_MODEM_CONFIG_DONE:
920 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800921 break;
922
Sooraj Sasindran37444802020-08-11 10:40:43 -0700923 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
926 request);
927 Phone phone = getPhoneFromRequest(request);
928 if (phone != null) {
929 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
930 } else {
931 loge("isNRDualConnectivityEnabled: No phone object");
932 request.result = false;
933 notifyRequester(request);
934 }
935 break;
936 }
937
938 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
939 ar = (AsyncResult) msg.obj;
940 request = (MainThreadRequest) ar.userObj;
941 if (ar.exception == null && ar.result != null) {
942 request.result = ar.result;
943 } else {
944 // request.result must be set to something non-null
945 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700946 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700947 request.result = ar.result;
948 } else {
949 request.result = false;
950 }
951 if (ar.result == null) {
952 loge("isNRDualConnectivityEnabled: Empty response");
953 } else if (ar.exception instanceof CommandException) {
954 loge("isNRDualConnectivityEnabled: CommandException: "
955 + ar.exception);
956 } else {
957 loge("isNRDualConnectivityEnabled: Unknown exception");
958 }
959 }
960 notifyRequester(request);
961 break;
962
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700963 case CMD_IS_VONR_ENABLED: {
964 request = (MainThreadRequest) msg.obj;
965 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
966 request);
967 Phone phone = getPhoneFromRequest(request);
968 if (phone != null) {
969 phone.isVoNrEnabled(onCompleted, request.workSource);
970 } else {
971 loge("isVoNrEnabled: No phone object");
972 request.result = false;
973 notifyRequester(request);
974 }
975 break;
976 }
977
978 case EVENT_IS_VONR_ENABLED_DONE:
979 ar = (AsyncResult) msg.obj;
980 request = (MainThreadRequest) ar.userObj;
981 if (ar.exception == null && ar.result != null) {
982 request.result = ar.result;
983 } else {
984 // request.result must be set to something non-null
985 // for the calling thread to unblock
986 if (ar.result != null) {
987 request.result = ar.result;
988 } else {
989 request.result = false;
990 }
991 if (ar.result == null) {
992 loge("isVoNrEnabled: Empty response");
993 } else if (ar.exception instanceof CommandException) {
994 loge("isVoNrEnabled: CommandException: "
995 + ar.exception);
996 } else {
997 loge("isVoNrEnabled: Unknown exception");
998 }
999 }
1000 notifyRequester(request);
1001 break;
1002
Sooraj Sasindran37444802020-08-11 10:40:43 -07001003 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1006 Phone phone = getPhoneFromRequest(request);
1007 if (phone != null) {
1008 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1009 request.workSource);
1010 } else {
1011 loge("enableNrDualConnectivity: No phone object");
1012 request.result =
1013 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1014 notifyRequester(request);
1015 }
1016 break;
1017 }
1018
1019 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception == null) {
1023 request.result =
1024 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1025 } else {
1026 request.result =
1027 TelephonyManager
1028 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1029 if (ar.exception instanceof CommandException) {
1030 CommandException.Error error =
1031 ((CommandException) (ar.exception)).getCommandError();
1032 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1033 request.result =
1034 TelephonyManager
1035 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001036 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1037 request.result =
1038 TelephonyManager
1039 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001040 }
1041 loge("enableNrDualConnectivity" + ": CommandException: "
1042 + ar.exception);
1043 } else {
1044 loge("enableNrDualConnectivity" + ": Unknown exception");
1045 }
1046 }
1047 notifyRequester(request);
1048 break;
1049 }
1050
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001051 case CMD_ENABLE_VONR: {
1052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1054 Phone phone = getPhoneFromRequest(request);
1055 if (phone != null) {
1056 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1057 request.workSource);
1058 } else {
1059 loge("setVoNrEnabled: No phone object");
1060 request.result =
1061 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1062 notifyRequester(request);
1063 }
1064 break;
1065 }
1066
1067 case EVENT_ENABLE_VONR_DONE: {
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
1070 if (ar.exception == null) {
1071 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1072 } else {
1073 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1074 if (ar.exception instanceof CommandException) {
1075 CommandException.Error error =
1076 ((CommandException) (ar.exception)).getCommandError();
1077 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1078 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1079 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1080 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1081 } else {
1082 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1083 }
1084 loge("setVoNrEnabled" + ": CommandException: "
1085 + ar.exception);
1086 } else {
1087 loge("setVoNrEnabled" + ": Unknown exception");
1088 }
1089 }
1090 notifyRequester(request);
1091 break;
1092 }
1093
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001095 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1097 request);
1098 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001099 break;
1100
SongFerngWang3ef3e072020-12-21 16:41:52 +08001101 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
1104 if (ar.exception == null && ar.result != null) {
1105 request.result = ar.result; // Integer
1106 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301107 // request.result must be set to something non-null
1108 // for the calling thread to unblock
1109 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001111 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001112 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001113 loge("getAllowedNetworkTypesBitmask: CommandException: "
1114 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 }
1118 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001119 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 break;
1121
SongFerngWang3ef3e072020-12-21 16:41:52 +08001122 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001124 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1125 request);
1126 Pair<Integer, Long> reasonWithNetworkTypes =
1127 (Pair<Integer, Long>) request.argument;
1128 getPhoneFromRequest(request).setAllowedNetworkTypes(
1129 reasonWithNetworkTypes.first,
1130 reasonWithNetworkTypes.second,
1131 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001132 break;
1133
SongFerngWang3ef3e072020-12-21 16:41:52 +08001134 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1135 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 break;
1137
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001138 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1139 request = (MainThreadRequest)msg.obj;
1140 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001141 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001142 break;
1143
1144 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1145 ar = (AsyncResult)msg.obj;
1146 request = (MainThreadRequest)ar.userObj;
1147 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001148 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001149 break;
1150
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001151 case CMD_SET_VOICEMAIL_NUMBER:
1152 request = (MainThreadRequest) msg.obj;
1153 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1154 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001155 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1156 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001157 break;
1158
1159 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1160 handleNullReturnEvent(msg, "setVoicemailNumber");
1161 break;
1162
Stuart Scott54788802015-03-30 13:18:01 -07001163 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1164 request = (MainThreadRequest) msg.obj;
1165 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1166 request);
1167 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1168 break;
1169
1170 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1171 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1172 break;
1173
Shishir Agrawal302c8692015-06-19 13:49:39 -07001174 case CMD_PERFORM_NETWORK_SCAN:
1175 request = (MainThreadRequest) msg.obj;
1176 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1177 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1178 break;
1179
Hall Liu27d24262020-09-18 19:04:59 -07001180 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001181 request = (MainThreadRequest) msg.obj;
1182 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001183 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1184 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1185 request.argument;
1186 int callForwardingReason = args.first;
1187 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001188 break;
Hall Liu27d24262020-09-18 19:04:59 -07001189 }
1190 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001191 ar = (AsyncResult) msg.obj;
1192 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001193 TelephonyManager.CallForwardingInfoCallback callback =
1194 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1195 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001197 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1199 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1200 // Service Class is a bit mask per 3gpp 27.007. Search for
1201 // any service for voice call.
1202 if ((callForwardInfo.serviceClass
1203 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001204 callForwardingInfo = new CallForwardingInfo(
1205 callForwardInfo.status
1206 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001207 callForwardInfo.reason,
1208 callForwardInfo.number,
1209 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 break;
1211 }
1212 }
1213 // Didn't find a call forward info for voice call.
1214 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001215 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1216 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001217 }
Hall Liu27d24262020-09-18 19:04:59 -07001218 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001219 } else {
1220 if (ar.result == null) {
1221 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1222 }
1223 if (ar.exception != null) {
1224 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1225 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001226 int errorCode = TelephonyManager
1227 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 if (ar.exception instanceof CommandException) {
1229 CommandException.Error error =
1230 ((CommandException) (ar.exception)).getCommandError();
1231 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001232 errorCode = TelephonyManager
1233 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001234 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001235 errorCode = TelephonyManager
1236 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001237 }
1238 }
Hall Liu27d24262020-09-18 19:04:59 -07001239 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001240 }
Shuo Qian4a594052020-01-23 11:59:30 -08001241 break;
Hall Liu27d24262020-09-18 19:04:59 -07001242 }
Shuo Qian4a594052020-01-23 11:59:30 -08001243
Hall Liu27d24262020-09-18 19:04:59 -07001244 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001245 request = (MainThreadRequest) msg.obj;
1246 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001247 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001248 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001249 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1250 request.argument).first;
1251 request.phone.setCallForwardingOption(
1252 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001253 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001254 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001255 callForwardingInfoToSet.getReason(),
1256 callForwardingInfoToSet.getNumber(),
1257 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260
Hall Liu27d24262020-09-18 19:04:59 -07001261 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001264 Consumer<Integer> callback =
1265 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1266 request.argument).second;
1267 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 int errorCode = TelephonyManager.CallForwardingInfoCallback
1270 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001271 if (ar.exception instanceof CommandException) {
1272 CommandException.Error error =
1273 ((CommandException) (ar.exception)).getCommandError();
1274 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 errorCode = TelephonyManager.CallForwardingInfoCallback
1276 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001277 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001278 errorCode = TelephonyManager.CallForwardingInfoCallback
1279 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
1281 }
1282 callback.accept(errorCode);
1283 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001284 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286 break;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
Shuo Qian4a594052020-01-23 11:59:30 -08001288
Hall Liu27d24262020-09-18 19:04:59 -07001289 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 request = (MainThreadRequest) msg.obj;
1291 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1292 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1293 break;
Hall Liu27d24262020-09-18 19:04:59 -07001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295
Hall Liu27d24262020-09-18 19:04:59 -07001296 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 ar = (AsyncResult) msg.obj;
1298 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001299 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001300 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001301 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001302 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001303 // Service Class is a bit mask per 3gpp 27.007.
1304 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001305 if (callForwardResults.length > 1
1306 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001307 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001308 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001309 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1310 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001311 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001312 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001313 }
1314 } else {
1315 if (ar.result == null) {
1316 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1317 }
1318 if (ar.exception != null) {
1319 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1320 }
1321 if (ar.exception instanceof CommandException) {
1322 CommandException.Error error =
1323 ((CommandException) (ar.exception)).getCommandError();
1324 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001325 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001326 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001327 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1328 callWaitingStatus =
1329 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001330 }
1331 }
1332 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001334 break;
Hall Liu27d24262020-09-18 19:04:59 -07001335 }
Shuo Qian4a594052020-01-23 11:59:30 -08001336
Hall Liu27d24262020-09-18 19:04:59 -07001337 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001338 request = (MainThreadRequest) msg.obj;
1339 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001340 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1341 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001342 break;
Hall Liu27d24262020-09-18 19:04:59 -07001343 }
Shuo Qian4a594052020-01-23 11:59:30 -08001344
Hall Liu27d24262020-09-18 19:04:59 -07001345 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001346 ar = (AsyncResult) msg.obj;
1347 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001348 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1349 Consumer<Integer> callback =
1350 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1351 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001352 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001353 if (ar.exception instanceof CommandException) {
1354 CommandException.Error error =
1355 ((CommandException) (ar.exception)).getCommandError();
1356 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1357 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001358 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1359 callback.accept(
1360 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001361 } else {
1362 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1363 }
1364 } else {
1365 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1366 }
1367 } else {
1368 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1369 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001370 }
Shuo Qian4a594052020-01-23 11:59:30 -08001371 break;
Hall Liu27d24262020-09-18 19:04:59 -07001372 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001373 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
1376 CellNetworkScanResult cellScanResult;
1377 if (ar.exception == null && ar.result != null) {
1378 cellScanResult = new CellNetworkScanResult(
1379 CellNetworkScanResult.STATUS_SUCCESS,
1380 (List<OperatorInfo>) ar.result);
1381 } else {
1382 if (ar.result == null) {
1383 loge("getCellNetworkScanResults: Empty response");
1384 }
1385 if (ar.exception != null) {
1386 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1387 }
1388 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1389 if (ar.exception instanceof CommandException) {
1390 CommandException.Error error =
1391 ((CommandException) (ar.exception)).getCommandError();
1392 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1393 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1394 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1395 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1396 }
1397 }
1398 cellScanResult = new CellNetworkScanResult(errorCode, null);
1399 }
1400 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001401 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001402 break;
1403
1404 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1405 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001406 ManualNetworkSelectionArgument selArg =
1407 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001408 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1409 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001410 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1411 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001412 break;
1413
1414 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001415 ar = (AsyncResult) msg.obj;
1416 request = (MainThreadRequest) ar.userObj;
1417 if (ar.exception == null) {
1418 request.result = true;
1419 } else {
1420 request.result = false;
1421 loge("setNetworkSelectionModeManual " + ar.exception);
1422 }
1423 notifyRequester(request);
1424 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001425 break;
1426
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001427 case CMD_GET_MODEM_ACTIVITY_INFO:
1428 request = (MainThreadRequest) msg.obj;
1429 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001430 if (defaultPhone != null) {
1431 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001432 } else {
1433 ResultReceiver result = (ResultReceiver) request.argument;
1434 Bundle bundle = new Bundle();
1435 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001436 new ModemActivityInfo(0, 0, 0,
1437 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001439 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001440 break;
1441
Hall Liud0f208c2020-10-14 16:54:44 -07001442 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001445 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001446 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001447 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001448 if (mLastModemActivityInfo == null) {
1449 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1450 mLastModemActivitySpecificInfo[0] =
1451 new ActivityStatsTechSpecificInfo(
1452 0,
1453 0,
1454 new int[ModemActivityInfo.getNumTxPowerLevels()],
1455 0);
1456 mLastModemActivityInfo =
1457 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1458 }
1459
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001461 // Update the last modem activity info and the result of the request.
1462 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1463 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001464 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 }
Kai Shi917fdc62022-11-28 14:01:02 -08001466 // This is needed to decouple ret from mLastModemActivityInfo
1467 // We don't want to return mLastModemActivityInfo which is updated
1468 // inside mergeModemActivityInfo()
1469 ret = new ModemActivityInfo(
1470 mLastModemActivityInfo.getTimestampMillis(),
1471 mLastModemActivityInfo.getSleepTimeMillis(),
1472 mLastModemActivityInfo.getIdleTimeMillis(),
1473 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001474
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 } else {
1476 if (ar.result == null) {
1477 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001478 error = TelephonyManager.ModemActivityInfoException
1479 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001480 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001481 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001482 error = TelephonyManager.ModemActivityInfoException
1483 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001484 } else {
1485 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001486 error = TelephonyManager.ModemActivityInfoException
1487 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 }
1489 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001490 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001491 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001492 bundle.putParcelable(
1493 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001494 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001495 } else {
1496 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1497 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001498 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001499 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001500 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001501 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001502
Meng Wang1a7c35a2016-05-05 20:56:15 -07001503 case CMD_SET_ALLOWED_CARRIERS:
1504 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001505 CarrierRestrictionRules argument =
1506 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001507 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001508 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001509 break;
1510
1511 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 if (ar.exception == null && ar.result != null) {
1515 request.result = ar.result;
1516 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001517 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1518 if (ar.exception instanceof CommandException) {
1519 loge("setAllowedCarriers: CommandException: " + ar.exception);
1520 CommandException.Error error =
1521 ((CommandException) (ar.exception)).getCommandError();
1522 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1523 request.result =
1524 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1525 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 } else {
1527 loge("setAllowedCarriers: Unknown exception");
1528 }
1529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001530 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531 break;
1532
1533 case CMD_GET_ALLOWED_CARRIERS:
1534 request = (MainThreadRequest) msg.obj;
1535 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001536 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 break;
1538
1539 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1540 ar = (AsyncResult) msg.obj;
1541 request = (MainThreadRequest) ar.userObj;
1542 if (ar.exception == null && ar.result != null) {
1543 request.result = ar.result;
1544 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001545 request.result = new IllegalStateException(
1546 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 if (ar.result == null) {
1548 loge("getAllowedCarriers: Empty response");
1549 } else if (ar.exception instanceof CommandException) {
1550 loge("getAllowedCarriers: CommandException: " +
1551 ar.exception);
1552 } else {
1553 loge("getAllowedCarriers: Unknown exception");
1554 }
1555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001556 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001557 break;
1558
Nathan Haroldb3014052017-01-25 15:57:32 -08001559 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 if (ar.exception == null && ar.result != null) {
1563 request.result = ar.result;
1564 } else {
1565 request.result = new IllegalArgumentException(
1566 "Failed to retrieve Forbidden Plmns");
1567 if (ar.result == null) {
1568 loge("getForbiddenPlmns: Empty response");
1569 } else {
1570 loge("getForbiddenPlmns: Unknown exception");
1571 }
1572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001574 break;
1575
1576 case CMD_GET_FORBIDDEN_PLMNS:
1577 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001578 uiccPort = getUiccPortFromRequest(request);
1579 if (uiccPort == null) {
1580 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001581 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001582 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001583 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001584 break;
1585 }
1586 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001587 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001588 if (uiccApp == null) {
1589 loge("getForbiddenPlmns() no app with specified type -- "
1590 + appType);
1591 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001592 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001593 break;
1594 } else {
1595 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1596 + " specified type -- " + appType);
1597 }
1598 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1599 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1600 onCompleted);
1601 break;
1602
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001603 case CMD_SWITCH_SLOTS:
1604 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001605 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001606 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001607 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001608 break;
1609
1610 case EVENT_SWITCH_SLOTS_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001614 notifyRequester(request);
1615 break;
1616 case CMD_GET_NETWORK_SELECTION_MODE:
1617 request = (MainThreadRequest) msg.obj;
1618 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1619 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1620 break;
1621
1622 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 if (ar.exception != null) {
1626 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1627 } else {
1628 int mode = ((int[]) ar.result)[0];
1629 if (mode == 0) {
1630 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1631 } else {
1632 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1633 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001634 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001635 notifyRequester(request);
1636 break;
1637 case CMD_GET_CDMA_ROAMING_MODE:
1638 request = (MainThreadRequest) msg.obj;
1639 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1640 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1641 break;
1642 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1643 ar = (AsyncResult) msg.obj;
1644 request = (MainThreadRequest) ar.userObj;
1645 if (ar.exception != null) {
1646 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1647 } else {
1648 request.result = ((int[]) ar.result)[0];
1649 }
1650 notifyRequester(request);
1651 break;
1652 case CMD_SET_CDMA_ROAMING_MODE:
1653 request = (MainThreadRequest) msg.obj;
1654 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1655 int mode = (int) request.argument;
1656 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1657 break;
1658 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 request.result = ar.exception == null;
1662 notifyRequester(request);
1663 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001664 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1667 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1668 break;
1669 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1670 ar = (AsyncResult) msg.obj;
1671 request = (MainThreadRequest) ar.userObj;
1672 if (ar.exception != null) {
1673 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1674 } else {
1675 request.result = ((int[]) ar.result)[0];
1676 }
1677 notifyRequester(request);
1678 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001679 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1682 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001683 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1684 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001685 break;
1686 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1687 ar = (AsyncResult) msg.obj;
1688 request = (MainThreadRequest) ar.userObj;
1689 request.result = ar.exception == null;
1690 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001691 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001692 case CMD_GET_ALL_CELL_INFO:
1693 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001695 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 case EVENT_GET_ALL_CELL_INFO_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001700 // If a timeout occurs, the response will be null
1701 request.result = (ar.exception == null && ar.result != null)
1702 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 synchronized (request) {
1704 request.notifyAll();
1705 }
1706 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001707 case CMD_REQUEST_CELL_INFO_UPDATE:
1708 request = (MainThreadRequest) msg.obj;
1709 request.phone.requestCellInfoUpdate(request.workSource,
1710 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1711 break;
1712 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1716 try {
1717 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001718 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001719 cb.onError(
1720 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1721 ar.exception.getClass().getName(),
1722 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001723 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001724 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001725 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001726 } else {
1727 // use the result as returned
1728 cb.onCellInfo((List<CellInfo>) ar.result);
1729 }
1730 } catch (RemoteException re) {
1731 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1732 }
1733 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001734 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001735 request = (MainThreadRequest) msg.obj;
1736 WorkSource ws = (WorkSource) request.argument;
1737 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001738 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 }
1741 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 if (ar.exception == null) {
1745 request.result = ar.result;
1746 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001747 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001748 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001749 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001750 }
1751
1752 synchronized (request) {
1753 request.notifyAll();
1754 }
1755 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001756 }
chen xu6dac5ab2018-10-26 17:39:23 -07001757 case CMD_MODEM_REBOOT:
1758 request = (MainThreadRequest) msg.obj;
1759 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001760 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001761 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001762 case EVENT_CMD_MODEM_REBOOT_DONE:
1763 handleNullReturnEvent(msg, "rebootModem");
1764 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001765 case CMD_REQUEST_ENABLE_MODEM:
1766 request = (MainThreadRequest) msg.obj;
1767 boolean enable = (boolean) request.argument;
1768 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001769 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001770 PhoneConfigurationManager.getInstance()
1771 .enablePhone(request.phone, enable, onCompleted);
1772 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001773 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001774 ar = (AsyncResult) msg.obj;
1775 request = (MainThreadRequest) ar.userObj;
1776 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001777 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001778 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001779 if ((boolean) request.result) {
1780 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1781 updateModemStateMetrics();
1782 } else {
1783 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1784 + ar.exception);
1785 }
1786 notifyRequester(request);
1787 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001788 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001789 case CMD_GET_MODEM_STATUS:
1790 request = (MainThreadRequest) msg.obj;
1791 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1792 PhoneConfigurationManager.getInstance()
1793 .getPhoneStatusFromModem(request.phone, onCompleted);
1794 break;
1795 case EVENT_GET_MODEM_STATUS_DONE:
1796 ar = (AsyncResult) msg.obj;
1797 request = (MainThreadRequest) ar.userObj;
1798 int id = request.phone.getPhoneId();
1799 if (ar.exception == null && ar.result != null) {
1800 request.result = ar.result;
1801 //update the cache as modem status has changed
1802 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1803 (boolean) request.result);
1804 } else {
1805 // Return true if modem status cannot be retrieved. For most cases,
1806 // modem status is on. And for older version modems, GET_MODEM_STATUS
1807 // and disable modem are not supported. Modem is always on.
1808 // TODO: this should be fixed in R to support a third
1809 // status UNKNOWN b/131631629
1810 request.result = true;
1811 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1812 + ar.exception);
1813 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001814 notifyRequester(request);
1815 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001816 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1817 request = (MainThreadRequest) msg.obj;
1818 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1819 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1820 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1821 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1822 break;
1823 }
1824 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1825 ar = (AsyncResult) msg.obj;
1826 request = (MainThreadRequest) ar.userObj;
1827 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1828 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1829 args.second.accept(ar.exception == null);
1830 notifyRequester(request);
1831 break;
1832 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001833 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1836 Phone phone = getPhoneFromRequest(request);
1837 if (phone != null) {
1838 phone.getSystemSelectionChannels(onCompleted);
1839 } else {
1840 loge("getSystemSelectionChannels: No phone object");
1841 request.result = new ArrayList<RadioAccessSpecifier>();
1842 notifyRequester(request);
1843 }
1844 break;
1845 }
1846 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1847 ar = (AsyncResult) msg.obj;
1848 request = (MainThreadRequest) ar.userObj;
1849 if (ar.exception == null && ar.result != null) {
1850 request.result = ar.result;
1851 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001852 request.result = new IllegalStateException(
1853 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001854 if (ar.result == null) {
1855 loge("getSystemSelectionChannels: Empty response");
1856 } else {
1857 loge("getSystemSelectionChannels: Unknown exception");
1858 }
1859 }
1860 notifyRequester(request);
1861 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001862 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1863 ar = (AsyncResult) msg.obj;
1864 request = (MainThreadRequest) ar.userObj;
1865 if (ar.exception == null && ar.result != null) {
1866 request.result = ar.result;
1867 } else {
1868 request.result = -1;
1869 loge("Failed to set Forbidden Plmns");
1870 if (ar.result == null) {
1871 loge("setForbidenPlmns: Empty response");
1872 } else if (ar.exception != null) {
1873 loge("setForbiddenPlmns: Exception: " + ar.exception);
1874 request.result = -1;
1875 } else {
1876 loge("setForbiddenPlmns: Unknown exception");
1877 }
1878 }
1879 notifyRequester(request);
1880 break;
1881 case CMD_SET_FORBIDDEN_PLMNS:
1882 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001883 uiccPort = getUiccPortFromRequest(request);
1884 if (uiccPort == null) {
1885 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001886 request.result = -1;
1887 notifyRequester(request);
1888 break;
1889 }
1890 Pair<Integer, List<String>> setFplmnsArgs =
1891 (Pair<Integer, List<String>>) request.argument;
1892 appType = setFplmnsArgs.first;
1893 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001894 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001895 if (uiccApp == null) {
1896 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1897 request.result = -1;
1898 loge("Failed to get UICC App");
1899 notifyRequester(request);
1900 } else {
1901 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1902 ((SIMRecords) uiccApp.getIccRecords())
1903 .setForbiddenPlmns(onCompleted, fplmns);
1904 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001905 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001906 case CMD_ERASE_MODEM_CONFIG:
1907 request = (MainThreadRequest) msg.obj;
1908 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1909 defaultPhone.eraseModemConfig(onCompleted);
1910 break;
1911 case EVENT_ERASE_MODEM_CONFIG_DONE:
1912 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001913 break;
zoey chene02881a2019-12-30 16:11:23 +08001914
Kai Shif70f46f2021-03-03 13:59:46 -08001915 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1916 request = (MainThreadRequest) msg.obj;
1917 request.result = defaultPhone.eraseDataInSharedPreferences();
1918 notifyRequester(request);
1919 break;
1920
zoey chene02881a2019-12-30 16:11:23 +08001921 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1922 request = (MainThreadRequest) msg.obj;
1923 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1924 Pair<String, String> changed = (Pair<String, String>) request.argument;
1925 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1926 changed.first, changed.second, onCompleted);
1927 break;
1928 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1929 ar = (AsyncResult) msg.obj;
1930 request = (MainThreadRequest) ar.userObj;
1931 if (ar.exception == null) {
1932 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001933 // If the operation is successful, update the PIN storage
1934 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1935 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001936 UiccController.getInstance().getPinStorage()
1937 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001938 } else {
1939 request.result = msg.arg1;
1940 }
1941 notifyRequester(request);
1942 break;
1943
Michele Berionne5e411512020-11-13 02:36:59 +00001944 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001945 request = (MainThreadRequest) msg.obj;
1946 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1947 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1948 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1949 enabled.first, enabled.second, onCompleted);
1950 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001951 }
zoey chene02881a2019-12-30 16:11:23 +08001952 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1953 ar = (AsyncResult) msg.obj;
1954 request = (MainThreadRequest) ar.userObj;
1955 if (ar.exception == null) {
1956 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001957 // If the operation is successful, update the PIN storage
1958 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1959 int phoneId = getPhoneFromRequest(request).getPhoneId();
1960 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001961 UiccController.getInstance().getPinStorage()
1962 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001963 } else {
1964 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1965 }
zoey chene02881a2019-12-30 16:11:23 +08001966 } else {
1967 request.result = msg.arg1;
1968 }
Michele Berionne5e411512020-11-13 02:36:59 +00001969
1970
zoey chene02881a2019-12-30 16:11:23 +08001971 notifyRequester(request);
1972 break;
1973
Peter Wangdafb9ac2020-01-15 14:13:38 -08001974 case MSG_NOTIFY_USER_ACTIVITY:
1975 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001976 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001977 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1978 getDefaultPhone().getContext().sendBroadcastAsUser(
1979 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1980 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001981
1982 case CMD_SET_DATA_THROTTLING: {
1983 request = (MainThreadRequest) msg.obj;
1984 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1985 DataThrottlingRequest dataThrottlingRequest =
1986 (DataThrottlingRequest) request.argument;
1987 Phone phone = getPhoneFromRequest(request);
1988 if (phone != null) {
1989 phone.setDataThrottling(onCompleted,
1990 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1991 dataThrottlingRequest.getCompletionDurationMillis());
1992 } else {
1993 loge("setDataThrottling: No phone object");
1994 request.result =
1995 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1996 notifyRequester(request);
1997 }
1998
1999 break;
2000 }
2001 case EVENT_SET_DATA_THROTTLING_DONE:
2002 ar = (AsyncResult) msg.obj;
2003 request = (MainThreadRequest) ar.userObj;
2004
2005 if (ar.exception == null) {
2006 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2007 } else if (ar.exception instanceof CommandException) {
2008 loge("setDataThrottling: CommandException: " + ar.exception);
2009 CommandException.Error error =
2010 ((CommandException) (ar.exception)).getCommandError();
2011
2012 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2013 request.result = TelephonyManager
2014 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2015 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2016 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2018 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002019 } else {
2020 request.result =
2021 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2022 }
2023 } else {
2024 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2025 }
2026 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2027 notifyRequester(request);
2028 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002029
2030 case CMD_SET_SIM_POWER: {
2031 request = (MainThreadRequest) msg.obj;
2032 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2033 request = (MainThreadRequest) msg.obj;
2034 int stateToSet =
2035 ((Pair<Integer, IIntegerConsumer>)
2036 request.argument).first;
2037 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2038 break;
2039 }
2040 case EVENT_SET_SIM_POWER_DONE: {
2041 ar = (AsyncResult) msg.obj;
2042 request = (MainThreadRequest) ar.userObj;
2043 IIntegerConsumer callback =
2044 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2045 if (ar.exception != null) {
2046 loge("setSimPower exception: " + ar.exception);
2047 int errorCode = TelephonyManager.CallForwardingInfoCallback
2048 .RESULT_ERROR_UNKNOWN;
2049 if (ar.exception instanceof CommandException) {
2050 CommandException.Error error =
2051 ((CommandException) (ar.exception)).getCommandError();
2052 if (error == CommandException.Error.SIM_ERR) {
2053 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2054 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2055 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2056 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2057 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2058 } else {
2059 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2060 }
2061 }
2062 try {
2063 callback.accept(errorCode);
2064 } catch (RemoteException e) {
2065 // Ignore if the remote process is no longer available to call back.
2066 Log.w(LOG_TAG, "setSimPower: callback not available.");
2067 }
2068 } else {
2069 try {
2070 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2071 } catch (RemoteException e) {
2072 // Ignore if the remote process is no longer available to call back.
2073 Log.w(LOG_TAG, "setSimPower: callback not available.");
2074 }
2075 }
2076 break;
2077 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002078 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2079 request = (MainThreadRequest) msg.obj;
2080
2081 final Phone phone = getPhoneFromRequest(request);
2082 if (phone == null || phone.getServiceStateTracker() == null) {
2083 request.result = new IllegalStateException("Phone or SST is null");
2084 notifyRequester(request);
2085 break;
2086 }
2087
2088 Pair<Integer, SignalStrengthUpdateRequest> pair =
2089 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2090 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2091 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002092 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002093 request.subId, pair.first /*callingUid*/,
2094 pair.second /*request*/, onCompleted);
2095 break;
2096 }
2097 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2098 ar = (AsyncResult) msg.obj;
2099 request = (MainThreadRequest) ar.userObj;
2100 // request.result will be the exception of ar if present, true otherwise.
2101 // Be cautious not to leave result null which will wait() forever
2102 request.result = ar.exception != null ? ar.exception : true;
2103 notifyRequester(request);
2104 break;
2105 }
2106 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2107 request = (MainThreadRequest) msg.obj;
2108
2109 Phone phone = getPhoneFromRequest(request);
2110 if (phone == null || phone.getServiceStateTracker() == null) {
2111 request.result = new IllegalStateException("Phone or SST is null");
2112 notifyRequester(request);
2113 break;
2114 }
2115
2116 Pair<Integer, SignalStrengthUpdateRequest> pair =
2117 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2118 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2119 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002120 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002121 request.subId, pair.first /*callingUid*/,
2122 pair.second /*request*/, onCompleted);
2123 break;
2124 }
2125 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2126 ar = (AsyncResult) msg.obj;
2127 request = (MainThreadRequest) ar.userObj;
2128 request.result = ar.exception != null ? ar.exception : true;
2129 notifyRequester(request);
2130 break;
2131 }
Jordan Liu109698e2020-11-24 14:50:34 -08002132
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002133 case CMD_GET_SLICING_CONFIG: {
2134 request = (MainThreadRequest) msg.obj;
2135 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2136 request.phone.getSlicingConfig(onCompleted);
2137 break;
2138 }
2139 case EVENT_GET_SLICING_CONFIG_DONE: {
2140 ar = (AsyncResult) msg.obj;
2141 request = (MainThreadRequest) ar.userObj;
2142 ResultReceiver result = (ResultReceiver) request.argument;
2143
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002144 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002145 Bundle bundle = new Bundle();
2146 int resultCode = 0;
2147 if (ar.exception != null) {
2148 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2149 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002150 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002151 } else if (ar.result == null) {
2152 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002153 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002154 } else {
2155 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002156 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2157 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002158 }
2159
2160 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002161 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002162 }
2163 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2164 result.send(resultCode, bundle);
2165 notifyRequester(request);
2166 break;
2167 }
2168
Sarah Chin71b3a852022-09-28 15:54:19 -07002169 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002170 request = (MainThreadRequest) msg.obj;
2171 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002172 PurchasePremiumCapabilityArgument arg =
2173 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002174 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002175 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002176 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002177 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002178
Sarah Chin71b3a852022-09-28 15:54:19 -07002179 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002180 ar = (AsyncResult) msg.obj;
2181 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002182 PurchasePremiumCapabilityArgument arg =
2183 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002184 try {
2185 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002186 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002187 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002188 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002189 + ", result= "
2190 + TelephonyManager.convertPurchaseResultToString(result));
2191 } catch (RemoteException e) {
2192 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002193 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002194 + " failed: " + e;
2195 if (DBG) log(logStr);
2196 AnomalyReporter.reportAnomaly(
2197 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2198 }
2199 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002200 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002201
Michele Berionne5e411512020-11-13 02:36:59 +00002202 case CMD_PREPARE_UNATTENDED_REBOOT:
2203 request = (MainThreadRequest) msg.obj;
2204 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002205 UiccController.getInstance().getPinStorage()
2206 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002207 notifyRequester(request);
2208 break;
2209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 default:
2211 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2212 break;
2213 }
2214 }
Jake Hambye994d462014-02-03 13:10:13 -08002215
Pengquan Menga1bb6272018-09-06 09:59:22 -07002216 private void notifyRequester(MainThreadRequest request) {
2217 synchronized (request) {
2218 request.notifyAll();
2219 }
2220 }
2221
Jake Hambye994d462014-02-03 13:10:13 -08002222 private void handleNullReturnEvent(Message msg, String command) {
2223 AsyncResult ar = (AsyncResult) msg.obj;
2224 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2225 if (ar.exception == null) {
2226 request.result = true;
2227 } else {
2228 request.result = false;
2229 if (ar.exception instanceof CommandException) {
2230 loge(command + ": CommandException: " + ar.exception);
2231 } else {
2232 loge(command + ": Unknown exception");
2233 }
2234 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002235 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238
2239 /**
2240 * Posts the specified command to be executed on the main thread,
2241 * waits for the request to complete, and returns the result.
2242 * @see #sendRequestAsync
2243 */
2244 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002245 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2246 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002247 }
2248
2249 /**
2250 * Posts the specified command to be executed on the main thread,
2251 * waits for the request to complete, and returns the result.
2252 * @see #sendRequestAsync
2253 */
2254 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2255 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002256 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002257 }
2258
2259 /**
2260 * Posts the specified command to be executed on the main thread,
2261 * waits for the request to complete, and returns the result.
2262 * @see #sendRequestAsync
2263 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002264 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002265 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2266 }
2267
2268 /**
2269 * Posts the specified command to be executed on the main thread,
2270 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2271 * if not timeout or null otherwise.
2272 * @see #sendRequestAsync
2273 */
2274 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2275 long timeoutInMs) {
2276 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002277 }
2278
2279 /**
2280 * Posts the specified command to be executed on the main thread,
2281 * waits for the request to complete, and returns the result.
2282 * @see #sendRequestAsync
2283 */
Nathan Harold92bed182018-10-12 18:16:49 -07002284 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002285 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002286 }
2287
2288 /**
2289 * Posts the specified command to be executed on the main thread,
2290 * waits for the request to complete, and returns the result.
2291 * @see #sendRequestAsync
2292 */
2293 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002294 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2295 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002296 }
2297
2298 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002299 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2300 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2301 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002302 * @see #sendRequestAsync
2303 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002304 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2305 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2307 throw new RuntimeException("This method will deadlock if called from the main thread.");
2308 }
2309
Nathan Harold92bed182018-10-12 18:16:49 -07002310 MainThreadRequest request = null;
2311 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2312 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2313 } else if (phone != null) {
2314 request = new MainThreadRequest(argument, phone, workSource);
2315 } else {
2316 request = new MainThreadRequest(argument, subId, workSource);
2317 }
2318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 Message msg = mMainThreadHandler.obtainMessage(command, request);
2320 msg.sendToTarget();
2321
Rambo Wang0f050d82021-02-12 11:43:36 -08002322
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002324 if (timeoutInMs >= 0) {
2325 // Wait for at least timeoutInMs before returning null request result
2326 long now = SystemClock.elapsedRealtime();
2327 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002328 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 try {
2330 request.wait(deadline - now);
2331 } catch (InterruptedException e) {
2332 // Do nothing, go back and check if request is completed or timeout
2333 } finally {
2334 now = SystemClock.elapsedRealtime();
2335 }
2336 }
2337 } else {
2338 // Wait for the request to complete
2339 while (request.result == null) {
2340 try {
2341 request.wait();
2342 } catch (InterruptedException e) {
2343 // Do nothing, go back and wait until the request is complete
2344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
2346 }
2347 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002348 if (request.result == null) {
2349 Log.wtf(LOG_TAG,
2350 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 return request.result;
2353 }
2354
2355 /**
2356 * Asynchronous ("fire and forget") version of sendRequest():
2357 * Posts the specified command to be executed on the main thread, and
2358 * returns immediately.
2359 * @see #sendRequest
2360 */
2361 private void sendRequestAsync(int command) {
2362 mMainThreadHandler.sendEmptyMessage(command);
2363 }
2364
2365 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002366 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002367 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002368 */
2369 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002370 sendRequestAsync(command, argument, null, null);
2371 }
2372
2373 /**
2374 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2375 * @see {@link #sendRequest(int,Object)}
2376 */
2377 private void sendRequestAsync(
2378 int command, Object argument, Phone phone, WorkSource workSource) {
2379 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002380 Message msg = mMainThreadHandler.obtainMessage(command, request);
2381 msg.sendToTarget();
2382 }
2383
2384 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 * Initialize the singleton PhoneInterfaceManager instance.
2386 * This is only done once, at startup, from PhoneApp.onCreate().
2387 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002388 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 synchronized (PhoneInterfaceManager.class) {
2390 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002391 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 } else {
2393 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2394 }
2395 return sInstance;
2396 }
2397 }
2398
2399 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002400 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002403 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002404 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002406 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002408 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002409 mTelephonySharedPreferences =
2410 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002411 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002412 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002413 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002414 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002415 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002416 mTelephony2gUpdater = new Telephony2gUpdater(
2417 Executors.newSingleThreadExecutor(), mApp);
2418 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 publish();
2420 }
2421
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002422 private Phone getDefaultPhone() {
2423 Phone thePhone = getPhone(getDefaultSubscription());
2424 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2425 }
2426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 private void publish() {
2428 if (DBG) log("publish: " + this);
2429
Peter Wangc035ce42020-01-08 21:00:22 -08002430 TelephonyFrameworkInitializer
2431 .getTelephonyServiceManager()
2432 .getTelephonyServiceRegisterer()
2433 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 }
2435
Stuart Scott584921c2015-01-15 17:10:34 -08002436 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002437 if (request.phone != null) {
2438 return request.phone;
2439 } else {
2440 return getPhoneFromSubId(request.subId);
2441 }
2442 }
2443
2444 private Phone getPhoneFromSubId(int subId) {
2445 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2446 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002447 }
2448
Rambo Wange53e07d2022-05-10 13:01:13 -07002449 @Nullable
2450 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 Phone phone = getPhoneFromRequest(request);
2452 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002453 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002454 }
2455
Wink Saville36469e72014-06-11 15:17:00 -07002456 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002457 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002458 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460
Kai Shif70f46f2021-03-03 13:59:46 -08002461 private void sendEraseModemConfig(@NonNull Phone phone) {
2462 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2463 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2464 }
2465
2466 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2467 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2468 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002469 }
2470
Peter Wang44b186e2020-01-13 23:33:09 -08002471 private boolean isImsAvailableOnDevice() {
2472 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2473 if (pm == null) {
2474 // For some reason package manger is not available.. This will fail internally anyway,
2475 // so do not throw error and allow.
2476 return true;
2477 }
2478 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2479 }
2480
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002482 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002483 }
2484
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 if (DBG) log("dial: " + number);
2487 // No permission check needed here: This is just a wrapper around the
2488 // ACTION_DIAL intent, which is available to any app since it puts up
2489 // the UI before it does anything.
2490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 String url = createTelUrl(number);
2494 if (url == null) {
2495 return;
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 // PENDING: should we just silently fail if phone is offhook or ringing?
2499 PhoneConstants.State state = mCM.getState(subId);
2500 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2501 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2502 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2503 mApp.startActivity(intent);
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 }
2508 }
2509
2510 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002511 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002512 }
2513
Wink Savilleb564aae2014-10-23 10:18:09 -07002514 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 if (DBG) log("call: " + number);
2516
2517 // This is just a wrapper around the ACTION_CALL intent, but we still
2518 // need to do a permission check since we're calling startActivity()
2519 // from the context of the phone app.
2520 enforceCallPermission();
2521
Jordan Liu1617b712019-07-10 15:06:26 -07002522 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 != AppOpsManager.MODE_ALLOWED) {
2524 return;
2525 }
2526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 String url = createTelUrl(number);
2530 if (url == null) {
2531 return;
2532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534 boolean isValid = false;
2535 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2536 if (slist != null) {
2537 for (SubscriptionInfo subInfoRecord : slist) {
2538 if (subInfoRecord.getSubscriptionId() == subId) {
2539 isValid = true;
2540 break;
2541 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002542 }
Wink Saville08874612014-08-31 19:19:58 -07002543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544 if (!isValid) {
2545 return;
2546 }
Wink Saville08874612014-08-31 19:19:58 -07002547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2549 intent.putExtra(SUBSCRIPTION_KEY, subId);
2550 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2551 mApp.startActivity(intent);
2552 } finally {
2553 Binder.restoreCallingIdentity(identity);
2554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 }
2556
Wink Savilleb564aae2014-10-23 10:18:09 -07002557 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002558 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002559 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2560 }
2561
Wink Savilleb564aae2014-10-23 10:18:09 -07002562 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002563 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002564 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2565 }
2566
Wink Savilleb564aae2014-10-23 10:18:09 -07002567 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002572 Phone phone = getPhone(subId);
2573 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 checkSimPin.start();
2575 return checkSimPin.unlockSim(null, pin);
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
2578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 }
2580
Wink Savilleb564aae2014-10-23 10:18:09 -07002581 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002586 Phone phone = getPhone(subId);
2587 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 checkSimPuk.start();
2589 return checkSimPuk.unlockSim(puk, pin);
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
2592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 }
2594
2595 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002596 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 * a synchronous one.
2598 */
2599 private static class UnlockSim extends Thread {
2600
2601 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002602 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603
2604 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002605 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2606 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607
2608 // For replies from SimCard interface
2609 private Handler mHandler;
2610
2611 // For async handler to identify request type
2612 private static final int SUPPLY_PIN_COMPLETE = 100;
2613
Michele Berionne5e411512020-11-13 02:36:59 +00002614 UnlockSim(int phoneId, IccCard simCard) {
2615 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 mSimCard = simCard;
2617 }
2618
2619 @Override
2620 public void run() {
2621 Looper.prepare();
2622 synchronized (UnlockSim.this) {
2623 mHandler = new Handler() {
2624 @Override
2625 public void handleMessage(Message msg) {
2626 AsyncResult ar = (AsyncResult) msg.obj;
2627 switch (msg.what) {
2628 case SUPPLY_PIN_COMPLETE:
2629 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2630 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002631 mRetryCount = msg.arg1;
2632 if (ar.exception != null) {
2633 if (ar.exception instanceof CommandException &&
2634 ((CommandException)(ar.exception)).getCommandError()
2635 == CommandException.Error.PASSWORD_INCORRECT) {
2636 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002637 } //When UiccCardApp dispose,handle message and return exception
2638 else if (ar.exception instanceof CommandException &&
2639 ((CommandException) (ar.exception)).getCommandError()
2640 == CommandException.Error.ABORTED) {
2641 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002642 } else {
2643 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2644 }
2645 } else {
2646 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 mDone = true;
2649 UnlockSim.this.notifyAll();
2650 }
2651 break;
2652 }
2653 }
2654 };
2655 UnlockSim.this.notifyAll();
2656 }
2657 Looper.loop();
2658 }
2659
2660 /*
2661 * Use PIN or PUK to unlock SIM card
2662 *
2663 * If PUK is null, unlock SIM card with PIN
2664 *
2665 * If PUK is not null, unlock SIM card with PUK and set PIN code
2666 */
Wink Saville9de0f752013-10-22 19:04:03 -07002667 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668
2669 while (mHandler == null) {
2670 try {
2671 wait();
2672 } catch (InterruptedException e) {
2673 Thread.currentThread().interrupt();
2674 }
2675 }
2676 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2677
2678 if (puk == null) {
2679 mSimCard.supplyPin(pin, callback);
2680 } else {
2681 mSimCard.supplyPuk(puk, pin, callback);
2682 }
2683
2684 while (!mDone) {
2685 try {
2686 Log.d(LOG_TAG, "wait for done");
2687 wait();
2688 } catch (InterruptedException e) {
2689 // Restore the interrupted status
2690 Thread.currentThread().interrupt();
2691 }
2692 }
2693 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002694 int[] resultArray = new int[2];
2695 resultArray[0] = mResult;
2696 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002697
2698 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002699 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002700 }
2701
Wink Saville9de0f752013-10-22 19:04:03 -07002702 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704 }
2705
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002706 /**
2707 * This method has been removed due to privacy and stability concerns.
2708 */
2709 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002711 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2712 return;
Wink Saville36469e72014-06-11 15:17:00 -07002713 }
2714
Nathan Harold1f889d82020-06-04 17:05:26 -07002715 @Override
2716 public void updateServiceLocationWithPackageName(String callingPackage) {
2717 mApp.getSystemService(AppOpsManager.class)
2718 .checkPackage(Binder.getCallingUid(), callingPackage);
2719
Nathan Haroldf096d982020-11-18 17:18:06 -08002720 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002721 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2722 // Callers targeting S have no business invoking this method.
2723 return;
2724 }
2725
2726 LocationAccessPolicy.LocationPermissionResult locationResult =
2727 LocationAccessPolicy.checkLocationPermission(mApp,
2728 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2729 .setCallingPackage(callingPackage)
2730 .setCallingFeatureId(null)
2731 .setCallingPid(Binder.getCallingPid())
2732 .setCallingUid(Binder.getCallingUid())
2733 .setMethod("updateServiceLocation")
2734 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2735 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2736 .build());
2737 // Apps that lack location permission have no business calling this method;
2738 // however, because no permission was declared in the public API, denials must
2739 // all be "soft".
2740 switch (locationResult) {
2741 case DENIED_HARD: /* fall through */
2742 case DENIED_SOFT:
2743 return;
2744 }
2745
2746 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 final long identity = Binder.clearCallingIdentity();
2748 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002749 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002751 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 }
2757
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002758 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002759 @Override
2760 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002761 return isRadioOnWithFeature(callingPackage, null);
2762 }
2763
2764
2765 @Override
2766 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2767 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2768 callingFeatureId);
2769 }
2770
2771 @Deprecated
2772 @Override
2773 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2774 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002775 }
2776
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002778 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002781 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002782 return false;
2783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784
2785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 return isRadioOnForSubscriber(subId);
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
2790 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002791 }
2792
2793 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 final Phone phone = getPhone(subId);
2797 if (phone != null) {
2798 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2799 } else {
2800 return false;
2801 }
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 }
2806
2807 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002808 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 }
Wink Saville36469e72014-06-11 15:17:00 -07002810
Wink Savilleb564aae2014-10-23 10:18:09 -07002811 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813
2814 final long identity = Binder.clearCallingIdentity();
2815 try {
2816 final Phone phone = getPhone(subId);
2817 if (phone != null) {
2818 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2819 }
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002822 }
Wink Saville36469e72014-06-11 15:17:00 -07002823 }
2824
2825 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002826 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002827 }
2828
Wink Savilleb564aae2014-10-23 10:18:09 -07002829 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002830 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831
2832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 final Phone phone = getPhone(subId);
2835 if (phone == null) {
2836 return false;
2837 }
2838 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2839 toggleRadioOnOffForSubscriber(subId);
2840 }
2841 return true;
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
Wink Saville36469e72014-06-11 15:17:00 -07002846
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002847 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002848 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002849 /*
2850 * If any of the Radios are available, it will need to be
2851 * shutdown. So return true if any Radio is available.
2852 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2856 Phone phone = PhoneFactory.getPhone(i);
2857 if (phone != null && phone.isRadioAvailable()) return true;
2858 }
2859 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2860 return false;
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002863 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002864 }
2865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002867 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 enforceModifyPermission();
2869
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2873 logv("Shutting down Phone " + i);
2874 shutdownRadioUsingPhoneId(i);
2875 }
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002878 }
2879 }
2880
2881 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002882 Phone phone = PhoneFactory.getPhone(phoneId);
2883 if (phone != null && phone.isRadioAvailable()) {
2884 phone.shutdownRadio();
2885 }
2886 }
2887
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002889 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2894 if (defaultPhone != null) {
2895 defaultPhone.setRadioPower(turnOn);
2896 return true;
2897 } else {
2898 loge("There's no default phone.");
2899 return false;
2900 }
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002903 }
Wink Saville36469e72014-06-11 15:17:00 -07002904 }
2905
Wink Savilleb564aae2014-10-23 10:18:09 -07002906 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone != null) {
2913 phone.setRadioPower(turnOn);
2914 return true;
2915 } else {
2916 return false;
2917 }
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 }
2922
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002923 /**
2924 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2925 * no reason to power it off. When any of the voters want to power it off, it will be turned
2926 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2927 * powering it off, and these radio off votes will be cleared.
2928 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2929 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2930 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2931 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2932 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2933 * check its vote.
2934 *
2935 * @param subId The subscription ID.
2936 * @param reason The reason for powering off radio.
2937 * @return true on success and false on failure.
2938 */
2939 public boolean requestRadioPowerOffForReason(int subId,
2940 @TelephonyManager.RadioPowerReason int reason) {
2941 enforceModifyPermission();
2942
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 final Phone phone = getPhone(subId);
2946 if (phone != null) {
2947 phone.setRadioPowerForReason(false, reason);
2948 return true;
2949 } else {
2950 return false;
2951 }
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
2955 }
2956
2957 /**
2958 * Remove the vote on powering off the radio for a reason, as requested by
2959 * {@link requestRadioPowerOffForReason}.
2960 *
2961 * @param subId The subscription ID.
2962 * @param reason The reason for powering off radio.
2963 * @return true on success and false on failure.
2964 */
2965 public boolean clearRadioPowerOffForReason(int subId,
2966 @TelephonyManager.RadioPowerReason int reason) {
2967 enforceModifyPermission();
2968
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 final Phone phone = getPhone(subId);
2972 if (phone != null) {
2973 phone.setRadioPowerForReason(true, reason);
2974 return true;
2975 } else {
2976 return false;
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 /**
2984 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2985 *
2986 * @param subId The subscription ID.
2987 * @param callingPackage The package making the call.
2988 * @param callingFeatureId The feature in the package.
2989 * @return List of reasons for powering off radio.
2990 */
2991 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2992 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2993
2994 final long identity = Binder.clearCallingIdentity();
2995 List result = new ArrayList();
2996 try {
2997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2998 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2999 return result;
3000 }
3001
3002 final Phone phone = getPhone(subId);
3003 if (phone != null) {
3004 result.addAll(phone.getRadioPowerOffReasons());
3005 }
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 return result;
3010 }
3011
Wink Saville36469e72014-06-11 15:17:00 -07003012 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003013 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003014 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
Jack Yu285100e2022-12-02 22:48:35 -08003019 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 final Phone phone = getPhone(subId);
3021 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003022 phone.getDataSettingsManager().setDataEnabled(
3023 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 return true;
3025 } else {
3026 return false;
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
3032
Wink Saville36469e72014-06-11 15:17:00 -07003033 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003034 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003035 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
Jack Yu285100e2022-12-02 22:48:35 -08003040 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 final Phone phone = getPhone(subId);
3042 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003043 phone.getDataSettingsManager().setDataEnabled(
3044 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045 return true;
3046 } else {
3047 return false;
3048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 }
3053
Sanket Padawe356d7632015-06-22 14:03:32 -07003054 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003055 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 final Phone phone = getPhone(subId);
3059 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003060 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 } else {
3062 return false;
3063 }
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 }
3068
3069 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003070 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003071 }
3072
pkanwarae03a6b2016-11-06 20:37:09 -08003073 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074 enforceCallPermission();
3075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3079 return;
3080 }
3081 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3082 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
pkanwar32d516d2016-10-14 19:37:38 -07003086 };
3087
Wink Savilleb564aae2014-10-23 10:18:09 -07003088 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003090
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3094 return false;
3095 }
3096 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3097 } finally {
3098 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 }
3101
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003102 /**
3103 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3104 * tag on getCallState Binder call.
3105 */
3106 @Deprecated
3107 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003109 if (CompatChanges.isChangeEnabled(
3110 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3111 Binder.getCallingUid())) {
3112 // Do not allow this API to be called on API version 31+, it should only be
3113 // called on old apps using this Binder call directly.
3114 throw new SecurityException("This method can only be used for applications "
3115 + "targeting API version 30 or less.");
3116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 final long identity = Binder.clearCallingIdentity();
3118 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003119 Phone phone = getPhone(getDefaultSubscription());
3120 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3121 PhoneConstantConversions.convertCallState(phone.getState());
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
3127 @Override
3128 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3129 if (CompatChanges.isChangeEnabled(
3130 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3131 Binder.getCallingUid())) {
3132 // Check READ_PHONE_STATE for API version 31+
3133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3134 featureId, "getCallStateForSubscription")) {
3135 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3136 + "targeting API level 31+.");
3137 }
3138 }
3139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3143 PhoneConstantConversions.convertCallState(phone.getState());
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
3146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147 }
3148
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003150 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003151 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003152 }
3153
3154 @Override
3155 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 final long identity = Binder.clearCallingIdentity();
3157 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003158 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003160 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161 } else {
3162 return PhoneConstantConversions.convertDataState(
3163 PhoneConstants.DataState.DISCONNECTED);
3164 }
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 }
3169
Sanket Padawe356d7632015-06-22 14:03:32 -07003170 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003171 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003172 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003173 }
3174
3175 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003176 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 final long identity = Binder.clearCallingIdentity();
3178 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003179 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003181 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182 } else {
3183 return TelephonyManager.DATA_ACTIVITY_NONE;
3184 }
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 }
3189
3190 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003191 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003193 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003194
3195 LocationAccessPolicy.LocationPermissionResult locationResult =
3196 LocationAccessPolicy.checkLocationPermission(mApp,
3197 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3198 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003199 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003200 .setCallingPid(Binder.getCallingPid())
3201 .setCallingUid(Binder.getCallingUid())
3202 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003203 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003204 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3205 .build());
3206 switch (locationResult) {
3207 case DENIED_HARD:
3208 throw new SecurityException("Not allowed to access cell location");
3209 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003210 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3211 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003218 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003219 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Svetoslav64fad262015-04-14 14:35:21 -07003223 }
3224
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003226 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003227 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3228 // registered cell info, so return a NULL country instead.
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003231 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3232 // Get default phone in this case.
3233 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3234 }
Jack Yu285100e2022-12-02 22:48:35 -08003235 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003237 if (phone == null) return "";
3238 ServiceStateTracker sst = phone.getServiceStateTracker();
3239 if (sst == null) return "";
3240 LocaleTracker lt = sst.getLocaleTracker();
3241 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003242 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003246 }
3247
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003248 /**
3249 * This method was removed due to potential issues caused by performing partial
3250 * updates of service state, and lack of a credible use case.
3251 *
3252 * This has the ability to break the telephony implementation by disabling notification of
3253 * changes in device connectivity. DO NOT USE THIS!
3254 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003255 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 public void enableLocationUpdates() {
3257 mApp.enforceCallingOrSelfPermission(
3258 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003261 /**
3262 * This method was removed due to potential issues caused by performing partial
3263 * updates of service state, and lack of a credible use case.
3264 *
3265 * This has the ability to break the telephony implementation by disabling notification of
3266 * changes in device connectivity. DO NOT USE THIS!
3267 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 @Override
3269 public void disableLocationUpdates() {
3270 mApp.enforceCallingOrSelfPermission(
3271 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
3273
3274 @Override
3275 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003276 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3277 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003278 try {
3279 mApp.getSystemService(AppOpsManager.class)
3280 .checkPackage(Binder.getCallingUid(), callingPackage);
3281 } catch (SecurityException e) {
3282 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3283 throw e;
3284 }
3285
Nathan Haroldf096d982020-11-18 17:18:06 -08003286 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003287 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3288 throw new SecurityException(
3289 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3290 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003291
Jordan Liu1617b712019-07-10 15:06:26 -07003292 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3294 return null;
3295 }
Svetoslav64fad262015-04-14 14:35:21 -07003296
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003297 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003298
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003299 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003300 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301
Nathan Haroldf180aac2018-06-01 18:43:55 -07003302 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3303 for (CellInfo ci : info) {
3304 if (ci instanceof CellInfoGsm) {
3305 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3306 } else if (ci instanceof CellInfoWcdma) {
3307 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003309 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003310 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003311 }
3312
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003313 private List<CellInfo> getCachedCellInfo() {
3314 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3315 for (Phone phone : PhoneFactory.getPhones()) {
3316 List<CellInfo> info = phone.getAllCellInfo();
3317 if (info != null) cellInfos.addAll(info);
3318 }
3319 return cellInfos;
3320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321
3322 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003323 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003324 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003325 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003326
3327 LocationAccessPolicy.LocationPermissionResult locationResult =
3328 LocationAccessPolicy.checkLocationPermission(mApp,
3329 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3330 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003331 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003332 .setCallingPid(Binder.getCallingPid())
3333 .setCallingUid(Binder.getCallingUid())
3334 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003335 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003336 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3337 .build());
3338 switch (locationResult) {
3339 case DENIED_HARD:
3340 throw new SecurityException("Not allowed to access cell info");
3341 case DENIED_SOFT:
3342 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003343 }
3344
Nathan Haroldf096d982020-11-18 17:18:06 -08003345 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003346 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3347 return getCachedCellInfo();
3348 }
3349
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003350 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3355 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003356 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003357 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 if (info != null) cellInfos.addAll(info);
3359 }
3360 return cellInfos;
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003363 }
3364 }
3365
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003366 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003367 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3368 String callingFeatureId) {
3369 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3370 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003371 }
3372
3373 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003374 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3375 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003376 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003377 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003378 }
3379
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003380 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3381 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003383 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003384
3385 LocationAccessPolicy.LocationPermissionResult locationResult =
3386 LocationAccessPolicy.checkLocationPermission(mApp,
3387 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3388 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003389 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003390 .setCallingPid(Binder.getCallingPid())
3391 .setCallingUid(Binder.getCallingUid())
3392 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003393 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3394 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003395 .build());
3396 switch (locationResult) {
3397 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003398 if (TelephonyPermissions
3399 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003400 // Safetynet logging for b/154934934
3401 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3402 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003403 throw new SecurityException("Not allowed to access cell info");
3404 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003405 if (TelephonyPermissions
3406 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003407 // Safetynet logging for b/154934934
3408 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3409 }
Nathan Harold5320c422019-05-09 10:26:08 -07003410 try {
3411 cb.onCellInfo(new ArrayList<CellInfo>());
3412 } catch (RemoteException re) {
3413 // Drop without consequences
3414 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003415 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003416 }
3417
Nathan Harolda939a962019-05-09 10:13:47 -07003418
3419 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003420 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3421
3422 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3423 }
3424
3425 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003426 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003427 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003428 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429
3430 final long identity = Binder.clearCallingIdentity();
3431 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003432 Phone phone = getPhone(subId);
3433 if (phone == null) {
3434 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3435 } else {
3436 phone.setCellInfoListRate(rateInMillis, workSource);
3437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 }
3442
Shishir Agrawala9f32182016-04-12 12:00:16 -07003443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003444 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003445 Phone phone = PhoneFactory.getPhone(slotIndex);
3446 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003447 return null;
3448 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003449 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003450 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003451 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003452 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003453 return null;
3454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003455
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 return phone.getImei();
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003462 }
3463
3464 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003465 public String getTypeAllocationCodeForSlot(int slotIndex) {
3466 Phone phone = PhoneFactory.getPhone(slotIndex);
3467 String tac = null;
3468 if (phone != null) {
3469 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003470 try {
3471 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3472 } catch (IndexOutOfBoundsException e) {
3473 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3474 return null;
3475 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003476 }
3477 return tac;
3478 }
3479
3480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003481 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003482 try {
3483 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3484 } catch (SecurityException se) {
3485 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3486 throw new SecurityException("Package " + callingPackage + " does not belong to "
3487 + Binder.getCallingUid());
3488 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003489 Phone phone = PhoneFactory.getPhone(slotIndex);
3490 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003491 return null;
3492 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003493
Jeff Davidson913390f2018-02-23 17:11:49 -08003494 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003495 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003496 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003497 return null;
3498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 return phone.getMeid();
3503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Jack Yu2af8d712017-03-15 17:14:14 -07003506 }
3507
3508 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003509 public String getManufacturerCodeForSlot(int slotIndex) {
3510 Phone phone = PhoneFactory.getPhone(slotIndex);
3511 String manufacturerCode = null;
3512 if (phone != null) {
3513 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003514 try {
3515 manufacturerCode =
3516 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3517 } catch (IndexOutOfBoundsException e) {
3518 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3519 return null;
3520 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003521 }
3522 return manufacturerCode;
3523 }
3524
3525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3527 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003528 Phone phone = PhoneFactory.getPhone(slotIndex);
3529 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003530 return null;
3531 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003532 int subId = phone.getSubId();
3533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003534 mApp, subId, callingPackage, callingFeatureId,
3535 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003536 return null;
3537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538
3539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 return phone.getDeviceSvn();
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003545 }
3546
fionaxu43304da2017-11-27 22:51:16 -08003547 @Override
3548 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 final Phone phone = getPhone(subId);
3552 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
fionaxu43304da2017-11-27 22:51:16 -08003556 }
3557
3558 @Override
3559 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 return phone == null ? null : phone.getCarrierName();
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
fionaxu43304da2017-11-27 22:51:16 -08003567 }
3568
calvinpanffe225e2018-11-01 19:43:06 +08003569 @Override
chen xu0026ca62019-03-06 15:28:50 -08003570 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 final Phone phone = getPhone(subId);
3574 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003575 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
3579 }
3580
3581 @Override
chen xu0026ca62019-03-06 15:28:50 -08003582 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003586 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
3590 }
3591
chen xu651eec72018-11-11 19:03:44 -08003592 @Override
chen xu864e11c2018-12-06 22:10:03 -08003593 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3594 if (!isSubscriptionMccMnc) {
3595 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3596 }
chen xu651eec72018-11-11 19:03:44 -08003597 final Phone phone = PhoneFactory.getPhone(slotIndex);
3598 if (phone == null) {
3599 return TelephonyManager.UNKNOWN_CARRIER_ID;
3600 }
3601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
3606 }
3607 }
3608
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003609 //
3610 // Internal helper methods.
3611 //
3612
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003613 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003614 * Make sure the caller is the calling package itself
3615 *
3616 * @throws SecurityException if the caller is not the calling package
3617 */
3618 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3619 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003620 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3621 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003622 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003623 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003624 } catch (PackageManager.NameNotFoundException e) {
3625 // packageUid is -1
3626 }
3627 if (packageUid != callingUid) {
3628 throw new SecurityException(message + ": Package " + callingPackage
3629 + " does not belong to " + callingUid);
3630 }
3631 }
3632
3633 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003634 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3635 *
3636 * @throws SecurityException if the caller does not have the required permission
3637 */
3638 private void enforceModifyPermission() {
3639 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3640 }
3641
Shuo Qian3b6ee772019-11-13 17:43:31 -08003642 private void enforceActiveEmergencySessionPermission() {
3643 mApp.enforceCallingOrSelfPermission(
3644 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3645 }
3646
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 /**
3648 * Make sure the caller has the CALL_PHONE permission.
3649 *
3650 * @throws SecurityException if the caller does not have the required permission
3651 */
3652 private void enforceCallPermission() {
3653 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3654 }
3655
paulhu5a773602019-08-23 19:17:33 +08003656 private void enforceSettingsPermission() {
3657 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003658 }
3659
Michele Berionne5e411512020-11-13 02:36:59 +00003660 private void enforceRebootPermission() {
3661 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3662 }
3663
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003664 private String createTelUrl(String number) {
3665 if (TextUtils.isEmpty(number)) {
3666 return null;
3667 }
3668
Jake Hambye994d462014-02-03 13:10:13 -08003669 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 }
3671
Ihab Awadf9e92732013-12-05 18:02:52 -08003672 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003673 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3674 }
3675
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003676 private static void logv(String msg) {
3677 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3678 }
3679
Ihab Awadf9e92732013-12-05 18:02:52 -08003680 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003681 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3682 }
3683
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003685 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003686 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003687 }
3688
Sanket Padawe356d7632015-06-22 14:03:32 -07003689 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003690 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 final Phone phone = PhoneFactory.getPhone(slotIndex);
3694 if (phone == null) {
3695 return PhoneConstants.PHONE_TYPE_NONE;
3696 } else {
3697 return phone.getPhoneType();
3698 }
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003702 }
3703
3704 /**
3705 * Returns the CDMA ERI icon index to display
3706 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003707 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003708 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3709 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3710 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003711 }
3712
Sanket Padawe356d7632015-06-22 14:03:32 -07003713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003714 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3715 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003717 mApp, subId, callingPackage, callingFeatureId,
3718 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003719 return -1;
3720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 final Phone phone = getPhone(subId);
3725 if (phone != null) {
3726 return phone.getCdmaEriIconIndex();
3727 } else {
3728 return -1;
3729 }
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003733 }
3734
3735 /**
3736 * Returns the CDMA ERI icon mode,
3737 * 0 - ON
3738 * 1 - FLASHING
3739 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003741 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3742 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3743 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003744 }
3745
Sanket Padawe356d7632015-06-22 14:03:32 -07003746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003747 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3748 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003750 mApp, subId, callingPackage, callingFeatureId,
3751 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003752 return -1;
3753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 final Phone phone = getPhone(subId);
3758 if (phone != null) {
3759 return phone.getCdmaEriIconMode();
3760 } else {
3761 return -1;
3762 }
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003766 }
3767
3768 /**
3769 * Returns the CDMA ERI text,
3770 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003771 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003772 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3773 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3774 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003775 }
3776
Sanket Padawe356d7632015-06-22 14:03:32 -07003777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003778 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003781 mApp, subId, callingPackage, callingFeatureId,
3782 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003783 return null;
3784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final Phone phone = getPhone(subId);
3789 if (phone != null) {
3790 return phone.getCdmaEriText();
3791 } else {
3792 return null;
3793 }
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003797 }
3798
3799 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003800 * Returns the CDMA MDN.
3801 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003802 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003803 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3805 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003810 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 return phone.getLine1Number();
3812 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003813 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 return null;
3815 }
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003818 }
3819 }
3820
3821 /**
3822 * Returns the CDMA MIN.
3823 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003824 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003825 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3827 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828
3829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = getPhone(subId);
3832 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3833 return phone.getCdmaMin();
3834 } else {
3835 return null;
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003839 }
3840 }
3841
Hall Liud892bec2018-11-30 14:51:45 -08003842 @Override
3843 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3844 INumberVerificationCallback callback, String callingPackage) {
3845 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3846 != PERMISSION_GRANTED) {
3847 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3848 }
3849 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3850
3851 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3852 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003853 throw new SecurityException("Calling package must be configured in the device config: "
3854 + "calling package: " + callingPackage
3855 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003856 }
3857
3858 if (range == null) {
3859 throw new NullPointerException("Range must be non-null");
3860 }
3861
3862 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003863 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003864
3865 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3866 }
3867
Junda Liuca05d5d2014-08-14 22:36:34 -07003868 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003869 * Returns true if CDMA provisioning needs to run.
3870 */
3871 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003874 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003878 }
3879
3880 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003881 * Sets the voice mail number of a given subId.
3882 */
3883 @Override
3884 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003885 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3886 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887
3888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3891 new Pair<String, String>(alphaTag, number), new Integer(subId));
3892 return success;
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003896 }
3897
Ta-wei Yen87c49842016-05-13 21:19:52 -07003898 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003899 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3900 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003901 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3902 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003903 if (!TextUtils.equals(callingPackage, systemDialer)) {
3904 throw new SecurityException("caller must be system dialer");
3905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906
3907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3910 if (phoneAccountHandle == null) {
3911 return null;
3912 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 } finally {
3915 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003916 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003917 }
3918
3919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003920 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3921 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003924 mApp, subId, callingPackage, callingFeatureId,
3925 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003926 return null;
3927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003929 final long identity = Binder.clearCallingIdentity();
3930 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003931 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003932 } finally {
3933 Binder.restoreCallingIdentity(identity);
3934 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003935 }
3936
3937 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003938 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3939 VisualVoicemailSmsFilterSettings settings) {
3940 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003945 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003949 }
3950
3951 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003952 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3953 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003962 }
3963
3964 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003965 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3966 String callingPackage, int subId) {
3967 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968
3969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 } finally {
3974 Binder.restoreCallingIdentity(identity);
3975 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003976 }
3977
3978 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003979 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003985 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003989 }
3990
3991 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003992 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3993 String callingAttributionTag, int subId, String number, int port, String text,
3994 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003996 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003997 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003998 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003999 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4000 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004001 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004002
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004003 /**
fionaxu0152e512016-11-14 13:36:14 -08004004 * Sets the voice activation state of a given subId.
4005 */
4006 @Override
4007 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4009 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 final Phone phone = getPhone(subId);
4014 if (phone != null) {
4015 phone.setVoiceActivationState(activationState);
4016 } else {
4017 loge("setVoiceActivationState fails with invalid subId: " + subId);
4018 }
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004021 }
4022 }
4023
4024 /**
4025 * Sets the data activation state of a given subId.
4026 */
4027 @Override
4028 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4030 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 final Phone phone = getPhone(subId);
4035 if (phone != null) {
4036 phone.setDataActivationState(activationState);
4037 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004038 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039 }
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004042 }
4043 }
4044
4045 /**
4046 * Returns the voice activation state of a given subId.
4047 */
4048 @Override
4049 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
fionaxu0152e512016-11-14 13:36:14 -08004052 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 if (phone != null) {
4056 return phone.getVoiceActivationState();
4057 } else {
4058 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4059 }
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004062 }
4063 }
4064
4065 /**
4066 * Returns the data activation state of a given subId.
4067 */
4068 @Override
4069 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071
fionaxu0152e512016-11-14 13:36:14 -08004072 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 if (phone != null) {
4076 return phone.getDataActivationState();
4077 } else {
4078 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4079 }
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004082 }
4083 }
4084
4085 /**
Wink Saville36469e72014-06-11 15:17:00 -07004086 * Returns the unread count of voicemails for a subId
4087 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004088 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004089 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4090 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004092 mApp, subId, callingPackage, callingFeatureId,
4093 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004094 return 0;
4095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 final Phone phone = getPhone(subId);
4099 if (phone != null) {
4100 return phone.getVoiceMessageCount();
4101 } else {
4102 return 0;
4103 }
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004107 }
4108
4109 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004110 * returns true, if the device is in a state where both voice and data
4111 * are supported simultaneously. This can change based on location or network condition.
4112 */
4113 @Override
4114 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 final Phone phone = getPhone(subId);
4118 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004122 }
4123
4124 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004125 * Send the dialer code if called from the current default dialer or the caller has
4126 * carrier privilege.
4127 * @param inputCode The dialer code to send
4128 */
4129 @Override
4130 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004131 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004133 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4134 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004135 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004136 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004137 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139
4140 final long identity = Binder.clearCallingIdentity();
4141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004142 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
fionaxu235cc5e2017-03-06 22:25:57 -08004146 }
4147
Pengquan Menga1bb6272018-09-06 09:59:22 -07004148 @Override
4149 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004150 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004151 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004152 mApp, subId, "getNetworkSelectionMode");
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 if (!isActiveSubscription(subId)) {
4156 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4157 }
4158 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004161 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004162 }
4163
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004165 public boolean isInEmergencySmsMode() {
4166 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 for (Phone phone : PhoneFactory.getPhones()) {
4170 if (phone.isInEmergencySmsMode()) {
4171 return true;
4172 }
4173 }
4174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
4177 return false;
4178 }
4179
shilu366312e2019-12-17 09:28:10 -08004180 /**
4181 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4182 * @param subId The subscription to use to check the configuration.
4183 * @param c The callback that will be used to send the result.
4184 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004185 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004186 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4187 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004188 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004189 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004190
4191 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4192 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4193 "IMS not available on device.");
4194 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long token = Binder.clearCallingIdentity();
4196 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004197 int slotId = getSlotIndexOrException(subId);
4198 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004199
4200 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4201 if (controller != null) {
4202 ImsManager imsManager = controller.getImsManager(subId);
4203 if (imsManager != null) {
4204 imsManager.addRegistrationCallbackForSubscription(c, subId);
4205 } else {
4206 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4207 }
4208 } else {
4209 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4210 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 } catch (ImsException e) {
4212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 } finally {
4214 Binder.restoreCallingIdentity(token);
4215 }
4216 }
4217
shilu366312e2019-12-17 09:28:10 -08004218 /**
4219 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4220 * @param subId The subscription to use to check the configuration.
4221 * @param c The callback that will be used to send the result.
4222 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004224 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004225 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004226 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004227 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4228 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4229 }
Meng Wangafbc5852019-09-19 17:37:13 -07004230 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004231
Meng Wangafbc5852019-09-19 17:37:13 -07004232 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004233 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4234 if (controller != null) {
4235 ImsManager imsManager = controller.getImsManager(subId);
4236 if (imsManager != null) {
4237 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4238 } else {
4239 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4240 + "is inactive, ignoring unregister.");
4241 // If the ImsManager is not valid, just return, since the callback
4242 // will already have been removed internally.
4243 }
4244 }
Meng Wangafbc5852019-09-19 17:37:13 -07004245 } finally {
4246 Binder.restoreCallingIdentity(token);
4247 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004248 }
4249
Brad Ebingera34a6c22019-10-22 17:36:18 -07004250 /**
4251 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4252 */
4253 @Override
4254 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4255 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4256 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4257 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4258 "IMS not available on device.");
4259 }
4260 final long token = Binder.clearCallingIdentity();
4261 try {
4262 Phone phone = getPhone(subId);
4263 if (phone == null) {
4264 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4265 + subId + "'");
4266 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4267 }
4268 phone.getImsRegistrationState(regState -> {
4269 try {
4270 consumer.accept((regState == null)
4271 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4272 } catch (RemoteException e) {
4273 // Ignore if the remote process is no longer available to call back.
4274 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4275 }
4276 });
4277 } finally {
4278 Binder.restoreCallingIdentity(token);
4279 }
4280 }
4281
4282 /**
4283 * Get the transport type for the IMS service registration state.
4284 */
4285 @Override
4286 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004287 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004288 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004289 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4290 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4291 "IMS not available on device.");
4292 }
4293 final long token = Binder.clearCallingIdentity();
4294 try {
4295 Phone phone = getPhone(subId);
4296 if (phone == null) {
4297 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4298 + subId + "'");
4299 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4300 }
4301 phone.getImsRegistrationTech(regTech -> {
4302 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4303 int regTechConverted = (regTech == null)
4304 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4305 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4306 regTechConverted);
4307 try {
4308 consumer.accept(regTechConverted);
4309 } catch (RemoteException e) {
4310 // Ignore if the remote process is no longer available to call back.
4311 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4312 }
4313 });
4314 } finally {
4315 Binder.restoreCallingIdentity(token);
4316 }
4317 }
4318
shilu366312e2019-12-17 09:28:10 -08004319 /**
4320 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4321 * @param subId The subscription to use to check the configuration.
4322 * @param c The callback that will be used to send the result.
4323 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004325 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4326 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004327 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004328 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004329 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4330 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4331 "IMS not available on device.");
4332 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 final long token = Binder.clearCallingIdentity();
4334 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004335 int slotId = getSlotIndexOrException(subId);
4336 verifyImsMmTelConfiguredOrThrow(slotId);
4337 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 } finally {
4341 Binder.restoreCallingIdentity(token);
4342 }
4343 }
4344
shilu366312e2019-12-17 09:28:10 -08004345 /**
4346 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4347 * @param subId The subscription to use to check the configuration.
4348 * @param c The callback that will be used to send the result.
4349 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004351 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004352 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004353 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004354 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4355 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4356 }
Meng Wangafbc5852019-09-19 17:37:13 -07004357
4358 final long token = Binder.clearCallingIdentity();
4359 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004360 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004361 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004362 } catch (ImsException e) {
4363 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4364 + "is inactive, ignoring unregister.");
4365 // If the subscription is no longer active, just return, since the callback
4366 // will already have been removed internally.
4367 } finally {
4368 Binder.restoreCallingIdentity(token);
4369 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 }
4371
4372 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004373 public boolean isCapable(int subId, int capability, int regTech) {
4374 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 final long token = Binder.clearCallingIdentity();
4376 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004377 int slotId = getSlotIndexOrException(subId);
4378 verifyImsMmTelConfiguredOrThrow(slotId);
4379 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4380 } catch (com.android.ims.ImsException e) {
4381 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4382 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004383 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004384 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4385 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
4389 }
4390
4391 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004392 public boolean isAvailable(int subId, int capability, int regTech) {
4393 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 final long token = Binder.clearCallingIdentity();
4395 try {
4396 Phone phone = getPhone(subId);
4397 if (phone == null) return false;
4398 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004399 } catch (com.android.ims.ImsException e) {
4400 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4401 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004402 } finally {
4403 Binder.restoreCallingIdentity(token);
4404 }
4405 }
4406
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004407 /**
4408 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4409 * subscription.
4410 * @param subId The subscription to use to check the configuration.
4411 * @param callback The callback that will be used to send the result.
4412 * @param capability The MmTelFeature capability that will be used to send the result.
4413 * @param transportType The transport type of the MmTelFeature capability.
4414 */
4415 @Override
4416 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4417 int transportType) {
4418 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004419 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4420 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4421 "IMS not available on device.");
4422 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004423 final long token = Binder.clearCallingIdentity();
4424 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004425 int slotId = getSlotIndex(subId);
4426 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4427 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4428 + subId + "'");
4429 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4430 }
4431 verifyImsMmTelConfiguredOrThrow(slotId);
4432 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4433 transportType, aBoolean -> {
4434 try {
4435 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4436 } catch (RemoteException e) {
4437 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4438 + "running. Ignore");
4439 }
4440 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 } catch (ImsException e) {
4442 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004443 } finally {
4444 Binder.restoreCallingIdentity(token);
4445 }
4446 }
4447
shilu366312e2019-12-17 09:28:10 -08004448 /**
4449 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4450 * @param subId The subscription to use to check the configuration.
4451 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 @Override
4453 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004454 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004455 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004456
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 final long token = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(token);
4466 }
4467 }
4468
4469 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004470 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004472 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004476 // This setting doesn't require an active ImsService connection, so do not verify. The
4477 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
shilu366312e2019-12-17 09:28:10 -08004486 /**
4487 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4488 * @param subId The subscription to use to check the configuration.
4489 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004491 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004493 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004497 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
4506 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004507 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004509 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004513 // This setting doesn't require an active ImsService connection, so do not verify. The
4514 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
shilu366312e2019-12-17 09:28:10 -08004523 /**
4524 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4525 * @param subId The subscription to use to check the configuration.
4526 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 @Override
4528 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004529 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004530 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004531 final long identity = Binder.clearCallingIdentity();
4532 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004533 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004534 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004535 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004536 } catch (ImsException e) {
4537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
4541 }
4542
4543 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004544 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004546 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 final long identity = Binder.clearCallingIdentity();
4548 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004549 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004550 // This setting doesn't require an active ImsService connection, so do not verify. The
4551 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004552 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004553 } catch (ImsException e) {
4554 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
4557 }
4558 }
4559
shilu366312e2019-12-17 09:28:10 -08004560 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004561 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4562 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4563 * @param subId The subscription to use to check the configuration.
4564 */
4565 @Override
4566 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004567 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004568 mApp, subId, "isCrossSimCallingEnabledByUser");
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004571 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004572 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004573 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004574 } catch (ImsException e) {
4575 throw new ServiceSpecificException(e.getCode());
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
4579 }
4580
4581 /**
4582 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4583 * Requires MODIFY_PHONE_STATE permission.
4584 * @param subId The subscription to use to check the configuration.
4585 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4586 * false otherwise
4587 */
4588 @Override
4589 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4591 "setCrossSimCallingEnabled");
4592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004595 // This setting doesn't require an active ImsService connection, so do not verify. The
4596 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004597 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
4603 }
4604
4605 /**
shilu366312e2019-12-17 09:28:10 -08004606 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4607 * @param subId The subscription to use to check the configuration.
4608 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004609 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004610
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004612 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004613 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004614 final long identity = Binder.clearCallingIdentity();
4615 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004616 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004617 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004619 } catch (ImsException e) {
4620 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
4624 }
4625
4626 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004627 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004629 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 final long identity = Binder.clearCallingIdentity();
4631 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004632 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004633 // This setting doesn't require an active ImsService connection, so do not verify. The
4634 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004635 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (ImsException e) {
4637 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
4641 }
4642
4643 @Override
4644 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4646 "setVoWiFiNonPersistent");
4647 final long identity = Binder.clearCallingIdentity();
4648 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004649 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004650 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004651 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004652 } catch (ImsException e) {
4653 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
4657 }
4658
shilu366312e2019-12-17 09:28:10 -08004659 /**
4660 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4661 * @param subId The subscription to use to check the configuration.
4662 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 @Override
4664 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004665 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004666 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 final long identity = Binder.clearCallingIdentity();
4668 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004669 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004670 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004671 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004672 } catch (ImsException e) {
4673 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
4677 }
4678
4679 @Override
4680 public void setVoWiFiModeSetting(int subId, int mode) {
4681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4682 "setVoWiFiModeSetting");
4683 final long identity = Binder.clearCallingIdentity();
4684 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004685 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004686 // This setting doesn't require an active ImsService connection, so do not verify. The
4687 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004689 } catch (ImsException e) {
4690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
4694 }
4695
4696 @Override
4697 public int getVoWiFiRoamingModeSetting(int subId) {
4698 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4699 final long identity = Binder.clearCallingIdentity();
4700 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004701 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004702 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004703 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004704 } catch (ImsException e) {
4705 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
4709 }
4710
4711 @Override
4712 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4714 "setVoWiFiRoamingModeSetting");
4715 final long identity = Binder.clearCallingIdentity();
4716 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004717 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004718 // This setting doesn't require an active ImsService connection, so do not verify. The
4719 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004720 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004721 } catch (ImsException e) {
4722 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004723 } finally {
4724 Binder.restoreCallingIdentity(identity);
4725 }
4726 }
4727
4728 @Override
4729 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4731 "setRttCapabilityEnabled");
4732 final long identity = Binder.clearCallingIdentity();
4733 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004734 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004735 // This setting doesn't require an active ImsService connection, so do not verify. The
4736 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004737 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004738 } catch (ImsException e) {
4739 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004740 } finally {
4741 Binder.restoreCallingIdentity(identity);
4742 }
4743 }
4744
shilu366312e2019-12-17 09:28:10 -08004745 /**
4746 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4747 * @param subId The subscription to use to check the configuration.
4748 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004749 @Override
4750 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004751 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004752 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004753 final long identity = Binder.clearCallingIdentity();
4754 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004755 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004756 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004757 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004758 } catch (ImsException e) {
4759 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
4763 }
4764
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004765 @Override
4766 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4767 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004768
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004769 final long identity = Binder.clearCallingIdentity();
4770 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004771 if (!isImsAvailableOnDevice()) {
4772 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4773 "IMS not available on device.");
4774 }
4775 int slotId = getSlotIndexOrException(subId);
4776 verifyImsMmTelConfiguredOrThrow(slotId);
4777 ImsManager.getInstance(mApp, slotId)
4778 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004779 } catch (ImsException e) {
4780 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
4784 }
4785
4786 @Override
4787 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4788 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004789
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004790 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4792 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4793 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004794 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004795 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004796 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004797 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004798 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4799 + "is inactive, ignoring unregister.");
4800 // If the subscription is no longer active, just return, since the callback will already
4801 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004802 } finally {
4803 Binder.restoreCallingIdentity(identity);
4804 }
4805 }
4806
joonhunshincffb7fc2021-11-28 07:32:01 +00004807 @Override
4808 public void registerFeatureProvisioningChangedCallback(int subId,
4809 IFeatureProvisioningCallback callback) {
4810 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4811 mApp, subId, "registerFeatureProvisioningChangedCallback");
4812
4813 final long identity = Binder.clearCallingIdentity();
4814 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4815 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4816 }
4817
joonhunshin91bc1952022-04-29 08:47:15 +00004818 try {
4819 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4820 if (controller == null) {
4821 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4822 "Device does not support IMS");
4823 }
4824 controller.addFeatureProvisioningChangedCallback(subId, callback);
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
4827 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004828 }
4829
4830 @Override
4831 public void unregisterFeatureProvisioningChangedCallback(int subId,
4832 IFeatureProvisioningCallback callback) {
4833 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4834 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4835
4836 final long identity = Binder.clearCallingIdentity();
4837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4838 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4839 }
4840
joonhunshin91bc1952022-04-29 08:47:15 +00004841 try {
4842 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4843 if (controller == null) {
4844 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4845 return;
4846 }
4847 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004851 }
allenwtsu99c623b2020-01-03 18:24:23 +08004852
4853 private void checkModifyPhoneStatePermission(int subId, String message) {
4854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4855 message);
4856 }
4857
allenwtsu99c623b2020-01-03 18:24:23 +08004858 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004859 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004860 boolean isProvisioned) {
4861 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4862
4863 final long identity = Binder.clearCallingIdentity();
4864 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004865 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4866 if (controller == null) {
4867 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4868 return;
4869 }
4870 controller.setRcsProvisioningStatusForCapability(
4871 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
allenwtsu99c623b2020-01-03 18:24:23 +08004875 }
4876
4877
4878 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004879 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4880 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4881 mApp, subId, "getRcsProvisioningStatusForCapability");
4882
allenwtsu99c623b2020-01-03 18:24:23 +08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004885 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4886 if (controller == null) {
4887 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4888
4889 // device does not support IMS, this method will return true always.
4890 return true;
4891 }
4892 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004898 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4900 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004901 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004902
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004905 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4906 if (controller == null) {
4907 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4908 return;
4909 }
4910 controller.setImsProvisioningStatusForCapability(
4911 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
4915 }
4916
4917 @Override
4918 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004919 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4920 mApp, subId, "getProvisioningStatusForCapability");
4921
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004924 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4925 if (controller == null) {
4926 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927
joonhunshin91bc1952022-04-29 08:47:15 +00004928 // device does not support IMS, this method will return true always.
4929 return true;
4930 }
4931 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004938 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4939 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4940 mApp, subId, "isProvisioningRequiredForCapability");
4941
4942 final long identity = Binder.clearCallingIdentity();
4943 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004944 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4945 if (controller == null) {
4946 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4947
4948 // device does not support IMS, this method will return false
4949 return false;
4950 }
4951 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004954 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 }
4956
4957 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004958 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4959 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4960 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961
joonhunshincffb7fc2021-11-28 07:32:01 +00004962 final long identity = Binder.clearCallingIdentity();
4963 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004964 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4965 if (controller == null) {
4966 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4967
4968 // device does not support IMS, this method will return false
4969 return false;
4970 }
4971 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004975 }
4976
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004977 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004978 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004979 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4980 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4981 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004982 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4983 mApp, subId, "getImsProvisioningInt");
4984
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004988 int slotId = getSlotIndex(subId);
4989 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4990 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4991 + subId + "' for key:" + key);
4992 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4993 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004994
joonhunshin91bc1952022-04-29 08:47:15 +00004995 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4996 if (controller == null) {
4997 loge("getImsProvisioningInt: Device does not support IMS");
4998
4999 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5000 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5001 }
5002 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005003 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5004 return retVal;
5005 }
5006
calvinpanb5a34062021-02-08 19:59:36 +08005007 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005008 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005009 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5010 + subId + "' for key:" + key);
5011 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
5015 }
5016
5017 @Override
5018 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005019 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5020 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5021 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005022 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5023 mApp, subId, "getImsProvisioningString");
5024
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005028 int slotId = getSlotIndex(subId);
5029 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5030 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5031 + subId + "' for key:" + key);
5032 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5033 }
calvinpanb5a34062021-02-08 19:59:36 +08005034 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005035 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005036 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5037 + subId + "' for key:" + key);
5038 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005039 } finally {
5040 Binder.restoreCallingIdentity(identity);
5041 }
5042 }
5043
5044 @Override
5045 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005046 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5047 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5048 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5050 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005051
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005055 int slotId = getSlotIndex(subId);
5056 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5057 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5058 + subId + "' for key:" + key);
5059 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5060 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005061
joonhunshin91bc1952022-04-29 08:47:15 +00005062 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5063 if (controller == null) {
5064 loge("setImsProvisioningInt: Device does not support IMS");
5065
5066 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5067 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5068 }
5069 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005070 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5071 return retVal;
5072 }
5073
calvinpanb5a34062021-02-08 19:59:36 +08005074 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5075 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005077 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005078 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
5082 }
5083
5084 @Override
5085 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005086 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5087 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5088 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5090 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005094 int slotId = getSlotIndex(subId);
5095 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5096 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5097 + subId + "' for key:" + key);
5098 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5099 }
calvinpanb5a34062021-02-08 19:59:36 +08005100 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5101 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005102 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005103 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005104 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
5107 }
5108 }
5109
Brad Ebinger919631e2021-06-02 17:46:35 -07005110 /**
5111 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5112 * for the given slot ID or no ImsResolver instance has been created.
5113 * @param slotId The slot ID that the IMS service is created for.
5114 * @throws ImsException If there is no ImsService configured for this slot.
5115 */
5116 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5117 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5118 ImsFeature.FEATURE_MMTEL)) {
5119 throw new ImsException("This subscription does not support MMTEL over IMS",
5120 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5121 }
5122 }
5123
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005124 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005125 int slotId = SubscriptionManager.getSlotIndex(subId);
5126 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005127 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5128 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005129 }
5130 return slotId;
5131 }
5132
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005133 private int getSlotIndex(int subId) {
5134 int slotId = SubscriptionManager.getSlotIndex(subId);
5135 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5136 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5137 }
5138 return slotId;
5139 }
5140
Wink Saville36469e72014-06-11 15:17:00 -07005141 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005142 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005143 */
5144 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005145 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5146 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005147 try {
5148 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5149 } catch (SecurityException se) {
5150 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5151 throw new SecurityException("Package " + callingPackage + " does not belong to "
5152 + Binder.getCallingUid());
5153 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005154 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005155 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005156 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005157 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005158 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005159 mApp, subId, callingPackage, callingFeatureId,
5160 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005161 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5162 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 final long identity = Binder.clearCallingIdentity();
5165 try {
5166 final Phone phone = getPhone(subId);
5167 if (phone != null) {
5168 return phone.getServiceState().getDataNetworkType();
5169 } else {
5170 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5171 }
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005175 }
5176
5177 /**
5178 * Returns the data network type
5179 */
5180 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005181 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005182 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005183 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005184 }
5185
5186 /**
5187 * Returns the data network type for a subId
5188 */
5189 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005190 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5191 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005192 String functionName = "getDataNetworkTypeForSubscriber";
5193 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5194 mApp, functionName)) {
5195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5196 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5197 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5198 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005199 }
5200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 final Phone phone = getPhone(subId);
5204 if (phone != null) {
5205 return phone.getServiceState().getDataNetworkType();
5206 } else {
5207 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5208 }
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005212 }
5213
5214 /**
Wink Saville36469e72014-06-11 15:17:00 -07005215 * Returns the Voice network type for a subId
5216 */
5217 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005218 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5219 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005220 String functionName = "getVoiceNetworkTypeForSubscriber";
5221 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5222 mApp, functionName)) {
5223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5224 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5226 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005227 }
5228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 final Phone phone = getPhone(subId);
5232 if (phone != null) {
5233 return phone.getServiceState().getVoiceNetworkType();
5234 } else {
5235 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5236 }
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005240 }
5241
5242 /**
5243 * @return true if a ICC card is present
5244 */
5245 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005246 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005247 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005248 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005249 }
5250
5251 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005252 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005253 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005254 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005255 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 final long identity = Binder.clearCallingIdentity();
5257 try {
5258 final Phone phone = PhoneFactory.getPhone(slotIndex);
5259 if (phone != null) {
5260 return phone.getIccCard().hasIccCard();
5261 } else {
5262 return false;
5263 }
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005267 }
5268
5269 /**
5270 * Return if the current radio is LTE on CDMA. This
5271 * is a tri-state return value as for a period of time
5272 * the mode may be unknown.
5273 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005274 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005275 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005276 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005277 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005278 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005279 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5280 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5281 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005282 }
5283
Sanket Padawe356d7632015-06-22 14:03:32 -07005284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005285 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5286 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005287 try {
5288 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5289 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005290 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5291 }
5292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 final Phone phone = getPhone(subId);
5296 if (phone == null) {
5297 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5298 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005299 return TelephonyProperties.lte_on_cdma_device()
5300 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 }
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005304 }
Wink Saville36469e72014-06-11 15:17:00 -07005305 }
5306
Wink Saville36469e72014-06-11 15:17:00 -07005307 /**
5308 * {@hide}
5309 * Returns Default subId, 0 in the case of single standby.
5310 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005311 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005312 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005313 }
5314
Shishir Agrawala9f32182016-04-12 12:00:16 -07005315 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005316 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005317 }
5318
Wink Savilleb564aae2014-10-23 10:18:09 -07005319 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005320 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005321 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005322
Pengquan Menge92a50d2018-09-21 15:54:48 -07005323 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005324 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5325 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5326 mApp.getOpPackageName(), mApp.getFeatureId());
5327 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005328 return mSubscriptionController.isActiveSubId(subId);
5329 }
5330
Ihab Awadf2177b72013-11-25 13:33:23 -08005331 /**
5332 * @see android.telephony.TelephonyManager.WifiCallingChoices
5333 */
5334 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 final long identity = Binder.clearCallingIdentity();
5336 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005337 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5339 getWhenToMakeWifiCallsDefaultPreference());
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005343 }
5344
5345 /**
5346 * @see android.telephony.TelephonyManager.WifiCallingChoices
5347 */
5348 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005352 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005357 }
5358
Sailesh Nepald1e68152013-12-12 19:08:02 -08005359 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005360 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005361 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005362 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005363
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005364 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5365 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5366 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005367 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005368 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5369 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005370 }
5371 return PhoneFactory.getPhone(phoneId);
5372 }
5373
Shishir Agrawal566b7612013-10-28 14:41:00 -07005374 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005375 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005376 @NonNull IccLogicalChannelRequest request) {
5377 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5378 /*message=*/ "iccOpenLogicalChannel");
5379
5380 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5381 // Verify that the callingPackage in the request belongs to the calling UID
5382 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5383
5384 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005385 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005386
Rambo Wanga1782702021-11-10 20:15:19 -08005387 private Phone getPhoneFromValidIccLogicalChannelRequest(
5388 @NonNull IccLogicalChannelRequest request, String message) {
5389 Phone phone;
5390 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5392 mApp, request.subId, message);
5393 phone = getPhoneFromSubId(request.subId);
5394 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5395 enforceModifyPermission();
5396 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5397 } else {
5398 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005399 }
Rambo Wanga1782702021-11-10 20:15:19 -08005400 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005401 }
5402
5403 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005404 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005407 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5410 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005411 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5412 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 loge("The calling package is not allowed to access ISD-R.");
5414 throw new SecurityException(
5415 "The calling package is not allowed to access ISD-R.");
5416 }
Derek Tan740e1672017-06-27 14:56:27 -07005417 }
Derek Tan740e1672017-06-27 14:56:27 -07005418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005420 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5421 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 return response;
5423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005426 }
5427
5428 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005429 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5430 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5431 /*message=*/"iccCloseLogicalChannel");
5432
5433 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5434
5435 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005436 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005437
Rambo Wanga1782702021-11-10 20:15:19 -08005438 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5439 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005440 // before this feature is enabled, this API should only return false if
5441 // the operation fails instead of throwing runtime exception for
5442 // backward-compatibility.
5443 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5444 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005447 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005448 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 }
Chen Xue9d737e2022-01-01 23:41:31 -08005450 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005451 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005452 Boolean success = false;
5453 if (result instanceof RuntimeException) {
5454 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005455 if (shouldThrowExceptionOnFailure) {
5456 throw (RuntimeException) result;
5457 } else {
5458 return false;
5459 }
Chen Xue9d737e2022-01-01 23:41:31 -08005460 } else if (result instanceof Boolean) {
5461 success = (Boolean) result;
5462 } else {
5463 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5464 }
Rambo Wanga1782702021-11-10 20:15:19 -08005465 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 return success;
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005469 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005470 }
5471
5472 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005473 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005474 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5476 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005477 if (DBG) {
5478 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5479 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5480 + p3 + " data=" + data);
5481 }
5482 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5483 command, p1, p2, p3, data);
5484 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005485
Jordan Liu4c733742019-02-28 12:03:40 -08005486 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005487 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5488 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005489 enforceModifyPermission();
5490 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005491 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5492 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5493 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005494 }
5495 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005496 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5497 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005498 }
5499
5500 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5501 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005504 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 return "";
5506 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005509 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5510 null /* workSource */);
5511 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 // Append the returned status code to the end of the response payload.
5514 String s = Integer.toHexString(
5515 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5516 if (response.payload != null) {
5517 s = IccUtils.bytesToHexString(response.payload) + s;
5518 }
5519 return s;
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005522 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005523 }
Jake Hambye994d462014-02-03 13:10:13 -08005524
Evan Charltonc66da362014-05-16 14:06:40 -07005525 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005526 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5527 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005531 if (DBG) {
5532 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5533 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5534 }
5535 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5536 cla, command, p1, p2, p3, data);
5537 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005538
Jordan Liu4c733742019-02-28 12:03:40 -08005539 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005540 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5541 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005542 enforceModifyPermission();
5543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5544 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005545 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5546 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5547 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005548 }
5549
5550 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005551 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5552 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005553 }
5554
5555 // open APDU basic channel assuming the caller has sufficient permissions
5556 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5557 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5561 && TextUtils.equals(ISDR_AID, data)) {
5562 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005563 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5564 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 if (bestComponent == null
5566 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5567 loge("The calling package is not allowed to select ISD-R.");
5568 throw new SecurityException(
5569 "The calling package is not allowed to select ISD-R.");
5570 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005571 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005574 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5575 null /* workSource */);
5576 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 // Append the returned status code to the end of the response payload.
5579 String s = Integer.toHexString(
5580 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5581 if (response.payload != null) {
5582 s = IccUtils.bytesToHexString(response.payload) + s;
5583 }
5584 return s;
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005587 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005588 }
5589
5590 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005591 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005592 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5594 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 final long identity = Binder.clearCallingIdentity();
5597 try {
5598 if (DBG) {
5599 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5600 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5601 }
5602
5603 IccIoResult response =
5604 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5605 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5606 subId);
5607
5608 if (DBG) {
5609 log("Exchange SIM_IO [R]" + response);
5610 }
5611
5612 byte[] result = null;
5613 int length = 2;
5614 if (response.payload != null) {
5615 length = 2 + response.payload.length;
5616 result = new byte[length];
5617 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5618 } else {
5619 result = new byte[length];
5620 }
5621
5622 result[length - 1] = (byte) response.sw2;
5623 result[length - 2] = (byte) response.sw1;
5624 return result;
5625 } finally {
5626 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005627 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005628 }
5629
Nathan Haroldb3014052017-01-25 15:57:32 -08005630 /**
5631 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5632 * on a particular subscription
5633 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005634 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5635 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005637 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005638 return null;
5639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 if (appType != TelephonyManager.APPTYPE_USIM
5644 && appType != TelephonyManager.APPTYPE_SIM) {
5645 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5646 return null;
5647 }
5648 Object response = sendRequest(
5649 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5650 if (response instanceof String[]) {
5651 return (String[]) response;
5652 }
yincheng zhao2737e882019-09-06 17:06:54 -07005653 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005655 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005658 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005659 }
5660
yincheng zhao2737e882019-09-06 17:06:54 -07005661 /**
5662 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5663 * subscription.
5664 *
5665 * @param subId the id of the subscription.
5666 * @param appType the uicc app type, must be USIM or SIM.
5667 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5668 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005669 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005670 * @return number of fplmns that is successfully written to the SIM.
5671 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005672 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5673 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5675 mApp, subId, "setForbiddenPlmns");
5676
yincheng zhao2737e882019-09-06 17:06:54 -07005677 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5678 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5679 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5680 }
5681 if (fplmns == null) {
5682 throw new IllegalArgumentException("Fplmn List provided is null");
5683 }
5684 for (String fplmn : fplmns) {
5685 if (!CellIdentity.isValidPlmn(fplmn)) {
5686 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5687 }
5688 }
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 Object response = sendRequest(
5692 CMD_SET_FORBIDDEN_PLMNS,
5693 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5694 subId);
5695 return (int) response;
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
5699 }
5700
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005701 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005702 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5704 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 final long identity = Binder.clearCallingIdentity();
5707 try {
5708 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5709 if (response.payload == null) {
5710 return "";
5711 }
Evan Charltonc66da362014-05-16 14:06:40 -07005712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 // Append the returned status code to the end of the response payload.
5714 String s = Integer.toHexString(
5715 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5716 s = IccUtils.bytesToHexString(response.payload) + s;
5717 return s;
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Evan Charltonc66da362014-05-16 14:06:40 -07005721 }
5722
Jake Hambye994d462014-02-03 13:10:13 -08005723 /**
5724 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5725 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5726 *
5727 * @param itemID the ID of the item to read
5728 * @return the NV item as a String, or null on error.
5729 */
5730 @Override
5731 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005732 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5734 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005739 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5741 return value;
5742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Jake Hambye994d462014-02-03 13:10:13 -08005745 }
5746
5747 /**
5748 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5749 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5750 *
5751 * @param itemID the ID of the item to read
5752 * @param itemValue the value to write, as a String
5753 * @return true on success; false on any failure
5754 */
5755 @Override
5756 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005757 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5759 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760
5761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5764 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005765 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5767 return success;
5768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Jake Hambye994d462014-02-03 13:10:13 -08005771 }
5772
5773 /**
5774 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5775 * Used for device configuration by some CDMA operators.
5776 *
5777 * @param preferredRoamingList byte array containing the new PRL
5778 * @return true on success; false on any failure
5779 */
5780 @Override
5781 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5783 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784
5785 final long identity = Binder.clearCallingIdentity();
5786 try {
5787 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5788 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5789 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5790 return success;
5791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Jake Hambye994d462014-02-03 13:10:13 -08005794 }
5795
5796 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005797 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005798 * Used for device configuration by some CDMA operators.
5799 *
chen xu6dac5ab2018-10-26 17:39:23 -07005800 * @param slotIndex - device slot.
5801 *
Jake Hambye994d462014-02-03 13:10:13 -08005802 * @return true on success; false on any failure
5803 */
5804 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005805 public boolean resetModemConfig(int slotIndex) {
5806 Phone phone = PhoneFactory.getPhone(slotIndex);
5807 if (phone != null) {
5808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5809 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810
chen xu6dac5ab2018-10-26 17:39:23 -07005811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5814 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5815 return success;
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
5818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 }
chen xu6dac5ab2018-10-26 17:39:23 -07005820 return false;
5821 }
5822
5823 /**
5824 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5825 *
5826 * @param slotIndex - device slot.
5827 *
5828 * @return true on success; false on any failure
5829 */
5830 @Override
5831 public boolean rebootModem(int slotIndex) {
5832 Phone phone = PhoneFactory.getPhone(slotIndex);
5833 if (phone != null) {
5834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5835 mApp, phone.getSubId(), "rebootModem");
5836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
5839 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5840 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5841 return success;
5842 } finally {
5843 Binder.restoreCallingIdentity(identity);
5844 }
5845 }
5846 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005847 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005848
Brad Ebinger51f743a2017-01-23 13:50:20 -08005849 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005850 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5851 * {@link #disableIms(int)}.
5852 * @param slotIndex device slot.
5853 */
5854 public void resetIms(int slotIndex) {
5855 enforceModifyPermission();
5856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 if (mImsResolver == null) {
5860 // may happen if the does not support IMS.
5861 return;
5862 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005863 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
5867 }
5868
5869 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005870 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5871 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005872 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005873 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005879 // may happen if the device does not support IMS.
5880 return;
5881 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005886 }
5887
5888 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005889 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5890 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005891 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005892 public void disableIms(int slotId) {
5893 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894
5895 final long identity = Binder.clearCallingIdentity();
5896 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005897 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005898 // may happen if the device does not support IMS.
5899 return;
5900 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005905 }
5906
5907 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005908 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5909 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005910 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005911 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005912 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005913 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914
5915 final long identity = Binder.clearCallingIdentity();
5916 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005918 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5919 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005920 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005921 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005925 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005926 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005927 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5928 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005929 @Override
5930 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005931 enforceModifyPermission();
5932
5933 final long identity = Binder.clearCallingIdentity();
5934 try {
5935 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005936 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
5940 }
5941
5942 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005943 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005944 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005945 */
5946 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948
5949 final long identity = Binder.clearCallingIdentity();
5950 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005952 // may happen if the device does not support IMS.
5953 return null;
5954 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005959 }
5960
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005961 /**
5962 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005963 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005964 */
5965 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005970 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005971 // may happen if the device does not support IMS.
5972 return null;
5973 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005974 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005978 }
5979
Brad Ebinger884c07b2018-02-15 16:17:40 -08005980 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005981 * Sets the ImsService Package Name that Telephony will bind to.
5982 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005983 * @param slotIndex the slot ID that the ImsService should bind for.
5984 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005985 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005986 * @param featureTypes An integer array of feature types associated with a packageName.
5987 * @param packageName The name of the package that the current configuration will be replaced
5988 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005989 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005990 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005991 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5992 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08005995 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 final long identity = Binder.clearCallingIdentity();
5998 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005999 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006000 // may happen if the device does not support IMS.
6001 return false;
6002 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006003 Map<Integer, String> featureConfig = new HashMap<>();
6004 for (int featureType : featureTypes) {
6005 featureConfig.put(featureType, packageName);
6006 }
6007 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6008 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006012 }
6013
6014 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006015 * Clears any carrier ImsService overrides for the slot index specified that were previously
6016 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6017 *
6018 * This should only be used for testing.
6019 *
6020 * @param slotIndex the slot ID that the ImsService should bind for.
6021 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6022 */
6023 @Override
6024 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6026 "clearCarrierImsServiceOverride");
6027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006028 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006029
6030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 if (mImsResolver == null) {
6033 // may happen if the device does not support IMS.
6034 return false;
6035 }
6036 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
6040 }
6041
6042 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006043 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006044 *
6045 * @param slotId The slot that the ImsService is associated with.
6046 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6047 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006048 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006049 * @return the package name of the ImsService configuration.
6050 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6052 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006053 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006054 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6055 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 final long identity = Binder.clearCallingIdentity();
6058 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006059 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006060 // may happen if the device does not support IMS.
6061 return "";
6062 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006063 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006064 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6065 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006069 }
6070
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006071 /**
6072 * Get the MmTelFeature state associated with the requested subscription id.
6073 * @param subId The subscription that the MmTelFeature is associated with.
6074 * @param callback A callback with an integer containing the
6075 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6076 */
6077 @Override
6078 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6079 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006080 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6081 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6082 "IMS not available on device.");
6083 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006084 final long token = Binder.clearCallingIdentity();
6085 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006086 int slotId = getSlotIndex(subId);
6087 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6088 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6089 + subId + "'");
6090 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6091 }
6092 verifyImsMmTelConfiguredOrThrow(slotId);
6093 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6094 try {
6095 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6096 } catch (RemoteException e) {
6097 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6098 + "Ignore");
6099 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006100 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006101 } catch (ImsException e) {
6102 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006103 } finally {
6104 Binder.restoreCallingIdentity(token);
6105 }
6106 }
6107
Daniel Brightbb5840b2021-01-12 15:48:18 -08006108 /**
6109 * Sets the ims registration state on all valid {@link Phone}s.
6110 */
6111 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113
6114 final long identity = Binder.clearCallingIdentity();
6115 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006116 // NOTE: Before S, this method only set the default phone.
6117 for (final Phone phone : PhoneFactory.getPhones()) {
6118 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6119 phone.setImsRegistrationState(registered);
6120 }
6121 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
Wink Saville36469e72014-06-11 15:17:00 -07006125 }
6126
6127 /**
Stuart Scott54788802015-03-30 13:18:01 -07006128 * Set the network selection mode to automatic.
6129 *
6130 */
6131 @Override
6132 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6134 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135
6136 final long identity = Binder.clearCallingIdentity();
6137 try {
shilufc958392020-01-20 11:36:01 -08006138 if (!isActiveSubscription(subId)) {
6139 return;
6140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006142 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6143 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
Stuart Scott54788802015-03-30 13:18:01 -07006147 }
6148
Jack Yud10cdd42020-09-28 20:28:01 -07006149 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006150 * Ask the radio to connect to the input network and change selection mode to manual.
6151 *
6152 * @param subId the id of the subscription.
6153 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6154 * the operator to attach to.
6155 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6156 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6157 * normal network selection next time.
6158 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006159 */
6160 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006161 public boolean setNetworkSelectionModeManual(
6162 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6164 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006165
Jack Yu285100e2022-12-02 22:48:35 -08006166 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006167 if (!isActiveSubscription(subId)) {
6168 return false;
6169 }
6170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006172 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006174 if (DBG) {
6175 log("setNetworkSelectionModeManual: subId: " + subId
6176 + " operator: " + operatorInfo);
6177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006182 }
shilu84f6e8b2019-12-19 13:58:01 -08006183 /**
6184 * Get the manual network selection
6185 *
6186 * @param subId the id of the subscription.
6187 *
6188 * @return the previously saved user selected PLMN
6189 */
6190 @Override
6191 public String getManualNetworkSelectionPlmn(int subId) {
6192 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006193 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006194 mApp, subId, "getManualNetworkSelectionPlmn");
6195
6196 final long identity = Binder.clearCallingIdentity();
6197 try {
6198 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006199 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006200 }
6201
6202 final Phone phone = getPhone(subId);
6203 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006204 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006205 }
6206 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6207 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6208 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
6212 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006213
6214 /**
6215 * Scans for available networks.
6216 */
6217 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006218 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6219 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6221 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006222 LocationAccessPolicy.LocationPermissionResult locationResult =
6223 LocationAccessPolicy.checkLocationPermission(mApp,
6224 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6225 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006226 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006227 .setCallingPid(Binder.getCallingPid())
6228 .setCallingUid(Binder.getCallingUid())
6229 .setMethod("getCellNetworkScanResults")
6230 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006231 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6232 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006233 .build());
6234 switch (locationResult) {
6235 case DENIED_HARD:
6236 throw new SecurityException("Not allowed to access scan results -- location");
6237 case DENIED_SOFT:
6238 return null;
6239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240
Pengquan Menga1bb6272018-09-06 09:59:22 -07006241 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 try {
6243 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006244 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 } finally {
6247 Binder.restoreCallingIdentity(identity);
6248 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006249 }
6250
6251 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006252 * Get the call forwarding info, given the call forwarding reason.
6253 */
6254 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006255 public void getCallForwarding(int subId, int callForwardingReason,
6256 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006257 enforceReadPrivilegedPermission("getCallForwarding");
6258 long identity = Binder.clearCallingIdentity();
6259 try {
6260 if (DBG) {
6261 log("getCallForwarding: subId " + subId
6262 + " callForwardingReason" + callForwardingReason);
6263 }
Hall Liu27d24262020-09-18 19:04:59 -07006264
6265 Phone phone = getPhone(subId);
6266 if (phone == null) {
6267 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006268 callback.onError(
6269 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006270 } catch (RemoteException e) {
6271 // ignore
6272 }
6273 return;
6274 }
6275
6276 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6277 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6278 @Override
6279 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6280 try {
6281 callback.onCallForwardingInfoAvailable(info);
6282 } catch (RemoteException e) {
6283 // ignore
6284 }
6285 }
6286
6287 @Override
6288 public void onError(int error) {
6289 try {
6290 callback.onError(error);
6291 } catch (RemoteException e) {
6292 // ignore
6293 }
6294 }
6295 });
6296 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006297 } finally {
6298 Binder.restoreCallingIdentity(identity);
6299 }
6300 }
6301
6302 /**
6303 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6304 * reason, the number to forward, and the timeout before the forwarding is attempted.
6305 */
6306 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006307 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6308 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006309 enforceModifyPermission();
6310 long identity = Binder.clearCallingIdentity();
6311 try {
6312 if (DBG) {
6313 log("setCallForwarding: subId " + subId
6314 + " callForwardingInfo" + callForwardingInfo);
6315 }
Hall Liu27d24262020-09-18 19:04:59 -07006316
6317 Phone phone = getPhone(subId);
6318 if (phone == null) {
6319 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006320 callback.accept(
6321 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006322 } catch (RemoteException e) {
6323 // ignore
6324 }
6325 return;
6326 }
6327
6328 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6329 FunctionalUtils.ignoreRemoteException(callback::accept));
6330
6331 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 }
6336
6337 /**
Hall Liu27d24262020-09-18 19:04:59 -07006338 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006339 */
6340 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006341 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006342 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006343 long identity = Binder.clearCallingIdentity();
6344 try {
Hall Liu27d24262020-09-18 19:04:59 -07006345 Phone phone = getPhone(subId);
6346 if (phone == null) {
6347 try {
6348 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6349 } catch (RemoteException e) {
6350 // ignore
6351 }
6352 return;
6353 }
SongFerngWang0e767992021-03-31 22:08:45 +08006354 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6355 PersistableBundle c = configManager.getConfigForSubId(subId);
6356 boolean requireUssd = c.getBoolean(
6357 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006358
Shuo Qian4a594052020-01-23 11:59:30 -08006359 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006360 if (requireUssd) {
6361 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6362 getSubscriptionCarrierId(subId));
6363 String newUssdCommand = "";
6364 try {
6365 newUssdCommand = carrierXmlParser.getFeature(
6366 CarrierXmlParser.FEATURE_CALL_WAITING)
6367 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6368 } catch (NullPointerException e) {
6369 loge("Failed to generate USSD number" + e);
6370 }
6371 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6372 mMainThreadHandler, callback, carrierXmlParser,
6373 CarrierXmlParser.SsEntry.SSAction.QUERY);
6374 final String ussdCommand = newUssdCommand;
6375 Executors.newSingleThreadExecutor().execute(() -> {
6376 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6377 });
6378 } else {
6379 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6380 callback::accept);
6381 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6382 }
Shuo Qian4a594052020-01-23 11:59:30 -08006383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
6386 }
6387
6388 /**
Hall Liu27d24262020-09-18 19:04:59 -07006389 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006390 */
6391 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006392 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006393 enforceModifyPermission();
6394 long identity = Binder.clearCallingIdentity();
6395 try {
Hall Liu27d24262020-09-18 19:04:59 -07006396 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6397
6398 Phone phone = getPhone(subId);
6399 if (phone == null) {
6400 try {
6401 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6402 } catch (RemoteException e) {
6403 // ignore
6404 }
6405 return;
6406 }
6407
SongFerngWang0e767992021-03-31 22:08:45 +08006408 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6409 PersistableBundle c = configManager.getConfigForSubId(subId);
6410 boolean requireUssd = c.getBoolean(
6411 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006412
SongFerngWang0e767992021-03-31 22:08:45 +08006413 if (DBG) log("getCallWaitingStatus: subId " + subId);
6414 if (requireUssd) {
6415 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6416 getSubscriptionCarrierId(subId));
6417 CarrierXmlParser.SsEntry.SSAction ssAction =
6418 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6419 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6420 String newUssdCommand = "";
6421 try {
6422 newUssdCommand = carrierXmlParser.getFeature(
6423 CarrierXmlParser.FEATURE_CALL_WAITING)
6424 .makeCommand(ssAction, null);
6425 } catch (NullPointerException e) {
6426 loge("Failed to generate USSD number" + e);
6427 }
6428 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6429 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6430 final String ussdCommand = newUssdCommand;
6431 Executors.newSingleThreadExecutor().execute(() -> {
6432 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6433 });
6434 } else {
6435 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6436 FunctionalUtils.ignoreRemoteException(callback::accept));
6437
6438 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6439 }
Shuo Qian4a594052020-01-23 11:59:30 -08006440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
6443 }
6444
6445 /**
yinxub1bed742017-04-17 11:45:04 -07006446 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006447 *
yinxub1bed742017-04-17 11:45:04 -07006448 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006449 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6450 * location related information which will be sent if the caller already possess
6451 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006452 * @param request contains the radio access networks with bands/channels to scan
6453 * @param messenger callback messenger for scan results or errors
6454 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006455 * @return the id of the requested scan which can be used to stop the scan.
6456 */
6457 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006458 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6459 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006460 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6462 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006463 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006464 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6465 if (!renounceFineLocationAccess) {
6466 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6467 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6468 .setCallingPackage(callingPackage)
6469 .setCallingFeatureId(callingFeatureId)
6470 .setCallingPid(Binder.getCallingPid())
6471 .setCallingUid(Binder.getCallingUid())
6472 .setMethod("requestNetworkScan")
6473 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6474 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6475 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6476 .build());
6477 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006478 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006479 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6480 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006481 if (e != null) {
6482 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6483 throw e;
6484 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006485 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006486 return TelephonyScanManager.INVALID_SCAN_ID;
6487 }
6488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 }
Hall Liu912dfd32019-04-25 14:02:26 -07006490 int callingUid = Binder.getCallingUid();
6491 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006495 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006496 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
yinxu504e1392017-04-12 16:03:22 -07006500 }
6501
Hall Liub2ac8ef2019-02-28 15:56:23 -08006502 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006503 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006504 boolean hasCarrierPriv;
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6508 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
Hall Liu558027f2019-05-15 19:14:05 -07006512 boolean hasNetworkScanPermission =
6513 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6514 == PERMISSION_GRANTED;
6515
6516 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6517 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6518 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006519 }
6520
6521 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6522 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006523 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6524 return new SecurityException("Specific channels must not be"
6525 + " scanned without location access.");
6526 }
6527 }
6528 }
6529
Hall Liub2ac8ef2019-02-28 15:56:23 -08006530 return null;
6531 }
6532
yinxu504e1392017-04-12 16:03:22 -07006533 /**
6534 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006535 *
6536 * @param subId id of the subscription
6537 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006538 */
6539 @Override
6540 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6542 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543
Hall Liu912dfd32019-04-25 14:02:26 -07006544 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 final long identity = Binder.clearCallingIdentity();
6546 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006547 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
yinxu504e1392017-04-12 16:03:22 -07006551 }
6552
6553 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006555 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006556 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006557 */
6558 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006559 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006560 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006561 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006562 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006566 if (DBG) log("getAllowedNetworkTypesBitmask");
6567 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6568 int networkTypesBitmask = (result != null ? result[0] : -1);
6569 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6570 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006574 }
6575
6576 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006577 * Get the allowed network types for certain reason.
6578 *
6579 * @param subId the id of the subscription.
6580 * @param reason the reason the allowed network type change is taking place
6581 * @return the allowed network types.
6582 */
6583 @Override
6584 public long getAllowedNetworkTypesForReason(int subId,
6585 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006586 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006587 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006588 final long identity = Binder.clearCallingIdentity();
6589 try {
6590 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6591 } finally {
6592 Binder.restoreCallingIdentity(identity);
6593 }
6594 }
6595
6596 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006597 * Enable/Disable E-UTRA-NR Dual Connectivity
6598 * @param subId subscription id of the sim card
6599 * @param nrDualConnectivityState expected NR dual connectivity state
6600 * This can be passed following states
6601 * <ol>
6602 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6603 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6604 * <li>Disable NR dual connectivity and force secondary cell to be released
6605 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6606 * </ol>
6607 * @return operation result.
6608 */
6609 @Override
6610 public int setNrDualConnectivityState(int subId,
6611 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6613 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006614 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006615 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6616 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6617 }
6618
Sooraj Sasindran37444802020-08-11 10:40:43 -07006619 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6620 final long identity = Binder.clearCallingIdentity();
6621 try {
6622 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6623 nrDualConnectivityState, subId,
6624 workSource);
6625 if (DBG) log("enableNRDualConnectivity result: " + result);
6626 return result;
6627 } finally {
6628 Binder.restoreCallingIdentity(identity);
6629 }
6630 }
6631
6632 /**
6633 * Is E-UTRA-NR Dual Connectivity enabled
6634 * @return true if dual connectivity is enabled else false
6635 */
6636 @Override
6637 public boolean isNrDualConnectivityEnabled(int subId) {
6638 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006639 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006640 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006641 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006642 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6643 return false;
6644 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006645 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6649 null, subId, workSource);
6650 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6651 return isEnabled;
6652 } finally {
6653 Binder.restoreCallingIdentity(identity);
6654 }
6655 }
6656
6657 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006658 * Set the allowed network types of the device and
6659 * provide the reason triggering the allowed network change.
6660 *
6661 * @param subId the id of the subscription.
6662 * @param reason the reason the allowed network type change is taking place
6663 * @param allowedNetworkTypes the allowed network types.
6664 * @return true on success; false on any failure.
6665 */
6666 @Override
6667 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006668 @TelephonyManager.AllowedNetworkTypesReason int reason,
6669 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6671 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006672 // If the caller only has carrier privileges, then they should not be able to override
6673 // any network types which were set for security reasons.
6674 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6675 != PERMISSION_GRANTED
6676 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6677 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6678 throw new SecurityException(
6679 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6680 + " reason "
6681 + reason);
6682 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006683 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006684 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6685 return false;
6686 }
6687 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6688 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006689 return false;
6690 }
6691
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006692 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6693 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6694
6695
6696 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6697 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6698 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006699 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006700
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006701 final long identity = Binder.clearCallingIdentity();
6702 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006703 Boolean success = (Boolean) sendRequest(
6704 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6705 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6706
6707 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6708 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006709 } finally {
6710 Binder.restoreCallingIdentity(identity);
6711 }
6712 }
6713
6714 /**
Miaoa84611c2019-03-15 09:21:10 +08006715 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006716 *
Miaoa84611c2019-03-15 09:21:10 +08006717 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006718 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006719 * @hide
6720 */
6721 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006722 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006723 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006725 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 try {
Miaoa84611c2019-03-15 09:21:10 +08006727 if (phone != null) {
6728 return phone.hasMatchedTetherApnSetting();
6729 } else {
6730 return false;
6731 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 } finally {
6733 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006734 }
Junda Liu475951f2014-11-07 16:45:03 -08006735 }
6736
6737 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006738 * Get the user enabled state of Mobile Data.
6739 *
6740 * TODO: remove and use isUserDataEnabled.
6741 * This can't be removed now because some vendor codes
6742 * calls through ITelephony directly while they should
6743 * use TelephonyManager.
6744 *
6745 * @return true on enabled
6746 */
6747 @Override
6748 public boolean getDataEnabled(int subId) {
6749 return isUserDataEnabled(subId);
6750 }
6751
6752 /**
6753 * Get whether mobile data is enabled per user setting.
6754 *
6755 * There are other factors deciding whether mobile data is actually enabled, but they are
6756 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006757 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006758 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6759 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006760 *
6761 * @return {@code true} if data is enabled else {@code false}
6762 */
6763 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006764 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006765 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006766 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006767 try {
6768 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6769 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006770 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006771 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6772 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006773 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006775 mApp, subId, functionName);
6776
Robert Greenwalt646120a2014-05-23 11:54:03 -07006777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
Jack Yu285100e2022-12-02 22:48:35 -08006781 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6783 Phone phone = PhoneFactory.getPhone(phoneId);
6784 if (phone != null) {
6785 boolean retVal = phone.isUserDataEnabled();
6786 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6787 return retVal;
6788 } else {
6789 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6790 return false;
6791 }
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006794 }
6795 }
6796
6797 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006798 * Checks if the device is capable of mobile data by considering whether whether the
6799 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6800 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006801 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006802 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006803 */
6804 @Override
6805 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006806 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006807 try {
6808 try {
6809 mApp.enforceCallingOrSelfPermission(
6810 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006811 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006812 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006813 try {
6814 mApp.enforceCallingOrSelfPermission(
6815 android.Manifest.permission.READ_PHONE_STATE,
6816 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006817 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006818 mApp.enforceCallingOrSelfPermission(
6819 permission.READ_BASIC_PHONE_STATE, functionName);
6820 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006821 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006822 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006823 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825
6826 final long identity = Binder.clearCallingIdentity();
6827 try {
Jack Yu285100e2022-12-02 22:48:35 -08006828 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 Phone phone = PhoneFactory.getPhone(phoneId);
6830 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006831 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006832 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 return retVal;
6834 } else {
6835 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6836 return false;
6837 }
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006840 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006841 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006842
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006843 /**
6844 * Check if data is enabled for a specific reason
6845 * @param subId Subscription index
6846 * @param reason the reason the data enable change is taking place
6847 * @return {@code true} if the overall data is enabled; {@code false} if not.
6848 */
6849 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006850 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006851 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006852 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006853 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006854 try {
6855 mApp.enforceCallingOrSelfPermission(
6856 android.Manifest.permission.ACCESS_NETWORK_STATE,
6857 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006858 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006859 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6860 functionName);
6861 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006862 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006863 try {
6864 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006865 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006866 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006868 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006869 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006870 }
6871
6872
6873 final long identity = Binder.clearCallingIdentity();
6874 try {
Jack Yu285100e2022-12-02 22:48:35 -08006875 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006876 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006877 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006878 + " reason=" + reason);
6879 }
6880 Phone phone = PhoneFactory.getPhone(phoneId);
6881 if (phone != null) {
6882 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006883 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006884 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006885 return retVal;
6886 } else {
6887 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006888 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006889 + subId + " retVal=false");
6890 }
6891 return false;
6892 }
6893 } finally {
6894 Binder.restoreCallingIdentity(identity);
6895 }
6896 }
6897
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006898 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006899 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006900 // No permission needed; this only lets the caller inspect their own status.
6901 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006902 }
Junda Liu29340342014-07-10 15:23:27 -07006903
6904 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006905 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006906 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006907 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6908 }
6909
6910 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6911 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006912 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006913 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006914 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6915 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006916 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6917 if (cpt == null) {
6918 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6920 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006922 }
6923
6924 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006925 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006926 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006927 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006928 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006929 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006930 Phone phone = getPhone(subId);
6931 if (phone == null) {
6932 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6934 }
6935 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6936 if (cpt == null) {
6937 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6939 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006940 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006941 }
6942
6943 @Override
6944 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006945 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006946 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6947 }
6948
6949 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006950 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006951 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006952 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006953 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006954 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6955 Phone phone = PhoneFactory.getPhone(phoneId);
6956 if (phone == null) {
6957 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006958 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006959 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6960 if (cpt == null) {
6961 continue;
6962 }
6963 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006964 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6965 break;
6966 }
6967 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006968 return result;
Junda Liu29340342014-07-10 15:23:27 -07006969 }
Derek Tan89e89d42014-07-08 17:00:10 -07006970
6971 @Override
Junda Liue64de782015-04-16 17:19:16 -07006972 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006973 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006974 Phone phone = PhoneFactory.getPhone(phoneId);
6975 if (phone == null) {
6976 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006977 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006978 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6979 if (cpt == null) {
6980 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006981 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006982 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006983 }
6984
Amith Yamasani6e118872016-02-19 12:53:51 -08006985 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006986 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006987 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006988 Phone phone = PhoneFactory.getPhone(phoneId);
6989 if (phone == null) {
6990 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006991 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006992 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6993 if (cpt == null) {
6994 return Collections.emptyList();
6995 }
6996 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006997 }
6998
chen xuf7e9fe82019-05-09 19:31:02 -07006999 @Override
7000 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007001 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007002 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007003 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007004 try {
7005 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7006 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7007 }
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007010 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007011 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007012 }
7013
Rambo Wang6812ffb2022-03-15 16:54:17 -07007014 @Override
7015 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7016 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7017
7018 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7019 if (phone == null) {
7020 return null;
7021 }
7022 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7023 if (cpt == null) {
7024 return null;
7025 }
7026 return cpt.getCarrierServicePackageName();
7027 }
7028
Wink Savilleb564aae2014-10-23 10:18:09 -07007029 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007030 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007031 UiccPort port = phone == null ? null : phone.getUiccPort();
7032 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007033 return null;
7034 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007035 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007036 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007037 return null;
7038 }
7039 return iccId;
7040 }
7041
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007042 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007043 public void setCallComposerStatus(int subId, int status) {
7044 enforceModifyPermission();
7045
7046 final long identity = Binder.clearCallingIdentity();
7047 try {
7048 Phone phone = getPhone(subId);
7049 if (phone != null) {
7050 Phone defaultPhone = phone.getImsPhone();
7051 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7052 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7053 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7055 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007056 }
7057 }
Shuo Qian284ae752020-12-22 19:10:14 -08007058 } catch (ImsException e) {
7059 throw new ServiceSpecificException(e.getCode());
7060 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007061 Binder.restoreCallingIdentity(identity);
7062 }
7063 }
7064
7065 @Override
7066 public int getCallComposerStatus(int subId) {
7067 enforceReadPrivilegedPermission("getCallComposerStatus");
7068
7069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 Phone phone = getPhone(subId);
7072 if (phone != null) {
7073 Phone defaultPhone = phone.getImsPhone();
7074 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7075 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7076 return imsPhone.getCallComposerStatus();
7077 }
7078 }
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7083 }
7084
7085 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007086 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7087 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007088 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 final long identity = Binder.clearCallingIdentity();
7092 try {
7093 final String iccId = getIccId(subId);
7094 final Phone phone = getPhone(subId);
7095 if (phone == null) {
7096 return false;
7097 }
7098 final String subscriberId = phone.getSubscriberId();
7099
7100 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007101 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 + subscriberId + " to " + number);
7103 }
7104
7105 if (TextUtils.isEmpty(iccId)) {
7106 return false;
7107 }
7108
7109 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7110
7111 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7112 if (alphaTag == null) {
7113 editor.remove(alphaTagPrefKey);
7114 } else {
7115 editor.putString(alphaTagPrefKey, alphaTag);
7116 }
7117
7118 // Record both the line number and IMSI for this ICCID, since we need to
7119 // track all merged IMSIs based on line number
7120 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7121 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7122 if (number == null) {
7123 editor.remove(numberPrefKey);
7124 editor.remove(subscriberPrefKey);
7125 } else {
7126 editor.putString(numberPrefKey, number);
7127 editor.putString(subscriberPrefKey, subscriberId);
7128 }
7129
7130 editor.commit();
7131 return true;
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007134 }
Derek Tan7226c842014-07-02 17:42:23 -07007135 }
7136
7137 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007138 public String getLine1NumberForDisplay(int subId, String callingPackage,
7139 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007140 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007142 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007143 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007144 return null;
7145 }
Derek Tan97ebb422014-09-05 16:55:38 -07007146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 String iccId = getIccId(subId);
7150 if (iccId != null) {
7151 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7152 if (DBG_MERGE) {
7153 log("getLine1NumberForDisplay returning "
7154 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7155 }
7156 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7159 return null;
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007162 }
Derek Tan7226c842014-07-02 17:42:23 -07007163 }
7164
7165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007166 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7167 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007169 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007170 return null;
7171 }
Derek Tan97ebb422014-09-05 16:55:38 -07007172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 String iccId = getIccId(subId);
7176 if (iccId != null) {
7177 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7178 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7179 }
7180 return null;
7181 } finally {
7182 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007183 }
Derek Tan7226c842014-07-02 17:42:23 -07007184 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007185
7186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007187 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7188 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007189 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7190 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007192 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007193 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007194 return null;
7195 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007196
Jordan Liub49b04b2019-05-06 14:45:15 -07007197 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7198 // the process, where TelephonyManager was instantiated.
7199 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007200 final long identity = Binder.clearCallingIdentity();
7201 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007202 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 final TelephonyManager tele = TelephonyManager.from(context);
7204 final SubscriptionManager sub = SubscriptionManager.from(context);
7205
7206 // Figure out what subscribers are currently active
7207 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208
Jordan Liub49b04b2019-05-06 14:45:15 -07007209 // Only consider subs which match the current subId
7210 // This logic can be simplified. See b/131189269 for progress.
7211 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007212 activeSubscriberIds.add(tele.getSubscriberId(subId));
7213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214
7215 // First pass, find a number override for an active subscriber
7216 String mergeNumber = null;
7217 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7218 for (String key : prefs.keySet()) {
7219 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7220 final String subscriberId = (String) prefs.get(key);
7221 if (activeSubscriberIds.contains(subscriberId)) {
7222 final String iccId = key.substring(
7223 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7224 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7225 mergeNumber = (String) prefs.get(numberKey);
7226 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007227 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 + " for active subscriber " + subscriberId);
7229 }
7230 if (!TextUtils.isEmpty(mergeNumber)) {
7231 break;
7232 }
7233 }
7234 }
7235 }
7236
7237 // Shortcut when no active merged subscribers
7238 if (TextUtils.isEmpty(mergeNumber)) {
7239 return null;
7240 }
7241
7242 // Second pass, find all subscribers under that line override
7243 final ArraySet<String> result = new ArraySet<>();
7244 for (String key : prefs.keySet()) {
7245 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7246 final String number = (String) prefs.get(key);
7247 if (mergeNumber.equals(number)) {
7248 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7249 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7250 final String subscriberId = (String) prefs.get(subscriberKey);
7251 if (!TextUtils.isEmpty(subscriberId)) {
7252 result.add(subscriberId);
7253 }
7254 }
7255 }
7256 }
7257
7258 final String[] resultArray = result.toArray(new String[result.size()]);
7259 Arrays.sort(resultArray);
7260 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007261 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7263 }
7264 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007265 } finally {
7266 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007267 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007268 }
7269
7270 @Override
zoey chen38003472019-12-13 17:16:31 +08007271 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7272 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007273
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 final TelephonyManager telephonyManager = mApp.getSystemService(
7277 TelephonyManager.class);
7278 String subscriberId = telephonyManager.getSubscriberId(subId);
7279 if (subscriberId == null) {
7280 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007281 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007282 + subId);
7283 }
7284 return null;
7285 }
7286
Jack Yu285100e2022-12-02 22:48:35 -08007287 ParcelUuid groupUuid;
7288 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7289 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7290 .getSubscriptionInfo(subId);
7291 groupUuid = info.getGroupUuid();
7292 } else {
7293 final SubscriptionInfo info = mSubscriptionController
7294 .getSubscriptionInfo(subId);
7295 groupUuid = info.getGroupUuid();
7296 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007297 // If it doesn't belong to any group, return just subscriberId of itself.
7298 if (groupUuid == null) {
7299 return new String[]{subscriberId};
7300 }
7301
7302 // Get all subscriberIds from the group.
7303 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007304 List<SubscriptionInfo> groupInfos;
7305 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7306 groupInfos = SubscriptionManagerService.getInstance()
7307 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7308 mApp.getAttributionTag());
7309 } else {
7310 groupInfos = mSubscriptionController
7311 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7312 mApp.getAttributionTag());
7313 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007314 for (SubscriptionInfo subInfo : groupInfos) {
7315 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7316 if (subscriberId != null) {
7317 mergedSubscriberIds.add(subscriberId);
7318 }
7319 }
7320
7321 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
7324
7325 }
7326 }
7327
7328 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007329 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007330 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007331 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 final Phone phone = getPhone(subId);
7336 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007340 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007341
7342 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007343 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007344 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7345 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007346 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7347 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348
7349 final long identity = Binder.clearCallingIdentity();
7350 try {
7351 final Phone phone = getPhone(subId);
7352 if (phone == null) {
7353 return false;
7354 }
7355 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7356 cdmaNonRoamingList);
7357 } finally {
7358 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007359 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007360 }
7361
7362 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007363 @Deprecated
7364 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7365 enforceModifyPermission();
7366
7367 int returnValue = 0;
7368 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007369 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007370 if(result.exception == null) {
7371 if (result.result != null) {
7372 byte[] responseData = (byte[])(result.result);
7373 if(responseData.length > oemResp.length) {
7374 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7375 responseData.length + "bytes. Buffer Size is " +
7376 oemResp.length + "bytes.");
7377 }
7378 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7379 returnValue = responseData.length;
7380 }
7381 } else {
7382 CommandException ex = (CommandException) result.exception;
7383 returnValue = ex.getCommandError().ordinal();
7384 if(returnValue > 0) returnValue *= -1;
7385 }
7386 } catch (RuntimeException e) {
7387 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7388 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7389 if(returnValue > 0) returnValue *= -1;
7390 }
7391
7392 return returnValue;
7393 }
7394
7395 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007396 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007397 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007398 try {
7399 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007400 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007401 mApp, phone.getSubId(), "getRadioAccessFamily");
7402 } catch (SecurityException e) {
7403 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7404 throw e;
7405 }
chen xub97461a2018-10-26 14:17:57 -07007406 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007407 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007408 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 final long identity = Binder.clearCallingIdentity();
7411 try {
chen xub97461a2018-10-26 14:17:57 -07007412 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007413 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007414 mApp, phone.getSubId(), "getRadioAccessFamily");
7415 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 } finally {
7417 Binder.restoreCallingIdentity(identity);
7418 }
chen xub97461a2018-10-26 14:17:57 -07007419 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007420 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007421
7422 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007423 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007424 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007425 try {
7426 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7427 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007428 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007429 }
7430 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007431 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007432 }
7433 RoleManager rm = mApp.getSystemService(RoleManager.class);
7434 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7435 if (!dialerRoleHolders.contains(callingPackage)) {
7436 throw new SecurityException("App must be the dialer role holder to"
7437 + " upload a call composer pic");
7438 }
7439
7440 Executors.newSingleThreadExecutor().execute(() -> {
7441 ByteArrayOutputStream output = new ByteArrayOutputStream(
7442 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7443 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7444 boolean readUntilEnd = false;
7445 int totalBytesRead = 0;
7446 byte[] buffer = new byte[16 * 1024];
7447 while (true) {
7448 int numRead;
7449 try {
7450 numRead = input.read(buffer);
7451 } catch (IOException e) {
7452 try {
7453 fd.checkError();
7454 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7455 null);
7456 } catch (IOException e1) {
7457 // This means that the other side closed explicitly with an error. If this
7458 // happens, log and ignore.
7459 loge("Remote end of call composer picture pipe closed: " + e1);
7460 }
7461 break;
7462 }
7463 if (numRead == -1) {
7464 readUntilEnd = true;
7465 break;
7466 }
7467 totalBytesRead += numRead;
7468 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7469 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7470 try {
7471 input.close();
7472 } catch (IOException e) {
7473 // ignore
7474 }
7475 break;
7476 }
7477 output.write(buffer, 0, numRead);
7478 }
7479 // Generally, the remote end will close the file descriptors. The only case where we
7480 // close is above, where the picture size is too big.
7481
7482 try {
7483 fd.checkError();
7484 } catch (IOException e) {
7485 loge("Remote end for call composer closed with an error: " + e);
7486 return;
7487 }
7488
Hall Liuaa4211e2021-01-20 15:43:39 -08007489 if (!readUntilEnd) {
7490 loge("Did not finish reading entire image; aborting");
7491 return;
7492 }
Hall Liu82694d52020-12-11 18:22:04 -08007493
Hall Liuaa4211e2021-01-20 15:43:39 -08007494 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7495 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7496 new CallComposerPictureTransfer.Factory() {},
7497 imageData,
7498 (result) -> {
7499 if (result.first != null) {
7500 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7501 Bundle outputResult = new Bundle();
7502 outputResult.putParcelable(
7503 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7504 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7505 outputResult);
7506 } else {
7507 callback.send(result.second, null);
7508 }
7509 }
7510 );
Hall Liu82694d52020-12-11 18:22:04 -08007511 });
7512 }
7513
7514 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007515 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007516 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518
7519 final long identity = Binder.clearCallingIdentity();
7520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007521 ImsManager.getInstance(defaultPhone.getContext(),
7522 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007526 }
7527
7528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007529 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007530 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7532 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007533 return false;
7534 }
Svet Ganovb320e182015-04-16 12:30:10 -07007535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 // Check the user preference and the system-level IMS setting. Even if the user has
7539 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7540 // In the long run, we may instead need to check if there exists a connection service
7541 // which can support video calling.
7542 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 return imsManager.isVtEnabledByPlatform()
7545 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7546 && imsManager.isVtEnabledByUser();
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007550 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007551
Andrew Leea1239f22015-03-02 17:44:07 -08007552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007553 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7554 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007556 mApp, subId, callingPackage, callingFeatureId,
7557 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 return false;
7559 }
7560
7561 final long identity = Binder.clearCallingIdentity();
7562 try {
7563 CarrierConfigManager configManager =
7564 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007565 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Andrew Leea1239f22015-03-02 17:44:07 -08007570 }
7571
7572 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007573 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576 return false;
7577 }
7578
7579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 CarrierConfigManager configManager =
7582 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007583 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
7587 }
Andrew Leea1239f22015-03-02 17:44:07 -08007588 }
7589
Andrew Lee9431b832015-03-09 18:46:45 -07007590 @Override
7591 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007592 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007593 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007594 }
7595
7596 @Override
7597 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598 final long identity = Binder.clearCallingIdentity();
7599 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007600 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
Andrew Lee9431b832015-03-09 18:46:45 -07007604 }
7605
Hall Liuf6668912018-10-31 17:05:23 -07007606 /**
7607 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7608 * support for the feature and device firmware support.
7609 *
7610 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7611 */
7612 @Override
7613 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007615 final Phone phone = getPhone(subscriptionId);
7616 if (phone == null) {
7617 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7618 return false;
7619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007621 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7623 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 return isCarrierSupported && isDeviceSupported;
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
Hall Liu98187582018-01-22 19:15:32 -08007629 }
7630
Hall Liuf6668912018-10-31 17:05:23 -07007631 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007632 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7633 * RTT setting, will return true if the device and carrier both support RTT.
7634 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007635 */
7636 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 final long identity = Binder.clearCallingIdentity();
7638 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007639 boolean isRttSupported = isRttSupported(subscriptionId);
7640 boolean isUserRttSettingOn = Settings.Secure.getInt(
7641 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7642 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7643 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7644 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007648 }
7649
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007650 @Deprecated
7651 @Override
7652 public String getDeviceId(String callingPackage) {
7653 return getDeviceIdWithFeature(callingPackage, null);
7654 }
7655
Sanket Padawe7310cc72015-01-14 09:53:20 -08007656 /**
7657 * Returns the unique device ID of phone, for example, the IMEI for
7658 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7659 *
7660 * <p>Requires Permission:
7661 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7662 */
7663 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007664 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007665 try {
7666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7667 } catch (SecurityException se) {
7668 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7669 throw new SecurityException("Package " + callingPackage + " does not belong to "
7670 + Binder.getCallingUid());
7671 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007672 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007673 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007674 return null;
7675 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007676 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007677 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007678 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007679 return null;
7680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681
7682 final long identity = Binder.clearCallingIdentity();
7683 try {
7684 return phone.getDeviceId();
7685 } finally {
7686 Binder.restoreCallingIdentity(identity);
7687 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007688 }
7689
Ping Sunc67b7c22016-03-02 19:16:45 +08007690 /**
7691 * {@hide}
7692 * Returns the IMS Registration Status on a particular subid
7693 *
7694 * @param subId
7695 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007696 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007697 Phone phone = getPhone(subId);
7698 if (phone != null) {
7699 return phone.isImsRegistered();
7700 } else {
7701 return false;
7702 }
7703 }
7704
Santos Cordon7a1885b2015-02-03 11:15:19 -08007705 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007706 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007707 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007709 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007710 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7711 }
7712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
7718 }
7719
7720 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007721 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007722 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007723 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007724 mApp,
7725 subscriptionId,
7726 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 Phone phone = getPhone(subscriptionId);
7730 if (phone == null) {
7731 return null;
7732 }
7733 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
7736 }
7737 }
7738
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007739 /**
7740 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007741 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007742 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743 final long identity = Binder.clearCallingIdentity();
7744 try {
7745 Phone phone = getPhone(subId);
7746 if (phone != null) {
7747 return phone.isWifiCallingEnabled();
7748 } else {
7749 return false;
7750 }
7751 } finally {
7752 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007753 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007754 }
7755
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007756 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007757 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007758 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007759 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 Phone phone = getPhone(subId);
7763 if (phone != null) {
7764 return phone.isVideoEnabled();
7765 } else {
7766 return false;
7767 }
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007770 }
7771 }
7772
7773 /**
7774 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7775 * defined in {@link ImsRegistrationImplBase}.
7776 */
7777 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 final long identity = Binder.clearCallingIdentity();
7779 try {
7780 Phone phone = getPhone(subId);
7781 if (phone != null) {
7782 return phone.getImsRegistrationTech();
7783 } else {
7784 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7785 }
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007788 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007789 }
7790
Stuart Scott8eef64f2015-04-08 15:13:54 -07007791 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007792 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007793 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007794 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7795 return;
7796 }
Kai Shif70f46f2021-03-03 13:59:46 -08007797 Phone defaultPhone = getDefaultPhone();
7798 if (defaultPhone != null) {
7799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7800 mApp, getDefaultPhone().getSubId(), "factoryReset");
7801 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007802 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007803
Svet Ganovcc087f82015-05-12 20:35:54 -07007804 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007805 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7806 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007807 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007808 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007809 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007810 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007811 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007812 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007813 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007814 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007815 // There has been issues when Sms raw table somehow stores orphan
7816 // fragments. They lead to garbled message when new fragments come
7817 // in and combined with those stale ones. In case this happens again,
7818 // user can reset all network settings which will clean up this table.
7819 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007820 // Clean up IMS settings as well here.
7821 int slotId = getSlotIndex(subId);
7822 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7823 ImsManager.getInstance(mApp, slotId).factoryReset();
7824 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007825
Kai Shif70f46f2021-03-03 13:59:46 -08007826 if (defaultPhone == null) {
7827 return;
7828 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007829 // Erase modem config if erase modem on network setting is enabled.
7830 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7831 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7832 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007833 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007834 }
Kai Shif70f46f2021-03-03 13:59:46 -08007835
7836 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007837 } finally {
7838 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007839 }
7840 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007841
SongFerngWangfd89b102021-05-27 22:44:54 +08007842 @VisibleForTesting
7843 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7844 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7845 return;
7846 }
7847 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7848 RILConstants.PREFERRED_NETWORK_MODE);
7849 SubscriptionManager.setSubscriptionProperty(subId,
7850 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7851 "user=" + defaultNetworkType);
7852 phone.loadAllowedNetworksFromSubscriptionDatabase();
7853 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7854 defaultNetworkType, null);
7855 }
7856
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007857 private void cleanUpSmsRawTable(Context context) {
7858 ContentResolver resolver = context.getContentResolver();
7859 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7860 resolver.delete(uri, null, null);
7861 }
7862
Narayan Kamath1c496c22015-04-16 14:40:19 +01007863 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007864 public String getSimLocaleForSubscriber(int subId) {
7865 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7866 final Phone phone = getPhone(subId);
7867 if (phone == null) {
7868 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007869 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 final long identity = Binder.clearCallingIdentity();
7872 try {
Jack Yu285100e2022-12-02 22:48:35 -08007873 SubscriptionInfo info;
7874 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7875 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7876 phone.getContext().getOpPackageName(),
7877 phone.getContext().getAttributionTag());
7878 if (info == null) {
7879 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7880 return null;
7881 }
7882 } else {
7883 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7884 phone.getContext().getOpPackageName(),
7885 phone.getContext().getAttributionTag());
7886 if (info == null) {
7887 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7888 return null;
7889 }
chen xu6291c472019-02-04 12:55:53 -08007890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 // Try and fetch the locale from the carrier properties or from the SIM language
7892 // preferences (EF-PL and EF-LI)...
7893 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007895 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7896 if (localeFromDefaultSim != null) {
7897 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7898 if (DBG) log("Using locale from subId: " + subId + " locale: "
7899 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007900 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007901 } else {
7902 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 }
7904 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906 // The SIM language preferences only store a language (e.g. fr = French), not an
7907 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7908 // the SIM and carrier preferences does not include a country we add the country
7909 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007910 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007912 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007913 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 }
7915
7916 if (DBG) log("No locale found - returning null");
7917 return null;
7918 } finally {
7919 Binder.restoreCallingIdentity(identity);
7920 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007921 }
7922
tom hsu0b59d292022-09-29 23:49:21 +08007923 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007924 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007925 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007926 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007927 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007928 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7929 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007930 Locale.forLanguageTag(localeTag).getCountry())) {
7931 return localeTag;
7932 }
7933 }
7934 return inputLocale.toLanguageTag();
7935 }
7936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 /**
7938 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7939 */
7940 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007941 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7942 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7943 mApp.getOpPackageName(), mApp.getAttributionTag());
7944 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007945 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007946 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007947 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007948
Gary Jian3aa9a762022-01-24 16:41:19 +08007949 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7950 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007951
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007952 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007953 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7954 * representing the state of the modem.
7955 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007956 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7957 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007958 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007959 */
7960 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007961 public void requestModemActivityInfo(ResultReceiver result) {
7962 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007963 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964
7965 final long identity = Binder.clearCallingIdentity();
7966 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007967 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 } finally {
7969 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007970 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007971 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007972
Siddharth Rayb8114062018-06-17 15:02:38 -07007973 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7974 // less than total activity duration.
7975 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7976 if (info == null) {
7977 return false;
7978 }
7979 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007980 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7981 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7982
Siddharth Rayb8114062018-06-17 15:02:38 -07007983 return (info.isValid()
7984 && (info.getSleepTimeMillis() <= activityDurationMs)
7985 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007986 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007987 && (totalTxTimeMs <= activityDurationMs));
7988 }
7989
Gary Jian3aa9a762022-01-24 16:41:19 +08007990 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7991 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7992 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7993 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7994
7995 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7996 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7997 }
7998
7999 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8000 mLastModemActivityInfo.setReceiveTimeMillis(
8001 rat,
8002 freq,
8003 info.getReceiveTimeMillis(rat, freq)
8004 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8005 }
8006
8007 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8008 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8009 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8010 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8011
8012 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8013 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8014 }
8015 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8016 mLastModemActivityInfo.setReceiveTimeMillis(
8017 rat,
8018 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8019 }
8020
8021 /**
8022 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8023 * @param info recent ModemActivityInfo
8024 */
8025 private void mergeModemActivityInfo(ModemActivityInfo info) {
8026 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008027 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008028 boolean matched;
8029 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8030 matched = false;
8031 int rat = info.getSpecificInfoRat(i);
8032 int freq = info.getSpecificInfoFrequencyRange(i);
8033 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8034 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8035 //if it already exists
8036 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8037 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8038 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8039 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8040 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8041 updateLastModemActivityInfo(info, rat, freq);
8042 matched = true;
8043 }
8044 } else {
8045 updateLastModemActivityInfo(info, rat);
8046 matched = true;
8047 }
8048 }
8049 }
8050
8051 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008052 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008053 new ActivityStatsTechSpecificInfo(
8054 rat,
8055 freq,
8056 info.getTransmitTimeMillis(rat, freq),
8057 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008058 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008059 }
8060 }
8061 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8062 mLastModemActivitySpecificInfo =
8063 new ActivityStatsTechSpecificInfo[merged.size()];
8064 merged.toArray(mLastModemActivitySpecificInfo);
8065
8066 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8067 mLastModemActivityInfo.setSleepTimeMillis(
8068 info.getSleepTimeMillis()
8069 + mLastModemActivityInfo.getSleepTimeMillis());
8070 mLastModemActivityInfo.setIdleTimeMillis(
8071 info.getIdleTimeMillis()
8072 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008073
8074 mLastModemActivityInfo =
8075 new ModemActivityInfo(
8076 mLastModemActivityInfo.getTimestampMillis(),
8077 mLastModemActivityInfo.getSleepTimeMillis(),
8078 mLastModemActivityInfo.getIdleTimeMillis(),
8079 mLastModemActivitySpecificInfo);
8080 }
8081
8082 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8083 ActivityStatsTechSpecificInfo[] info) {
8084 int infoSize = info.length;
8085 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8086 for (int i = 0; i < infoSize; i++) {
8087 ret[i] = new ActivityStatsTechSpecificInfo(
8088 info[i].getRat(), info[i].getFrequencyRange(),
8089 info[i].getTransmitTimeMillis(),
8090 (int) info[i].getReceiveTimeMillis());
8091 }
8092 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008093 }
8094
Jack Yu85bd38a2015-11-09 11:34:32 -08008095 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008096 * Returns the service state information on specified subscription.
8097 */
8098 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008099 public ServiceState getServiceStateForSubscriber(int subId,
8100 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8101 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008103 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008104 return null;
8105 }
8106
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008107 boolean hasFinePermission = false;
8108 boolean hasCoarsePermission = false;
8109 if (!renounceFineLocationAccess) {
8110 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8111 LocationAccessPolicy.checkLocationPermission(mApp,
8112 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8113 .setCallingPackage(callingPackage)
8114 .setCallingFeatureId(callingFeatureId)
8115 .setCallingPid(Binder.getCallingPid())
8116 .setCallingUid(Binder.getCallingUid())
8117 .setMethod("getServiceStateForSubscriber")
8118 .setLogAsInfo(true)
8119 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8120 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8121 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8122 .build());
8123 hasFinePermission =
8124 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8125 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008126
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008127 if (!renounceCoarseLocationAccess) {
8128 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8129 LocationAccessPolicy.checkLocationPermission(mApp,
8130 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8131 .setCallingPackage(callingPackage)
8132 .setCallingFeatureId(callingFeatureId)
8133 .setCallingPid(Binder.getCallingPid())
8134 .setCallingUid(Binder.getCallingUid())
8135 .setMethod("getServiceStateForSubscriber")
8136 .setLogAsInfo(true)
8137 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8138 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8139 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8140 .build());
8141 hasCoarsePermission =
8142 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8143 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008144
Jack Yu479f40e2020-10-27 21:29:25 -07008145 final Phone phone = getPhone(subId);
8146 if (phone == null) {
8147 return null;
8148 }
8149
Jordan Liu0f2bc442020-11-18 16:47:37 -08008150 final long identity = Binder.clearCallingIdentity();
8151
Jack Yu479f40e2020-10-27 21:29:25 -07008152 boolean isCallingPackageDataService = phone.getDataServicePackages()
8153 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008154 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008155 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008156 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8157 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8158 .getSubscriptionInfoInternal(subId);
8159 if (subInfo == null || !subInfo.isActive()) {
8160 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8161 + "subId=" + subId);
8162 return null;
8163 }
8164 } else {
8165 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8166 callingFeatureId)) {
8167 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8168 + "subId=" + subId);
8169 return null;
8170 }
Jordan Liuc437b192020-08-17 10:59:12 -07008171 }
8172
Hall Liuf19c44f2018-11-27 14:38:17 -08008173 ServiceState ss = phone.getServiceState();
8174
8175 // Scrub out the location info in ServiceState depending on what level of access
8176 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008177 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008178 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8179 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 } finally {
8181 Binder.restoreCallingIdentity(identity);
8182 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008183 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008184
8185 /**
8186 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8187 *
8188 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8189 * voicemail ringtone.
8190 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8191 * PhoneAccount.
8192 */
8193 @Override
8194 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195 final long identity = Binder.clearCallingIdentity();
8196 try {
8197 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8198 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008199 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8203 } finally {
8204 Binder.restoreCallingIdentity(identity);
8205 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008206 }
8207
8208 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008209 * Sets the per-account voicemail ringtone.
8210 *
8211 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8212 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8213 *
8214 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8215 * voicemail ringtone.
8216 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8217 * PhoneAccount.
8218 */
8219 @Override
8220 public void setVoicemailRingtoneUri(String callingPackage,
8221 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008222 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008223 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008224 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8225 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8227 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8228 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230
8231 final long identity = Binder.clearCallingIdentity();
8232 try {
8233 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8234 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008235 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 }
8237 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008240 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008241 }
8242
8243 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008244 * Returns whether vibration is set for voicemail notification in Phone settings.
8245 *
8246 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8247 * voicemail vibration setting.
8248 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8249 */
8250 @Override
8251 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 final long identity = Binder.clearCallingIdentity();
8253 try {
8254 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8255 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008256 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8260 } finally {
8261 Binder.restoreCallingIdentity(identity);
8262 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008263 }
8264
Youhan Wange64578a2016-05-02 15:32:42 -07008265 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008266 * Sets the per-account voicemail vibration.
8267 *
8268 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8269 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8270 *
8271 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8272 * voicemail vibration setting.
8273 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8274 * specific PhoneAccount.
8275 */
8276 @Override
8277 public void setVoicemailVibrationEnabled(String callingPackage,
8278 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008279 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008280 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008281 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8282 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8284 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8285 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008286 }
8287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 final long identity = Binder.clearCallingIdentity();
8289 try {
8290 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8291 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008292 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 }
8294 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8295 } finally {
8296 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008297 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008298 }
8299
8300 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008301 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8302 *
8303 * @throws SecurityException if the caller does not have the required permission
8304 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008305 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008306 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008307 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008308 }
8309
8310 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008311 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8312 * permission.
8313 *
8314 * @throws SecurityException if the caller does not have the required permission
8315 */
8316 private void enforceSendSmsPermission() {
8317 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8318 }
8319
8320 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008321 * Make sure either called from same process as self (phone) or IPC caller has interact across
8322 * users permission.
8323 *
8324 * @throws SecurityException if the caller does not have the required permission
8325 */
8326 private void enforceInteractAcrossUsersPermission(String message) {
8327 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8328 }
8329
8330 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008331 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008332 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008333 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008334 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008335 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008339 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 if (componentName == null) {
8341 throw new SecurityException(
8342 "Caller not current active visual voicemail package[null]");
8343 }
8344 String vvmPackage = componentName.getPackageName();
8345 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008346 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 }
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008350 }
8351 }
8352
8353 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008354 * Return the application ID for the app type.
8355 *
8356 * @param subId the subscription ID that this request applies to.
8357 * @param appType the uicc app type.
8358 * @return Application ID for specificied app type, or null if no uicc.
8359 */
8360 @Override
8361 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008362 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008363 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364
8365 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008366 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 if (phone == null) {
8368 return null;
8369 }
8370 String aid = null;
8371 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008372 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373 .getApplicationByType(appType).getAid();
8374 } catch (Exception e) {
8375 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8376 }
8377 return aid;
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008380 }
Youhan Wange64578a2016-05-02 15:32:42 -07008381 }
8382
Youhan Wang4001d252016-05-11 10:29:41 -07008383 /**
8384 * Return the Electronic Serial Number.
8385 *
8386 * @param subId the subscription ID that this request applies to.
8387 * @return ESN or null if error.
8388 */
8389 @Override
8390 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008391 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008392 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393
8394 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008395 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 if (phone == null) {
8397 return null;
8398 }
8399 String esn = null;
8400 try {
8401 esn = phone.getEsn();
8402 } catch (Exception e) {
8403 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8404 }
8405 return esn;
8406 } finally {
8407 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008408 }
Youhan Wang4001d252016-05-11 10:29:41 -07008409 }
8410
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008411 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008412 * Return the Preferred Roaming List Version.
8413 *
8414 * @param subId the subscription ID that this request applies to.
8415 * @return PRLVersion or null if error.
8416 */
8417 @Override
8418 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008419 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008420 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421
8422 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008423 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424 if (phone == null) {
8425 return null;
8426 }
8427 String cdmaPrlVersion = null;
8428 try {
8429 cdmaPrlVersion = phone.getCdmaPrlVersion();
8430 } catch (Exception e) {
8431 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8432 }
8433 return cdmaPrlVersion;
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008436 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008437 }
8438
8439 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008440 * Get snapshot of Telephony histograms
8441 * @return List of Telephony histograms
8442 * @hide
8443 */
8444 @Override
8445 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8447 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448
8449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 return RIL.getTelephonyRILTimingHistograms();
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008455 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008456
8457 /**
8458 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008459 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8460 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008461 * Require system privileges. In the future we may add this to carrier APIs.
8462 *
Michele Berionne482f8202018-11-27 18:57:59 -08008463 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008464 */
8465 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008466 @TelephonyManager.SetCarrierRestrictionResult
8467 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008468 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008469 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008470
Michele Berionne482f8202018-11-27 18:57:59 -08008471 if (carrierRestrictionRules == null) {
8472 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008473 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008475 final long identity = Binder.clearCallingIdentity();
8476 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008477 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008478 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479 } finally {
8480 Binder.restoreCallingIdentity(identity);
8481 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008482 }
8483
8484 /**
8485 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008486 * Get the allowed carrier list and the excluded carrier list, including the priority between
8487 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008488 * Require system privileges. In the future we may add this to carrier APIs.
8489 *
Michele Berionne482f8202018-11-27 18:57:59 -08008490 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008491 */
8492 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008493 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008494 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008495 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008496
8497 final long identity = Binder.clearCallingIdentity();
8498 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008499 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8500 if (response instanceof CarrierRestrictionRules) {
8501 return (CarrierRestrictionRules) response;
8502 }
8503 // Response is an Exception of some kind,
8504 // which is signalled to the user as a NULL retval
8505 return null;
8506 } catch (Exception e) {
8507 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8508 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509 } finally {
8510 Binder.restoreCallingIdentity(identity);
8511 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008512 }
8513
fionaxu59545b42016-05-25 15:53:37 -07008514 /**
fionaxu59545b42016-05-25 15:53:37 -07008515 * Action set from carrier signalling broadcast receivers to enable/disable radio
8516 * @param subId the subscription ID that this action applies to.
8517 * @param enabled control enable or disable radio.
8518 * {@hide}
8519 */
8520 @Override
8521 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8522 enforceModifyPermission();
8523 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524
8525 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008526 if (phone == null) {
8527 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8528 return;
8529 }
8530 try {
8531 phone.carrierActionSetRadioEnabled(enabled);
8532 } catch (Exception e) {
8533 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 } finally {
8535 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008536 }
8537 }
8538
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008539 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008540 * Enable or disable Voice over NR (VoNR)
8541 * @param subId the subscription ID that this action applies to.
8542 * @param enabled enable or disable VoNR.
8543 * @return operation result.
8544 */
8545 @Override
8546 public int setVoNrEnabled(int subId, boolean enabled) {
8547 enforceModifyPermission();
8548 final Phone phone = getPhone(subId);
8549
8550 final long identity = Binder.clearCallingIdentity();
8551 if (phone == null) {
8552 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8553 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8554 }
8555
8556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8557 try {
8558 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8559 workSource);
8560 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008561
8562 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8563 if (DBG) {
8564 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8565 }
8566 SubscriptionManager.setSubscriptionProperty(
8567 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8568 (enabled ? "1" : "0"));
8569 }
8570
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008571 return result;
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
8574 }
8575 }
8576
8577 /**
8578 * Is voice over NR enabled
8579 * @return true if VoNR is enabled else false
8580 */
8581 @Override
8582 public boolean isVoNrEnabled(int subId) {
8583 enforceReadPrivilegedPermission("isVoNrEnabled");
8584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8585 final long identity = Binder.clearCallingIdentity();
8586 try {
8587 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8588 null, subId, workSource);
8589 if (DBG) log("isVoNrEnabled: " + isEnabled);
8590 return isEnabled;
8591 } finally {
8592 Binder.restoreCallingIdentity(identity);
8593 }
8594 }
8595
8596 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008597 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8598 * network status based on which carrier apps could apply actions accordingly,
8599 * enable/disable default url handler for example.
8600 *
8601 * @param subId the subscription ID that this action applies to.
8602 * @param report control start/stop reporting the default network status.
8603 * {@hide}
8604 */
8605 @Override
8606 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8607 enforceModifyPermission();
8608 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609
8610 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008611 if (phone == null) {
8612 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8613 return;
8614 }
8615 try {
8616 phone.carrierActionReportDefaultNetworkStatus(report);
8617 } catch (Exception e) {
8618 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 } finally {
8620 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008621 }
8622 }
8623
8624 /**
fionaxud9622282017-07-17 17:51:30 -07008625 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8626 * @param subId the subscription ID that this action applies to.
8627 * {@hide}
8628 */
8629 @Override
8630 public void carrierActionResetAll(int subId) {
8631 enforceModifyPermission();
8632 final Phone phone = getPhone(subId);
8633 if (phone == null) {
8634 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8635 return;
8636 }
8637 try {
8638 phone.carrierActionResetAll();
8639 } catch (Exception e) {
8640 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8641 }
8642 }
8643
8644 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008645 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8646 * bug report is being generated.
8647 */
8648 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008649 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008650 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8651 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008652 writer.println("Permission Denial: can't dump Phone from pid="
8653 + Binder.getCallingPid()
8654 + ", uid=" + Binder.getCallingUid()
8655 + "without permission "
8656 + android.Manifest.permission.DUMP);
8657 return;
8658 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008659 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008660 }
Jack Yueb89b242016-06-22 13:27:47 -07008661
Brad Ebingerdac2f002018-04-03 15:17:52 -07008662 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008663 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8664 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8665 @NonNull String[] args) {
8666 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8667 this, in.getFileDescriptor(), out.getFileDescriptor(),
8668 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008669 }
8670
Jack Yueb89b242016-06-22 13:27:47 -07008671 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008672 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008673 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008674 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008675 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008676 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008677 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008678 */
8679 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008680 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008681 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008682 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8683 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8684 try {
8685 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008686 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008687 } catch (SecurityException se) {
8688 enforceModifyPermission();
8689 }
8690 } else {
8691 enforceModifyPermission();
8692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008693
8694 final long identity = Binder.clearCallingIdentity();
8695 try {
8696 Phone phone = getPhone(subId);
8697 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008698 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8699 phone.carrierActionSetMeteredApnsEnabled(enabled);
8700 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008701 phone.getDataSettingsManager().setDataEnabled(
8702 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008704 }
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008707 }
8708 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008709
8710 /**
8711 * Get Client request stats
8712 * @return List of Client Request Stats
8713 * @hide
8714 */
8715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008716 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8717 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008719 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008720 return null;
8721 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008722 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008724 final long identity = Binder.clearCallingIdentity();
8725 try {
8726 if (phone != null) {
8727 return phone.getClientRequestStats();
8728 }
8729
8730 return null;
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008734 }
8735
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008736 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008737 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008738 if (uid == Process.ROOT_UID && packageName == null) {
8739 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8740 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8741 // exception. ROOT_UID seems not to have a valid package name returned by
8742 // PackageManager, so just fake it here to avoid issues when running telephony shell
8743 // commands that plumb through the RIL as root, like so:
8744 // $ adb root
8745 // $ adb shell cmd phone ...
8746 packageName = "root";
8747 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008748 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008749 }
Jack Yueb4124c2017-02-16 15:32:43 -08008750
8751 /**
Grace Chen70990072017-03-24 17:21:30 -07008752 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008753 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008754 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008755 * @param state State of SIM (power down, power up, pass through)
8756 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8757 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8758 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008759 *
8760 **/
8761 @Override
Grace Chen70990072017-03-24 17:21:30 -07008762 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008763 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008764 Phone phone = PhoneFactory.getPhone(slotIndex);
8765
vagdeviaf9a5b92018-08-15 16:01:53 -07008766 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008771 phone.setSimPowerState(state, null, workSource);
8772 }
8773 } finally {
8774 Binder.restoreCallingIdentity(identity);
8775 }
8776 }
8777
8778 /**
8779 * Set SIM card power state.
8780 *
8781 * @param slotIndex SIM slot id.
8782 * @param state State of SIM (power down, power up, pass through)
8783 * @param callback callback to trigger after success or failure
8784 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8785 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8786 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8787 *
8788 **/
8789 @Override
8790 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8791 IIntegerConsumer callback) {
8792 enforceModifyPermission();
8793 Phone phone = PhoneFactory.getPhone(slotIndex);
8794
8795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8796
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 if (phone != null) {
8800 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8801 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008802 }
8803 } finally {
8804 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008805 }
8806 }
Shuo Qiandd210312017-04-12 22:11:33 +00008807
Tyler Gunn65d45c22017-06-05 11:22:26 -07008808 private boolean isUssdApiAllowed(int subId) {
8809 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008810 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008811 if (configManager == null) {
8812 return false;
8813 }
8814 PersistableBundle pb = configManager.getConfigForSubId(subId);
8815 if (pb == null) {
8816 return false;
8817 }
8818 return pb.getBoolean(
8819 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8820 }
8821
Shuo Qiandd210312017-04-12 22:11:33 +00008822 /**
8823 * Check if phone is in emergency callback mode
8824 * @return true if phone is in emergency callback mode
8825 * @param subId sub id
8826 */
goneil9c5f4872017-12-05 14:07:56 -08008827 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008828 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008829 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008831
8832 final long identity = Binder.clearCallingIdentity();
8833 try {
8834 if (phone != null) {
8835 return phone.isInEcm();
8836 } else {
8837 return false;
8838 }
8839 } finally {
8840 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008841 }
8842 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008843
8844 /**
8845 * Get the current signal strength information for the given subscription.
8846 * Because this information is not updated when the device is in a low power state
8847 * it should not be relied-upon to be current.
8848 * @param subId Subscription index
8849 * @return the most recent cached signal strength info from the modem
8850 */
8851 @Override
8852 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 final long identity = Binder.clearCallingIdentity();
8854 try {
8855 Phone p = getPhone(subId);
8856 if (p == null) {
8857 return null;
8858 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008860 return p.getSignalStrength();
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008864 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008865
Pengquan Meng77b7f132018-08-22 14:49:57 -07008866 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008867 * Get the current modem radio state for the given slot.
8868 * @param slotIndex slot index.
8869 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008870 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008871 * @return the current radio power state from the modem
8872 */
8873 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008874 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008875 Phone phone = PhoneFactory.getPhone(slotIndex);
8876 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8878 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008879 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8880 }
8881
8882 final long identity = Binder.clearCallingIdentity();
8883 try {
8884 return phone.getRadioPowerState();
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
8887 }
8888 }
8889 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8890 }
8891
8892 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008893 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8894 *
8895 * <p>Requires one of the following permissions:
8896 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008897 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008898 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8899 * privileges.
8900 *
8901 * @param subId subscription id
8902 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8903 * {@code false}.
8904 */
8905 @Override
8906 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008907 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008908 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008909 try {
8910 mApp.enforceCallingOrSelfPermission(
8911 android.Manifest.permission.ACCESS_NETWORK_STATE,
8912 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008913 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008914 mApp.enforceCallingOrSelfPermission(
8915 permission.READ_BASIC_PHONE_STATE, functionName);
8916 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008917 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008918 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008919 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008920 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008921
Pengquan Menga1bb6272018-09-06 09:59:22 -07008922 boolean isEnabled = false;
8923 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008924 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008925 Phone phone = getPhone(subId);
8926 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008927 } finally {
8928 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008929 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008930 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008931 }
8932
8933
8934 /**
8935 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8936 *
8937 * <p> Requires permission:
8938 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8939 * privileges.
8940 *
8941 * @param subId subscription id
8942 * @param isEnabled {@code true} means enable, {@code false} means disable.
8943 */
8944 @Override
8945 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8947 mApp, subId, "setDataRoamingEnabled");
8948
Pengquan Menga1bb6272018-09-06 09:59:22 -07008949 final long identity = Binder.clearCallingIdentity();
8950 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008951 Phone phone = getPhone(subId);
8952 if (phone != null) {
8953 phone.setDataRoamingEnabled(isEnabled);
8954 }
8955 } finally {
8956 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008957 }
8958 }
8959
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008960 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008961 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008962 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008963 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008964 mApp, subId, "isManualNetworkSelectionAllowed");
8965
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008966 boolean isAllowed = true;
8967 final long identity = Binder.clearCallingIdentity();
8968 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008969 Phone phone = getPhone(subId);
8970 if (phone != null) {
8971 isAllowed = phone.isCspPlmnEnabled();
8972 }
8973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
8976 return isAllowed;
8977 }
8978
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008979 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8980 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008981 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008982 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008983 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008984 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8985 if (phone == null) {
8986 return false;
8987 }
8988 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8989 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8990 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008991 }
8992
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008993 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008994 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008995 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008996 mApp.getSystemService(AppOpsManager.class)
8997 .checkPackage(Binder.getCallingUid(), callingPackage);
8998
Jordan Liu1e142fc2019-04-22 15:10:43 -07008999 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009000 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009001 try {
9002 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009003 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009004 } catch (SecurityException e) {
9005 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9006 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009007 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009008 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009009 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009010 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009011 }
sandeepjsb6c87872021-09-27 15:34:44 +00009012 // checking compatibility, if calling app's target SDK is T and beyond.
9013 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9014 Binder.getCallingUid())) {
9015 isIccIdAccessRestricted = true;
9016 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009017 final long identity = Binder.clearCallingIdentity();
9018 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009019 UiccController uiccController = UiccController.getInstance();
9020 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009021 if (hasReadPermission) {
9022 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009023 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009024
9025 // Remove private info if the caller doesn't have access
9026 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9027 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009028 //setting the value after compatibility check
9029 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009030 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9031 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009032 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009033 if (card == null) {
9034 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009035 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009036 continue;
9037 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009038 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9039 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009040 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009041 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009042 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009043 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9044 for (UiccPortInfo portInfo : portInfos) {
9045 UiccPort port = uiccController.getUiccPortForSlot(
9046 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9047 if (port == null) {
9048 // assume no access if port is null
9049 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9050 continue;
9051 }
9052 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9053 uiccPortInfos.add(portInfo);
9054 } else {
9055 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9056 }
9057 }
9058 filteredInfos.add(new UiccCardInfo(
9059 cardInfo.isEuicc(),
9060 cardInfo.getCardId(),
9061 null,
9062 cardInfo.getPhysicalSlotIndex(),
9063 cardInfo.isRemovable(),
9064 cardInfo.isMultipleEnabledProfilesSupported(),
9065 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009066 }
9067 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009068 } finally {
9069 Binder.restoreCallingIdentity(identity);
9070 }
9071 }
9072
sandeepjsb6c87872021-09-27 15:34:44 +00009073 /**
9074 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9075 * generally private and require carrier privileges to view.
9076 *
9077 * @hide
9078 */
9079 @NonNull
9080 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9081 List<UiccPortInfo> portinfo = new ArrayList<>();
9082 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9083 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9084 }
9085 return new UiccCardInfo(
9086 cardInfo.isEuicc(),
9087 cardInfo.getCardId(),
9088 null,
9089 cardInfo.getPhysicalSlotIndex(),
9090 cardInfo.isRemovable(),
9091 cardInfo.isMultipleEnabledProfilesSupported(),
9092 portinfo
9093 );
9094 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009095
sandeepjsb6c87872021-09-27 15:34:44 +00009096 /**
9097 * @hide
9098 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9099 * These values are generally private and require carrier privileges to view.
9100 */
9101 @NonNull
9102 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9103 return new UiccPortInfo(
9104 UiccPortInfo.ICCID_REDACTED,
9105 portInfo.getPortIndex(),
9106 portInfo.getLogicalSlotIndex(),
9107 portInfo.isActive()
9108 );
9109 }
9110 @Override
9111 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009112 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009113 mApp.getSystemService(AppOpsManager.class)
9114 .checkPackage(Binder.getCallingUid(), callingPackage);
9115
sandeepjsb6c87872021-09-27 15:34:44 +00009116 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009117
Aman Guptaf3c90b32022-03-17 04:54:16 +00009118 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9119 // we are reading iccId which is PII data.
9120 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009121
9122 // checking compatibility, if calling app's target SDK is T and beyond.
9123 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9124 Binder.getCallingUid())) {
9125 isLogicalSlotAccessRestricted = true;
9126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009127 final long identity = Binder.clearCallingIdentity();
9128 try {
9129 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009130 if (slots == null || slots.length == 0) {
9131 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009132 return null;
9133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9135 for (int i = 0; i < slots.length; i++) {
9136 UiccSlot slot = slots[i];
9137 if (slot == null) {
9138 continue;
9139 }
9140
Jordan Liu7be7e652019-05-06 18:55:02 +00009141 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009142 UiccCard card = slot.getUiccCard();
9143 if (card != null) {
9144 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009145 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009146 cardId = slot.getEid();
9147 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009148 // If cardId is null, use iccId of default port as cardId.
9149 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009151 }
9152
Jordan Liu857451f2019-05-09 16:35:35 -07009153 if (cardId != null) {
9154 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9155 // if cardId is an EID, it's all digits so this is fine
9156 cardId = IccUtils.stripTrailingFs(cardId);
9157 }
9158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009159 int cardState = 0;
9160 switch (slot.getCardState()) {
9161 case CARDSTATE_ABSENT:
9162 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9163 break;
9164 case CARDSTATE_PRESENT:
9165 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9166 break;
9167 case CARDSTATE_ERROR:
9168 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9169 break;
9170 case CARDSTATE_RESTRICTED:
9171 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9172 break;
9173 default:
9174 break;
9175
9176 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009177 List<UiccPortInfo> portInfos = new ArrayList<>();
9178 int[] portIndexes = slot.getPortList();
9179 for (int portIdx : portIndexes) {
9180 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009181 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009182 portInfos.add(new UiccPortInfo(iccId, portIdx,
9183 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009186 slot.isEuicc(),
9187 cardId,
9188 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009189 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009190 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009191 //setting the value after compatibility check
9192 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009193 }
9194 return infos;
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009197 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009198 }
9199
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009200 /* Returns null if doesn't have read permission or carrier privilege access. */
9201 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9202 boolean hasReadPermission) {
9203 String iccId = slot.getIccId(portIndex);
9204 if (hasReadPermission) { // if has read permission
9205 return iccId;
9206 } else {
9207 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9208 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9209 // if no read permission, checking carrier privilege access
9210 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9211 return iccId;
9212 }
9213 }
9214 }
9215 // No read permission or carrier privilege access.
9216 return UiccPortInfo.ICCID_REDACTED;
9217 }
9218
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009219 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009220 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009221 public boolean switchSlots(int[] physicalSlots) {
9222 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009223
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009226 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9227 for (int i = 0; i < physicalSlots.length; i++) {
9228 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9229 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9230 physicalSlots[i], i));
9231 }
9232 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009233 } finally {
9234 Binder.restoreCallingIdentity(identity);
9235 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009236 }
Jack Yu4c988042018-02-27 15:30:01 -08009237
9238 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009239 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9240 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9241 enforceModifyPermission();
9242
9243 final long identity = Binder.clearCallingIdentity();
9244 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009245 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
9249 }
9250
9251 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009252 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009253 final long identity = Binder.clearCallingIdentity();
9254 try {
9255 return UiccController.getInstance().getCardIdForDefaultEuicc();
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
9259 }
9260
Pengquan Meng85728fb2018-03-12 16:31:21 -07009261 /**
goneil47ffb6e2018-04-06 15:40:58 -07009262 * A test API to reload the UICC profile.
9263 *
9264 * <p>Requires that the calling app has permission
9265 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9266 * @hide
9267 */
9268 @Override
9269 public void refreshUiccProfile(int subId) {
9270 enforceModifyPermission();
9271
9272 final long identity = Binder.clearCallingIdentity();
9273 try {
9274 Phone phone = getPhone(subId);
9275 if (phone == null) {
9276 return;
9277 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009278 UiccPort uiccPort = phone.getUiccPort();
9279 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009280 return;
9281 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009282 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009283 if (uiccProfile == null) {
9284 return;
9285 }
9286 uiccProfile.refresh();
9287 } finally {
9288 Binder.restoreCallingIdentity(identity);
9289 }
9290 }
9291
9292 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009293 * Returns false if the mobile data is disabled by default, otherwise return true.
9294 */
9295 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009296 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009297 }
9298
9299 /**
9300 * Returns true if the data roaming is enabled by default, i.e the system property
9301 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9302 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9303 */
9304 private boolean getDefaultDataRoamingEnabled(int subId) {
9305 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009306 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009307 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009308 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9309 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9310 return isDataRoamingEnabled;
9311 }
9312
9313 /**
9314 * Returns the default network type for the given {@code subId}, if the default network type is
9315 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9316 */
9317 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009318 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009319 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009320 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9321 return list.get(phoneId);
9322 }
9323 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009324 }
fionaxua13278b2018-03-21 00:08:13 -07009325
9326 @Override
9327 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009328 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009330
9331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 final Phone phone = getPhone(subId);
9334 if (phone == null) {
9335 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9336 return;
9337 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009338 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9339 if (cpt != null) {
9340 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9341 }
9342 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009343 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9344 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009345 if (carrierPrivilegeRules == null) {
9346 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9347 } else {
9348 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009350 } finally {
9351 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009352 }
fionaxua13278b2018-03-21 00:08:13 -07009353 }
9354
9355 @Override
9356 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009357 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009358
9359 final long identity = Binder.clearCallingIdentity();
9360 try {
9361 final Phone phone = getPhone(subId);
9362 if (phone == null) {
9363 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9364 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9365 }
9366 return phone.getCarrierIdListVersion();
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009369 }
fionaxua13278b2018-03-21 00:08:13 -07009370 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009371
9372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009373 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9374 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009376 mApp, subId, callingPackage, callingFeatureId,
9377 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009378 return -1;
9379 }
9380
9381 final long identity = Binder.clearCallingIdentity();
9382 try {
9383 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9384 } finally {
9385 Binder.restoreCallingIdentity(identity);
9386 }
9387 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009388
9389 @Override
9390 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009391 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009392 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009393 mApp, subId, "getCdmaRoamingMode");
9394
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
9397 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9398 } finally {
9399 Binder.restoreCallingIdentity(identity);
9400 }
9401 }
9402
9403 @Override
9404 public boolean setCdmaRoamingMode(int subId, int mode) {
9405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9406 mApp, subId, "setCdmaRoamingMode");
9407
9408 final long identity = Binder.clearCallingIdentity();
9409 try {
9410 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9411 } finally {
9412 Binder.restoreCallingIdentity(identity);
9413 }
9414 }
9415
9416 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009417 public int getCdmaSubscriptionMode(int subId) {
9418 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009419 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009420 mApp, subId, "getCdmaSubscriptionMode");
9421
9422 final long identity = Binder.clearCallingIdentity();
9423 try {
9424 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
9429
9430 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009431 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9433 mApp, subId, "setCdmaSubscriptionMode");
9434
9435 final long identity = Binder.clearCallingIdentity();
9436 try {
9437 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009442
sqianc5eccab2018-10-19 18:46:41 -07009443 @Override
sqian8c685422019-02-22 15:55:18 -08009444 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009445 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009447 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9448 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009449 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9450 }
9451 final long identity = Binder.clearCallingIdentity();
9452 try {
sqian854d44b2018-12-12 16:48:18 -08009453 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9454 for (Phone phone: PhoneFactory.getPhones()) {
9455 if (phone.getEmergencyNumberTracker() != null
9456 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9457 emergencyNumberListInternal.put(
9458 phone.getSubId(),
9459 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9460 }
sqian11b7a0e2018-12-05 18:48:28 -08009461 }
sqian854d44b2018-12-12 16:48:18 -08009462 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009463 } finally {
9464 Binder.restoreCallingIdentity(identity);
9465 }
sqianc5eccab2018-10-19 18:46:41 -07009466 }
9467
9468 @Override
sqian8c685422019-02-22 15:55:18 -08009469 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009470 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009471 if (!exactMatch) {
9472 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009473 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009474 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009475 }
9476 final long identity = Binder.clearCallingIdentity();
9477 try {
sqian854d44b2018-12-12 16:48:18 -08009478 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009479 //Note: we ignore passed in param exactMatch. We can remove it once
9480 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009481 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009482 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009483 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009484 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009485 }
sqian11b7a0e2018-12-05 18:48:28 -08009486 }
9487 return false;
9488 } finally {
9489 Binder.restoreCallingIdentity(identity);
9490 }
9491 }
9492
sqianf4ca7ed2019-01-15 18:32:07 -08009493 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009494 * Start emergency callback mode for GsmCdmaPhone for testing.
9495 */
9496 @Override
9497 public void startEmergencyCallbackMode() {
9498 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9499 "startEmergencyCallbackMode");
9500 enforceModifyPermission();
9501 final long identity = Binder.clearCallingIdentity();
9502 try {
9503 for (Phone phone : PhoneFactory.getPhones()) {
9504 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9505 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9506 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9507 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9508 gsmCdmaPhone.obtainMessage(
9509 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9510 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9511 }
9512 }
9513 } finally {
9514 Binder.restoreCallingIdentity(identity);
9515 }
9516 }
9517
9518 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009519 * Update emergency number list for test mode.
9520 */
9521 @Override
9522 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9523 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9524 "updateEmergencyNumberListTestMode");
9525
9526 final long identity = Binder.clearCallingIdentity();
9527 try {
9528 for (Phone phone: PhoneFactory.getPhones()) {
9529 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9530 if (tracker != null) {
9531 tracker.executeEmergencyNumberTestModeCommand(action, num);
9532 }
9533 }
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537 }
9538
9539 /**
9540 * Get the full emergency number list for test mode.
9541 */
9542 @Override
9543 public List<String> getEmergencyNumberListTestMode() {
9544 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9545 "getEmergencyNumberListTestMode");
9546
9547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 Set<String> emergencyNumbers = new HashSet<>();
9550 for (Phone phone: PhoneFactory.getPhones()) {
9551 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9552 if (tracker != null) {
9553 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9554 emergencyNumbers.add(num.getNumber());
9555 }
9556 }
9557 }
9558 return new ArrayList<>(emergencyNumbers);
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
chen xud6b45bd2018-10-30 22:27:10 -07009564 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009565 public int getEmergencyNumberDbVersion(int subId) {
9566 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9567
9568 final long identity = Binder.clearCallingIdentity();
9569 try {
9570 final Phone phone = getPhone(subId);
9571 if (phone == null) {
9572 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9573 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9574 }
9575 return phone.getEmergencyNumberDbVersion();
9576 } finally {
9577 Binder.restoreCallingIdentity(identity);
9578 }
9579 }
9580
9581 @Override
9582 public void notifyOtaEmergencyNumberDbInstalled() {
9583 enforceModifyPermission();
9584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 for (Phone phone: PhoneFactory.getPhones()) {
9588 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9589 if (tracker != null) {
9590 tracker.updateOtaEmergencyNumberDatabase();
9591 }
9592 }
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
9597
9598 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009599 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009600 enforceActiveEmergencySessionPermission();
9601
9602 final long identity = Binder.clearCallingIdentity();
9603 try {
9604 for (Phone phone: PhoneFactory.getPhones()) {
9605 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9606 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009607 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9608 }
9609 }
9610 } finally {
9611 Binder.restoreCallingIdentity(identity);
9612 }
9613 }
9614
9615 @Override
9616 public void resetOtaEmergencyNumberDbFilePath() {
9617 enforceActiveEmergencySessionPermission();
9618
9619 final long identity = Binder.clearCallingIdentity();
9620 try {
9621 for (Phone phone: PhoneFactory.getPhones()) {
9622 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9623 if (tracker != null) {
9624 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009625 }
9626 }
9627 } finally {
9628 Binder.restoreCallingIdentity(identity);
9629 }
9630 }
9631
9632 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009633 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9634 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9635 Phone phone = getPhone(subId);
9636 if (phone == null) {
9637 return null;
9638 }
9639 final long identity = Binder.clearCallingIdentity();
9640 try {
9641 UiccProfile profile = UiccController.getInstance()
9642 .getUiccProfileForPhone(phone.getPhoneId());
9643 if (profile != null) {
9644 return profile.getCertsFromCarrierPrivilegeAccessRules();
9645 }
9646 } finally {
9647 Binder.restoreCallingIdentity(identity);
9648 }
9649 return null;
9650 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009651
9652 /**
9653 * Enable or disable a modem stack.
9654 */
9655 @Override
9656 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9657 enforceModifyPermission();
9658
9659 final long identity = Binder.clearCallingIdentity();
9660 try {
9661 Phone phone = PhoneFactory.getPhone(slotIndex);
9662 if (phone == null) {
9663 return false;
9664 } else {
9665 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9666 }
9667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
Michelecea4cf22018-12-21 15:00:11 -08009671
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009672 /**
9673 * Whether a modem stack is enabled or not.
9674 */
9675 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009676 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9677 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009678 Phone phone = PhoneFactory.getPhone(slotIndex);
9679 if (phone == null) return false;
9680
9681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009682 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9683 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009684 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9685 }
9686
9687 final long identity = Binder.clearCallingIdentity();
9688 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009689 try {
9690 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9691 } catch (NoSuchElementException ex) {
9692 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9693 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009694 } finally {
9695 Binder.restoreCallingIdentity(identity);
9696 }
9697 }
9698
Michelecea4cf22018-12-21 15:00:11 -08009699 @Override
Michele0ea7d782019-03-19 14:58:42 -07009700 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009701 enforceModifyPermission();
9702
9703 final long identity = Binder.clearCallingIdentity();
9704 try {
9705 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009706 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009707 .commit();
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
9713 @Override
Michele0ea7d782019-03-19 14:58:42 -07009714 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009715 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009717 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9718 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009719 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009720 }
Michelecea4cf22018-12-21 15:00:11 -08009721
9722 final long identity = Binder.clearCallingIdentity();
9723 try {
Michele0ea7d782019-03-19 14:58:42 -07009724 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009729
Michele0ea7d782019-03-19 14:58:42 -07009730 @TelephonyManager.IsMultiSimSupportedResult
9731 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009732 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9733 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9734 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009735 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9736 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009737 }
9738 // Check if the hardware supports multisim functionality. If usage of multisim is not
9739 // supported by the modem, indicate that it is restricted.
9740 PhoneCapability staticCapability =
9741 mPhoneConfigurationManager.getStaticPhoneCapability();
9742 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009743 loge("isMultiSimSupportedInternal: no static configuration available");
9744 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009745 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009746 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009747 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9748 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009749 }
9750 // Check if support of multiple SIMs is restricted by carrier
9751 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009752 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009753 }
9754
Michele0ea7d782019-03-19 14:58:42 -07009755 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009756 }
9757
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009758 /**
9759 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009760 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9761 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9762 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009763 * @param numOfSims number of active sims we want to switch to
9764 */
9765 @Override
9766 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009767 if (numOfSims == 1) {
9768 enforceModifyPermission();
9769 } else {
9770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9771 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9772 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009773 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009774
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009775 try {
Michele30b57b22019-03-01 12:01:14 -08009776 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009777 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009778 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9779 return;
9780 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009781 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009787 @Override
9788 public boolean isApplicationOnUicc(int subId, int appType) {
9789 enforceReadPrivilegedPermission("isApplicationOnUicc");
9790 Phone phone = getPhone(subId);
9791 if (phone == null) {
9792 return false;
9793 }
9794 final long identity = Binder.clearCallingIdentity();
9795 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009796 UiccPort uiccPort = phone.getUiccPort();
9797 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009798 return false;
9799 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009800 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009801 if (uiccProfile == null) {
9802 return false;
9803 }
9804 if (TelephonyManager.APPTYPE_SIM <= appType
9805 && appType <= TelephonyManager.APPTYPE_ISIM) {
9806 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9807 }
9808 return false;
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009814 /**
chen xub4baa772019-04-03 10:23:41 -07009815 * Get whether making changes to modem configurations will trigger reboot.
9816 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009817 */
9818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009819 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9820 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009822 mApp, subId, callingPackage, callingFeatureId,
9823 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009824 return false;
9825 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009826 final long identity = Binder.clearCallingIdentity();
9827 try {
9828 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
9833
Nathan Harold29f5f052019-02-15 13:41:57 -08009834 private void updateModemStateMetrics() {
9835 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9836 // TODO: check the state for each modem if the api is ready.
9837 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9838 }
9839
Pengquan Meng3889a572019-01-23 11:16:29 -08009840 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009841 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009842 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009843 // Verify that the callingPackage belongs to the calling UID
9844 mApp.getSystemService(AppOpsManager.class)
9845 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009846 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009847 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009848 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009849 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9850 if (slotInfos != null) {
9851 for (int i = 0; i < slotInfos.length; i++) {
9852 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9853 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9854 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9855 portInfo.getLogicalSlotIndex()));
9856 }
9857 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009858 }
9859 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009860 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009865
9866 /**
9867 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009868 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009869 */
jimsunf9ec1622022-09-13 21:18:43 +08009870 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009871 @Override
9872 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009873 return getHalVersion(HAL_SERVICE_RADIO);
9874 }
9875
9876 /**
9877 * Get the HAL Version of a specific service
9878 */
9879 @Override
9880 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009881 Phone phone = getDefaultPhone();
9882 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009883 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009884 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9885 return hv.major * 100 + hv.minor;
9886 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009887
9888 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009889 * Get the current calling package name.
9890 * @return the current calling package name
9891 */
9892 @Override
9893 public String getCurrentPackageName() {
9894 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9895 }
9896
9897 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009898 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9899 * corresponding network requests on a subId.
9900 *
9901 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009902 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009903 * 2) APN is un-metered for this subscription, or
9904 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009905 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009906 *
9907 * @return whether data is allowed for a apn type.
9908 *
9909 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009910 */
9911 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009912 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009913 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9914 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009915
9916 // Now that all security checks passes, perform the operation as ourselves.
9917 final long identity = Binder.clearCallingIdentity();
9918 try {
9919 Phone phone = getPhone(subId);
9920 if (phone == null) return false;
9921
Jack Yu27422a52022-03-21 10:38:05 -07009922 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009923 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009924 isMetered = phone.getDataNetworkController().getDataConfigManager()
9925 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9926 phone.getServiceState().getDataRoaming());
9927 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009928 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009929 } finally {
9930 Binder.restoreCallingIdentity(identity);
9931 }
9932 }
9933
9934 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009935 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009936 enforceReadPrivilegedPermission("isApnMetered");
9937
9938 // Now that all security checks passes, perform the operation as ourselves.
9939 final long identity = Binder.clearCallingIdentity();
9940 try {
9941 Phone phone = getPhone(subId);
9942 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009943 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9944 DataUtils.apnTypeToNetworkCapability(apnType),
9945 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009946 } finally {
9947 Binder.restoreCallingIdentity(identity);
9948 }
9949 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009950
9951 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009952 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9953 int subscriptionId, IBooleanConsumer resultCallback) {
9954 enforceModifyPermission();
9955 long token = Binder.clearCallingIdentity();
9956 try {
9957 Phone phone = getPhone(subscriptionId);
9958 if (phone == null) {
9959 try {
9960 if (resultCallback != null) {
9961 resultCallback.accept(false);
9962 }
9963 } catch (RemoteException e) {
9964 // ignore
9965 }
9966 return;
9967 }
9968 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9969 Pair.create(specifiers, (x) -> {
9970 try {
9971 if (resultCallback != null) {
9972 resultCallback.accept(x);
9973 }
9974 } catch (RemoteException e) {
9975 // ignore
9976 }
9977 });
9978 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9979 } finally {
9980 Binder.restoreCallingIdentity(token);
9981 }
9982 }
9983
9984 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009985 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9986 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009987 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009988 mApp, subId, "getSystemSelectionChannels");
9989 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9990 final long identity = Binder.clearCallingIdentity();
9991 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009992 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9993 if (result instanceof IllegalStateException) {
9994 throw (IllegalStateException) result;
9995 }
9996 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009997 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9998 return specifiers;
9999 } finally {
10000 Binder.restoreCallingIdentity(identity);
10001 }
10002 }
10003
10004 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010005 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010006 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010007 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010008 }
10009
10010 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010011 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10012 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010013 if (callingPackage == null) {
10014 callingPackage = getCurrentPackageName();
10015 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010016 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10017 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010018 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10019 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010020 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10021 }
10022 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10023 Intent intent = new Intent();
10024 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10025 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10026 // Bring up choose default SMS subscription dialog right now
10027 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10028 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10029 mApp.startActivity(intent);
10030 }
chen xud5ca2d52019-05-28 15:20:57 -070010031
10032 @Override
10033 public String getMmsUAProfUrl(int subId) {
10034 //TODO investigate if this API should require proper permission check in R b/133791609
10035 final long identity = Binder.clearCallingIdentity();
10036 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010037 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10038 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10039 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10040 return carrierUAProfUrl;
10041 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010042 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10043 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010044 } finally {
10045 Binder.restoreCallingIdentity(identity);
10046 }
10047 }
10048
10049 @Override
10050 public String getMmsUserAgent(int subId) {
10051 //TODO investigate if this API should require proper permission check in R b/133791609
10052 final long identity = Binder.clearCallingIdentity();
10053 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010054 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10055 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10056 if (!TextUtils.isEmpty(carrierUserAgent)) {
10057 return carrierUserAgent;
10058 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010059 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10060 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010061 } finally {
10062 Binder.restoreCallingIdentity(identity);
10063 }
10064 }
Jack Yub07d4972019-05-28 16:12:25 -070010065
10066 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010067 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10068 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010069
Jack Yub07d4972019-05-28 16:12:25 -070010070 final long identity = Binder.clearCallingIdentity();
10071 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010072 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010073 if (phone == null) return false;
10074
Ling Maf188d502022-09-16 15:22:36 -070010075 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010076 } finally {
10077 Binder.restoreCallingIdentity(identity);
10078 }
10079 }
10080
10081 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010082 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010083 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010084 enforceModifyPermission();
10085
changbettyd5c246e2019-12-24 15:40:37 +080010086 final long identity = Binder.clearCallingIdentity();
10087 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010088 Phone phone = getPhone(subscriptionId);
10089 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010090
Ling Maf188d502022-09-16 15:22:36 -070010091 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
10095 }
10096
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010097 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010098 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010099 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10100 * otherwise.
10101 */
10102 @Override
10103 public void setCepEnabled(boolean isCepEnabled) {
10104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10105
10106 final long identity = Binder.clearCallingIdentity();
10107 try {
10108 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10109 for (Phone phone : PhoneFactory.getPhones()) {
10110 Phone defaultPhone = phone.getImsPhone();
10111 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10112 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10113 ImsPhoneCallTracker imsPhoneCallTracker =
10114 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10115 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10116 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10117 + imsPhone.getMsisdn());
10118 }
10119 }
10120 } finally {
10121 Binder.restoreCallingIdentity(identity);
10122 }
10123 }
allenwtsu46dcc572020-01-08 18:24:03 +080010124
10125 /**
10126 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10127 *
10128 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10129 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10130 * before being read.
10131 */
10132 @Override
10133 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10134 isCompressed) {
10135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10136 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10138 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10139 }
10140 if (!isImsAvailableOnDevice()) {
10141 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10142 "IMS not available on device.");
10143 }
10144
10145 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010146 try {
Hui Wang761a6682020-10-31 05:12:53 +000010147 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10148 } finally {
10149 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010150 }
10151 }
zoey chene02881a2019-12-30 16:11:23 +080010152
10153 @Override
10154 public boolean isIccLockEnabled(int subId) {
10155 enforceReadPrivilegedPermission("isIccLockEnabled");
10156
10157 // Now that all security checks passes, perform the operation as ourselves.
10158 final long identity = Binder.clearCallingIdentity();
10159 try {
10160 Phone phone = getPhone(subId);
10161 if (phone != null && phone.getIccCard() != null) {
10162 return phone.getIccCard().getIccLockEnabled();
10163 } else {
10164 return false;
10165 }
10166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 /**
10172 * Set the ICC pin lock enabled or disabled.
10173 *
10174 * @return an integer representing the status of IccLock enabled or disabled in the following
10175 * three cases:
10176 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10177 * successfully.
10178 * - Positive number and zero for remaining password attempts.
10179 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10180 *
10181 */
10182 @Override
10183 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10184 enforceModifyPermission();
10185
10186 Phone phone = getPhone(subId);
10187 if (phone == null) {
10188 return 0;
10189 }
10190 // Now that all security checks passes, perform the operation as ourselves.
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10194 new Pair<Boolean, String>(enabled, password), phone, null);
10195 return attemptsRemaining;
10196
10197 } catch (Exception e) {
10198 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10199 } finally {
10200 Binder.restoreCallingIdentity(identity);
10201 }
10202 return 0;
10203 }
10204
10205 /**
10206 * Change the ICC password used in ICC pin lock.
10207 *
10208 * @return an integer representing the status of IccLock changed in the following three cases:
10209 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10210 * - Positive number and zero for remaining password attempts.
10211 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10212 *
10213 */
10214 @Override
10215 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10216 enforceModifyPermission();
10217
10218 Phone phone = getPhone(subId);
10219 if (phone == null) {
10220 return 0;
10221 }
10222 // Now that all security checks passes, perform the operation as ourselves.
10223 final long identity = Binder.clearCallingIdentity();
10224 try {
10225 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10226 new Pair<String, String>(oldPassword, newPassword), phone, null);
10227 return attemptsRemaining;
10228
10229 } catch (Exception e) {
10230 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 return 0;
10235 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010236
10237 /**
10238 * Request for receiving user activity notification
10239 */
10240 @Override
10241 public void requestUserActivityNotification() {
10242 if (!mNotifyUserActivity.get()
10243 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10244 mNotifyUserActivity.set(true);
10245 }
10246 }
10247
10248 /**
10249 * Called when userActivity is signalled in the power manager.
10250 * This is safe to call from any thread, with any window manager locks held or not.
10251 */
10252 @Override
10253 public void userActivity() {
10254 // ***************************************
10255 // * Inherited from PhoneWindowManager *
10256 // ***************************************
10257 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10258 // WITH ITS LOCKS HELD.
10259 //
10260 // This code must be VERY careful about the locks
10261 // it acquires.
10262 // In fact, the current code acquires way too many,
10263 // and probably has lurking deadlocks.
10264
10265 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10266 throw new SecurityException("Only the OS may call notifyUserActivity()");
10267 }
10268
10269 if (mNotifyUserActivity.getAndSet(false)) {
10270 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10271 USER_ACTIVITY_NOTIFICATION_DELAY);
10272 }
10273 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010274
10275 @Override
10276 public boolean canConnectTo5GInDsdsMode() {
10277 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10278 }
Jack Yud10cdd42020-09-28 20:28:01 -070010279
10280 @Override
10281 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10282 String callingFeatureId) {
10283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10284 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10285 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10286 }
10287
10288 Phone phone = getPhone(subId);
10289 if (phone == null) {
10290 throw new RuntimeException("phone is not available");
10291 }
10292 // Now that all security checks passes, perform the operation as ourselves.
10293 final long identity = Binder.clearCallingIdentity();
10294 try {
10295 return phone.getEquivalentHomePlmns();
10296 } finally {
10297 Binder.restoreCallingIdentity(identity);
10298 }
10299 }
Daniel Bright59e67312020-11-13 11:49:37 -080010300
10301 @Override
10302 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010303 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10304 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010305 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010306 if (radioInterfaceCapabilities == null) {
10307 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010308 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010309 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010310 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010311
Hui Wang641e81c2020-10-12 12:14:23 -070010312 @Override
10313 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10314 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010315 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10316 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10317 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10318 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10319 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010320 if (DBG) {
10321 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10322 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10323 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10324 }
10325
10326 if (!SubscriptionManager.isValidSubscriptionId(subId)
10327 || appType < TelephonyManager.APPTYPE_UNKNOWN
10328 || appType > TelephonyManager.APPTYPE_ISIM
10329 || nafUrl == null || securityProtocol == null || callback == null) {
10330 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10331 if (callback != null) {
10332 try {
10333 callback.onAuthenticationFailure(
10334 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10335 } catch (RemoteException exception) {
10336 log("Fail to notify onAuthenticationFailure due to " + exception);
10337 }
10338 return;
10339 }
10340 }
10341
10342 final long token = Binder.clearCallingIdentity();
10343 try {
10344 getGbaManager(subId).bootstrapAuthenticationRequest(
10345 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10346 forceBootStrapping, callback));
10347 } finally {
10348 Binder.restoreCallingIdentity(token);
10349 }
10350 }
10351
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010352 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010353 * Attempts to set the radio power state for all phones for thermal reason.
10354 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010355 * requested radio power state will actually be set. See {@link
10356 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10357 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010358 * @param enable {@code true} if trying to turn radio on.
10359 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10360 * false}.
10361 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010362 private boolean setRadioPowerForThermal(boolean enable) {
10363 boolean isPhoneAvailable = false;
10364 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10365 Phone phone = PhoneFactory.getPhone(i);
10366 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010367 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010368 isPhoneAvailable = true;
10369 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010370 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010371
10372 // return true if successfully informed the phone object about the thermal radio power
10373 // request.
10374 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010375 }
10376
10377 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010378 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010379 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10380 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10381 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10382 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10383 throw new IllegalArgumentException("modem does not support data throttling");
10384 }
10385
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010386 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10387 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010388 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010389 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10390 }
10391
Sarah Chinecc78c42022-03-31 21:16:48 -070010392 setDataEnabledForReason(
10393 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010394
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010395 if (isDataThrottlingSupported) {
10396 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010397 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010398 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10399 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10400 } else if (thermalMitigationResult
10401 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010402 log("Modem likely does not support data throttling on secondary carrier. Data " +
10403 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10404 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010405 }
10406 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010407 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010408
10409 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010410 }
10411
Jack Nudelman644b91a2021-03-12 14:09:48 -080010412 private static List<String> getThermalMitigationAllowlist(Context context) {
10413 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10414 for (String pckg : context.getResources()
10415 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10416 sThermalMitigationAllowlistedPackages.add(pckg);
10417 }
10418 }
10419
10420 return sThermalMitigationAllowlistedPackages;
10421 }
10422
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010423 private boolean isAnyPhoneInEmergencyState() {
10424 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10425 if (tm.isInEmergencyCall()) {
10426 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10427 return true;
10428 }
10429 for (Phone phone : PhoneFactory.getPhones()) {
10430 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10431 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10432 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10433 + phone.isInEcm());
10434 return true;
10435 }
10436 }
10437
10438 return false;
10439 }
10440
Jack Nudelman644b91a2021-03-12 14:09:48 -080010441 /**
10442 * Used by shell commands to add an authorized package name for thermal mitigation.
10443 * @param packageName name of package to be allowlisted
10444 * @param context
10445 */
10446 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10447 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10448 sThermalMitigationAllowlistedPackages.add(packageName);
10449 }
10450
10451 /**
10452 * Used by shell commands to remove an authorized package name for thermal mitigation.
10453 * @param packageName name of package to remove from allowlist
10454 * @param context
10455 */
10456 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10457 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10458 sThermalMitigationAllowlistedPackages.remove(packageName);
10459 }
10460
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010461 /**
10462 * Thermal mitigation request to control functionalities at modem.
10463 *
10464 * @param subId the id of the subscription.
10465 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010466 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010467 *
10468 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10469 */
10470 @Override
10471 @ThermalMitigationResult
10472 public int sendThermalMitigationRequest(
10473 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010474 ThermalMitigationRequest thermalMitigationRequest,
10475 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010476 enforceModifyPermission();
10477
Jack Nudelman644b91a2021-03-12 14:09:48 -080010478 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10479 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10480 .contains(callingPackage)) {
10481 throw new SecurityException("Calling package must be configured in the device config. "
10482 + "calling package: " + callingPackage);
10483 }
10484
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10486 final long identity = Binder.clearCallingIdentity();
10487
10488 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10489 try {
10490 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10491 switch (thermalMitigationAction) {
10492 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10493 thermalMitigationResult =
10494 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010495 thermalMitigationRequest.getDataThrottlingRequest(),
10496 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010497 break;
10498 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10499 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10500 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10501 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10502 }
10503
10504 // Ensure that radio is on. If not able to power on due to phone being
10505 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010506 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010507 thermalMitigationResult =
10508 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10509 break;
10510 }
10511
10512 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010513 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010514 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10515 break;
10516 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10517 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10518 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10519 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10520 }
10521
10522 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10523 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010524 Phone phone = getPhone(subId);
10525 if (phone == null) {
10526 thermalMitigationResult =
10527 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10528 break;
10529 }
10530
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010531 TelephonyConnectionService service =
10532 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010533 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010534 Log.e(LOG_TAG, "An emergency call is pending");
10535 thermalMitigationResult =
10536 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10537 break;
10538 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010539 thermalMitigationResult =
10540 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10541 break;
10542 }
10543 } else {
10544 thermalMitigationResult =
10545 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10546 break;
10547 }
10548
10549 // Turn radio off. If not able to power off due to phone being unavailable,
10550 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010551 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010552 thermalMitigationResult =
10553 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10554 break;
10555 }
10556 thermalMitigationResult =
10557 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10558 break;
10559 default:
10560 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10561 + "not exist. Requested action: " + thermalMitigationAction);
10562 }
10563 } catch (IllegalArgumentException e) {
10564 throw e;
10565 } catch (Exception e) {
10566 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10567 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10568 } finally {
10569 Binder.restoreCallingIdentity(identity);
10570 }
10571
10572 if (DBG) {
10573 log("thermalMitigationRequest returning with thermalMitigationResult: "
10574 + thermalMitigationResult);
10575 }
10576
10577 return thermalMitigationResult;
10578 }
Hui Wang641e81c2020-10-12 12:14:23 -070010579
10580 /**
10581 * Set the GbaService Package Name that Telephony will bind to.
10582 *
10583 * @param subId The sim that the GbaService is associated with.
10584 * @param packageName The name of the package to be replaced with.
10585 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10586 */
10587 @Override
10588 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10589 enforceModifyPermission();
10590
10591 final long identity = Binder.clearCallingIdentity();
10592 try {
10593 return getGbaManager(subId).overrideServicePackage(packageName);
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
10599 /**
10600 * Return the package name of the currently bound GbaService.
10601 *
10602 * @param subId The sim that the GbaService is associated with.
10603 * @return the package name of the GbaService configuration, null if GBA is not supported.
10604 */
10605 @Override
10606 public String getBoundGbaService(int subId) {
10607 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10608
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 return getGbaManager(subId).getServicePackage();
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 }
10616
10617 /**
10618 * Set the release time for telephony to unbind GbaService.
10619 *
10620 * @param subId The sim that the GbaService is associated with.
10621 * @param interval The release time to unbind GbaService by millisecond.
10622 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10623 */
10624 @Override
10625 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10626 enforceModifyPermission();
10627
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 return getGbaManager(subId).overrideReleaseTime(interval);
10631 } finally {
10632 Binder.restoreCallingIdentity(identity);
10633 }
10634 }
10635
10636 /**
10637 * Return the release time for telephony to unbind GbaService.
10638 *
10639 * @param subId The sim that the GbaService is associated with.
10640 * @return The release time to unbind GbaService by millisecond.
10641 */
10642 @Override
10643 public int getGbaReleaseTime(int subId) {
10644 enforceReadPrivilegedPermission("getGbaReleaseTime");
10645
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 return getGbaManager(subId).getReleaseTime();
10649 } finally {
10650 Binder.restoreCallingIdentity(identity);
10651 }
10652 }
10653
10654 private GbaManager getGbaManager(int subId) {
10655 GbaManager instance = GbaManager.getInstance(subId);
10656 if (instance == null) {
10657 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10658 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10659 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10660 }
10661 return instance;
10662 }
Hui Wang761a6682020-10-31 05:12:53 +000010663
10664 /**
10665 * indicate whether the device and the carrier can support
10666 * RCS VoLTE single registration.
10667 */
10668 @Override
10669 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010670 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10671 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10672 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10673 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010674
10675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10676 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10677 }
10678
10679 final long identity = Binder.clearCallingIdentity();
10680 try {
10681 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10682 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010683 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10684 if (isCapable != null) {
10685 return isCapable;
10686 }
Hui Wang761a6682020-10-31 05:12:53 +000010687 }
Hui Wang67af90e2021-06-04 16:57:15 -070010688 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10689 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010690 } finally {
10691 Binder.restoreCallingIdentity(identity);
10692 }
10693 }
10694
10695 /**
10696 * Register RCS provisioning callback.
10697 */
10698 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010699 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010700 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010701 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010702 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010703 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10704 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010705
10706 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10707 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10708 }
10709 if (!isImsAvailableOnDevice()) {
10710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10711 "IMS not available on device.");
10712 }
10713
10714 final long identity = Binder.clearCallingIdentity();
10715 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010716 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010717 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010718 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10719 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010720 }
Hui Wang761a6682020-10-31 05:12:53 +000010721 } finally {
10722 Binder.restoreCallingIdentity(identity);
10723 }
10724 }
10725
10726 /**
10727 * Unregister RCS provisioning callback.
10728 */
10729 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010730 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010731 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010732 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010733 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010734 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10735 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010736
10737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10738 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10739 }
10740 if (!isImsAvailableOnDevice()) {
10741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10742 "IMS not available on device.");
10743 }
10744
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010747 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010748 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010749 } finally {
10750 Binder.restoreCallingIdentity(identity);
10751 }
10752 }
10753
10754 /**
10755 * trigger RCS reconfiguration.
10756 */
10757 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010758 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10759 "triggerRcsReconfiguration",
10760 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010761
10762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10763 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10764 }
10765 if (!isImsAvailableOnDevice()) {
10766 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10767 "IMS not available on device.");
10768 }
10769
10770 final long identity = Binder.clearCallingIdentity();
10771 try {
10772 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10773 } finally {
10774 Binder.restoreCallingIdentity(identity);
10775 }
10776 }
10777
10778 /**
10779 * Provide the client configuration parameters of the RCS application.
10780 */
10781 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010782 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10783 "setRcsClientConfiguration",
10784 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010785
10786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10787 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10788 }
10789 if (!isImsAvailableOnDevice()) {
10790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10791 "IMS not available on device.");
10792 }
10793
10794 final long identity = Binder.clearCallingIdentity();
10795
10796 try {
10797 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10798 if (configBinder == null) {
10799 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010800 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10801 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010802 } else {
10803 configBinder.setRcsClientConfiguration(rcc);
10804 }
joonhunshin3e154242021-09-17 06:33:39 +000010805
10806 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10807 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010808 } catch (RemoteException e) {
10809 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010810 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10811 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010812 } finally {
10813 Binder.restoreCallingIdentity(identity);
10814 }
10815 }
10816
10817 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010818 * Enables or disables the test mode for RCS VoLTE single registration.
10819 */
10820 @Override
10821 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10822 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10823 "setRcsSingleRegistrationTestModeEnabled");
10824
10825 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10826 }
10827
10828 /**
10829 * Gets the test mode for RCS VoLTE single registration.
10830 */
10831 @Override
10832 public boolean getRcsSingleRegistrationTestModeEnabled() {
10833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10834 "getRcsSingleRegistrationTestModeEnabled");
10835
10836 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10837 }
10838
10839 /**
Hui Wang761a6682020-10-31 05:12:53 +000010840 * Overrides the config of RCS VoLTE single registration enabled for the device.
10841 */
10842 @Override
10843 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10845 "setDeviceSingleRegistrationEnabledOverride");
10846 enforceModifyPermission();
10847
10848 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10849 : Boolean.parseBoolean(enabledStr);
10850 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010851 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010852 }
10853
10854 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010855 * Sends a device to device communication message. Only usable via shell.
10856 * @param message message to send.
10857 * @param value message value.
10858 */
10859 @Override
10860 public void sendDeviceToDeviceMessage(int message, int value) {
10861 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010862 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010863 enforceModifyPermission();
10864
10865 final long identity = Binder.clearCallingIdentity();
10866 try {
10867 TelephonyConnectionService service =
10868 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10869 if (service == null) {
10870 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10871 return;
10872 }
10873 service.sendTestDeviceToDeviceMessage(message, value);
10874 } finally {
10875 Binder.restoreCallingIdentity(identity);
10876 }
10877 }
10878
Tyler Gunnbabbda02021-02-10 11:05:02 -080010879 /**
10880 * Sets the specified device to device transport active.
10881 * @param transport The transport to set active.
10882 */
10883 @Override
10884 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10886 "setActiveDeviceToDeviceTransport");
10887 enforceModifyPermission();
10888
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 TelephonyConnectionService service =
10892 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10893 if (service == null) {
10894 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10895 return;
10896 }
10897 service.setActiveDeviceToDeviceTransport(transport);
10898 } finally {
10899 Binder.restoreCallingIdentity(identity);
10900 }
10901 }
Tyler Gunn92479152021-01-20 16:30:10 -080010902
Tyler Gunnd4339262021-05-03 14:46:49 -070010903 @Override
10904 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10906 "setDeviceToDeviceForceEnabled");
10907
10908 final long identity = Binder.clearCallingIdentity();
10909 try {
10910 Arrays.stream(PhoneFactory.getPhones()).forEach(
10911 p -> {
10912 Phone thePhone = p.getImsPhone();
10913 if (thePhone != null && thePhone instanceof ImsPhone) {
10914 ImsPhone imsPhone = (ImsPhone) thePhone;
10915 CallTracker tracker = imsPhone.getCallTracker();
10916 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10917 ImsPhoneCallTracker imsPhoneCallTracker =
10918 (ImsPhoneCallTracker) tracker;
10919 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10920 }
10921 }
10922 }
10923 );
10924 } finally {
10925 Binder.restoreCallingIdentity(identity);
10926 }
10927 }
10928
Tyler Gunn92479152021-01-20 16:30:10 -080010929 /**
Hui Wang761a6682020-10-31 05:12:53 +000010930 * Gets the config of RCS VoLTE single registration enabled for the device.
10931 */
10932 @Override
10933 public boolean getDeviceSingleRegistrationEnabled() {
10934 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10935 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10936 }
10937
10938 /**
10939 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10940 */
10941 @Override
10942 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10944 "setCarrierSingleRegistrationEnabledOverride");
10945 enforceModifyPermission();
10946
10947 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10948 : Boolean.parseBoolean(enabledStr);
10949 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10950 subId, enabled);
10951 }
10952
10953 /**
10954 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10955 */
10956 @Override
10957 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10958 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10959 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10960 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010961
10962 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010963 * Overrides the ims feature validation result
10964 */
10965 @Override
10966 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10968 "setImsFeatureValidationOverride");
10969
10970 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10971 : Boolean.parseBoolean(enabledStr);
10972 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10973 subId, enabled);
10974 }
10975
10976 /**
10977 * Gets the ims feature validation override value
10978 */
10979 @Override
10980 public boolean getImsFeatureValidationOverride(int subId) {
10981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10982 "getImsFeatureValidationOverride");
10983 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10984 }
10985
10986 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010987 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10988 * their mobile plan.
10989 */
10990 @Override
10991 public String getMobileProvisioningUrl() {
10992 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
10995 return getDefaultPhone().getMobileProvisioningUrl();
10996 } finally {
10997 Binder.restoreCallingIdentity(identity);
10998 }
10999 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011000
James.cf Linbcdf8b32021-01-14 16:44:13 +080011001 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011002 * Get the EAB contact from the EAB database.
11003 */
11004 @Override
11005 public String getContactFromEab(String contact) {
11006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11007 enforceModifyPermission();
11008 final long identity = Binder.clearCallingIdentity();
11009 try {
11010 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11011 } finally {
11012 Binder.restoreCallingIdentity(identity);
11013 }
11014 }
11015
11016 /**
Calvin Pana1434322021-07-01 19:27:01 +080011017 * Get the EAB capability from the EAB database.
11018 */
11019 @Override
11020 public String getCapabilityFromEab(String contact) {
11021 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11022 enforceModifyPermission();
11023 final long identity = Binder.clearCallingIdentity();
11024 try {
11025 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11026 } finally {
11027 Binder.restoreCallingIdentity(identity);
11028 }
11029 }
11030
11031 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011032 * Remove the EAB contacts from the EAB database.
11033 */
11034 @Override
11035 public int removeContactFromEab(int subId, String contacts) {
11036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11037 enforceModifyPermission();
11038 final long identity = Binder.clearCallingIdentity();
11039 try {
11040 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11041 } finally {
11042 Binder.restoreCallingIdentity(identity);
11043 }
11044 }
11045
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011046 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011047 public boolean getDeviceUceEnabled() {
11048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11049 final long identity = Binder.clearCallingIdentity();
11050 try {
11051 return mApp.getDeviceUceEnabled();
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
11056
11057 @Override
11058 public void setDeviceUceEnabled(boolean isEnabled) {
11059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11060 final long identity = Binder.clearCallingIdentity();
11061 try {
11062 mApp.setDeviceUceEnabled(isEnabled);
11063 } finally {
11064 Binder.restoreCallingIdentity(identity);
11065 }
11066 }
11067
Brad Ebinger14d467f2021-02-12 06:18:28 +000011068 /**
11069 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11070 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11071 */
11072 // Used for SHELL command only right now.
11073 @Override
11074 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11075 List<String> featureTags) {
11076 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11077 "addUceRegistrationOverrideShell");
11078 final long identity = Binder.clearCallingIdentity();
11079 try {
11080 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11081 new ArraySet<>(featureTags));
11082 } catch (ImsException e) {
11083 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11084 } finally {
11085 Binder.restoreCallingIdentity(identity);
11086 }
11087 }
11088
11089 /**
11090 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11091 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11092 */
11093 // Used for SHELL command only right now.
11094 @Override
11095 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11096 List<String> featureTags) {
11097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11098 "removeUceRegistrationOverrideShell");
11099 final long identity = Binder.clearCallingIdentity();
11100 try {
11101 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11102 new ArraySet<>(featureTags));
11103 } catch (ImsException e) {
11104 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11105 } finally {
11106 Binder.restoreCallingIdentity(identity);
11107 }
11108 }
11109
11110 /**
11111 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11112 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11113 */
11114 // Used for SHELL command only right now.
11115 @Override
11116 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11118 "clearUceRegistrationOverrideShell");
11119 final long identity = Binder.clearCallingIdentity();
11120 try {
11121 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11122 } catch (ImsException e) {
11123 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
11129 /**
11130 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11131 */
11132 // Used for SHELL command only right now.
11133 @Override
11134 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11135 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11136 "getLatestRcsContactUceCapabilityShell");
11137 final long identity = Binder.clearCallingIdentity();
11138 try {
11139 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11140 } catch (ImsException e) {
11141 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11142 } finally {
11143 Binder.restoreCallingIdentity(identity);
11144 }
11145 }
11146
11147 /**
11148 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11149 * device does not have an active PUBLISH.
11150 */
11151 // Used for SHELL command only right now.
11152 @Override
11153 public String getLastUcePidfXmlShell(int subId) {
11154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11155 final long identity = Binder.clearCallingIdentity();
11156 try {
11157 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11158 } catch (ImsException e) {
11159 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 }
11164
James.cf Line8713a42021-04-29 16:04:26 +080011165 /**
11166 * Remove UCE requests cannot be sent to the network status.
11167 */
11168 // Used for SHELL command only right now.
11169 @Override
11170 public boolean removeUceRequestDisallowedStatus(int subId) {
11171 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11172 final long identity = Binder.clearCallingIdentity();
11173 try {
11174 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11175 } catch (ImsException e) {
11176 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11177 } finally {
11178 Binder.restoreCallingIdentity(identity);
11179 }
11180 }
11181
James.cf Lin18bb9002021-05-25 01:37:38 +080011182 /**
11183 * Remove UCE requests cannot be sent to the network status.
11184 */
11185 // Used for SHELL command only.
11186 @Override
11187 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11188 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11189 final long identity = Binder.clearCallingIdentity();
11190 try {
11191 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11192 } catch (ImsException e) {
11193 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11194 } finally {
11195 Binder.restoreCallingIdentity(identity);
11196 }
11197 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011198
James.cf Lin4b784aa2021-01-31 03:25:15 +080011199 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011200 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11201 String callingPackage) {
11202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11203 mApp, subId, "setSignalStrengthUpdateRequest");
11204
11205 final int callingUid = Binder.getCallingUid();
11206 // Verify that tha callingPackage belongs to the calling UID
11207 mApp.getSystemService(AppOpsManager.class)
11208 .checkPackage(callingUid, callingPackage);
11209
Rambo Wang3607f502021-02-01 21:51:40 -080011210 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011211
11212 final long identity = Binder.clearCallingIdentity();
11213 try {
11214 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11215 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11216
11217 if (result instanceof IllegalStateException) {
11218 throw (IllegalStateException) result;
11219 }
11220 } finally {
11221 Binder.restoreCallingIdentity(identity);
11222 }
11223 }
11224
11225 @Override
11226 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11227 String callingPackage) {
11228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11229 mApp, subId, "clearSignalStrengthUpdateRequest");
11230
11231 final int callingUid = Binder.getCallingUid();
11232 // Verify that tha callingPackage belongs to the calling UID
11233 mApp.getSystemService(AppOpsManager.class)
11234 .checkPackage(callingUid, callingPackage);
11235
11236 final long identity = Binder.clearCallingIdentity();
11237 try {
11238 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11239 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11240
11241 if (result instanceof IllegalStateException) {
11242 throw (IllegalStateException) result;
11243 }
11244 } finally {
11245 Binder.restoreCallingIdentity(identity);
11246 }
11247 }
11248
Rambo Wang3607f502021-02-01 21:51:40 -080011249 private static void validateSignalStrengthUpdateRequest(Context context,
11250 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011251 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11252 // phone/system process do not have further restriction on request
11253 return;
11254 }
11255
11256 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011257 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011258 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011259 context.enforceCallingOrSelfPermission(
11260 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11261 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011262 }
11263
11264 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11265 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11266 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11267 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11268 || info.isEnabled()) {
11269 throw new IllegalArgumentException(
11270 "Only system can set hide fields in SignalThresholdInfo");
11271 }
11272
11273 // Thresholds length for each RAN need in range. This has been validated in
11274 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11275 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11276 final int[] thresholds = info.getThresholds();
11277 Objects.requireNonNull(thresholds);
11278 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11279 || thresholds.length
11280 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11281 throw new IllegalArgumentException(
11282 "thresholds length is out of range: " + thresholds.length);
11283 }
11284 }
11285 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011286
11287 /**
11288 * Gets the current phone capability.
11289 *
11290 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11291 * @return the PhoneCapability which describes the data connection capability of modem.
11292 * It's used to evaluate possible phone config change, for example from single
11293 * SIM device to multi-SIM device.
11294 */
11295 @Override
11296 public PhoneCapability getPhoneCapability() {
11297 enforceReadPrivilegedPermission("getPhoneCapability");
11298 final long identity = Binder.clearCallingIdentity();
11299 try {
11300 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11301 } finally {
11302 Binder.restoreCallingIdentity(identity);
11303 }
11304 }
Michele Berionne5e411512020-11-13 02:36:59 +000011305
11306 /**
11307 * Prepare TelephonyManager for an unattended reboot. The reboot is
11308 * required to be done shortly after the API is invoked.
11309 */
11310 @Override
11311 @TelephonyManager.PrepareUnattendedRebootResult
11312 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011313 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011314 enforceRebootPermission();
11315
11316 final long identity = Binder.clearCallingIdentity();
11317 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011318 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011319 } finally {
11320 Binder.restoreCallingIdentity(identity);
11321 }
11322 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011323
11324 /**
11325 * Request to get the current slicing configuration including URSP rules and
11326 * NSSAIs (configured, allowed and rejected).
11327 *
11328 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11329 */
11330 @Override
11331 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011332 TelephonyPermissions
11333 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11334 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011335
11336 final long identity = Binder.clearCallingIdentity();
11337 try {
11338 Phone phone = getDefaultPhone();
11339 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11340 } finally {
11341 Binder.restoreCallingIdentity(identity);
11342 }
11343 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011344
11345 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011346 * Check whether the given premium capability is available for purchase from the carrier.
11347 *
11348 * @param capability The premium capability to check.
11349 * @param subId The subId to check the premium capability for.
11350 *
11351 * @return Whether the given premium capability is available to purchase.
11352 */
11353 @Override
11354 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11355 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11356 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11357 log("Premium capability "
11358 + TelephonyManager.convertPremiumCapabilityToString(capability)
11359 + " is not available for purchase due to missing permissions.");
11360 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11361 + "permission READ_BASIC_PHONE_STATE.");
11362 }
11363
11364 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011365 if (phone == null) {
11366 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11367 return false;
11368 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011369 final long identity = Binder.clearCallingIdentity();
11370 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011371 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011372 .isPremiumCapabilityAvailableForPurchase(capability);
11373 } finally {
11374 Binder.restoreCallingIdentity(identity);
11375 }
11376 }
11377
11378 /**
11379 * Purchase the given premium capability from the carrier.
11380 *
11381 * @param capability The premium capability to purchase.
11382 * @param callback The result of the purchase request.
11383 * @param subId The subId to purchase the premium capability for.
11384 */
11385 @Override
11386 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11387 log("purchasePremiumCapability: capability="
11388 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11389 + getCurrentPackageName());
11390
11391 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11392 mApp, "purchasePremiumCapability")) {
11393 log("purchasePremiumCapability "
11394 + TelephonyManager.convertPremiumCapabilityToString(capability)
11395 + " failed due to missing permissions.");
11396 throw new SecurityException("purchasePremiumCapability requires permission "
11397 + "READ_BASIC_PHONE_STATE.");
11398 }
11399
11400 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011401 if (phone == null) {
11402 try {
11403 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11404 callback.accept(result);
11405 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11406 } catch (RemoteException e) {
11407 String logStr = "Purchase premium capability "
11408 + TelephonyManager.convertPremiumCapabilityToString(capability)
11409 + " failed due to RemoteException handling null phone: " + e;
11410 if (DBG) log(logStr);
11411 AnomalyReporter.reportAnomaly(
11412 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11413 }
11414 return;
11415 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011416 String appName;
11417 try {
11418 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11419 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11420 } catch (PackageManager.NameNotFoundException e) {
11421 appName = "An application";
11422 }
11423 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11424 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011425 }
11426
11427 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011428 * Register an IMS connection state callback
11429 */
11430 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011431 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11432 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011433 if (feature == ImsFeature.FEATURE_MMTEL) {
11434 // ImsMmTelManager
11435 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11436 TelephonyPermissions
11437 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11438 mApp, subId, "registerImsStateCallback");
11439 } else if (feature == ImsFeature.FEATURE_RCS) {
11440 // ImsRcsManager or SipDelegateManager
11441 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11442 Binder.getCallingUid(), "registerImsStateCallback",
11443 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11444 Manifest.permission.READ_PRECISE_PHONE_STATE,
11445 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11446 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11447 }
11448
11449 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11450 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11451 "IMS not available on device.");
11452 }
11453
11454 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11455 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11456 }
11457
11458 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11459 if (controller == null) {
11460 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11461 "IMS not available on device.");
11462 }
11463
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011464 if (callingPackage == null) {
11465 callingPackage = getCurrentPackageName();
11466 }
11467
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011468 final long token = Binder.clearCallingIdentity();
11469 try {
11470 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011471 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011472 } catch (ImsException e) {
11473 throw new ServiceSpecificException(e.getCode());
11474 } finally {
11475 Binder.restoreCallingIdentity(token);
11476 }
11477 }
11478
11479 /**
11480 * Unregister an IMS connection state callback
11481 */
11482 @Override
11483 public void unregisterImsStateCallback(IImsStateCallback cb) {
11484 final long token = Binder.clearCallingIdentity();
11485 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11486 if (controller == null) {
11487 return;
11488 }
11489 try {
11490 controller.unregisterImsStateCallback(cb);
11491 } finally {
11492 Binder.restoreCallingIdentity(token);
11493 }
11494 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011495
11496 /**
11497 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11498 *
11499 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11500 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11501 * SecurityException.
11502 * If there is current registered network this value will be same as the registered cell
11503 * identity. If the device goes out of service the previous cell identity is cached and
11504 * will be returned. If the cache age of the Cell identity is more than 24 hours
11505 * it will be cleared and null will be returned.
11506 *
11507 */
11508 @Override
11509 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11510 String callingFeatureId) {
11511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11512 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11513 LocationAccessPolicy.checkLocationPermission(mApp,
11514 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11515 .setCallingPackage(callingPackage)
11516 .setCallingFeatureId(callingFeatureId)
11517 .setCallingPid(Binder.getCallingPid())
11518 .setCallingUid(Binder.getCallingUid())
11519 .setMethod("getLastKnownCellIdentity")
11520 .setLogAsInfo(true)
11521 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11522 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11523 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11524 .build());
11525
11526 boolean hasFinePermission =
11527 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11528 if (!hasFinePermission
11529 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11530 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011531 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011532 }
11533
11534 final long identity = Binder.clearCallingIdentity();
11535 try {
11536 Phone phone = getPhone(subId);
11537 if (phone == null) return null;
11538 ServiceStateTracker sst = phone.getServiceStateTracker();
11539 if (sst == null) return null;
11540 return sst.getLastKnownCellIdentity();
11541 } finally {
11542 Binder.restoreCallingIdentity(identity);
11543 }
11544 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011545
jimsun3b9ccac2021-10-26 15:01:23 +080011546 /**
11547 * Sets the modem service class Name that Telephony will bind to.
11548 *
11549 * @param serviceName The class name of the modem service.
11550 * @return true if the operation is succeed, otherwise false.
11551 */
11552 public boolean setModemService(String serviceName) {
11553 Log.d(LOG_TAG, "setModemService - " + serviceName);
11554 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11556 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11557 "setModemService");
11558 return mPhoneConfigurationManager.setModemService(serviceName);
11559 }
11560
11561 /**
11562 * Return the class name of the currently bounded modem service.
11563 *
11564 * @return the class name of the modem service.
11565 */
11566 public String getModemService() {
11567 String result;
11568 Log.d(LOG_TAG, "getModemService");
11569 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11570 TelephonyPermissions
11571 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11572 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11573 "getModemService");
11574 result = mPhoneConfigurationManager.getModemService();
11575 Log.d(LOG_TAG, "result = " + result);
11576 return result;
11577 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011578
11579 @Override
11580 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11581 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11582 mApp.enforceCallingOrSelfPermission(
11583 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11585
11586 final long identity = Binder.clearCallingIdentity();
11587 try {
11588 Phone phone = getPhone(subId);
11589 if (phone == null) return;
11590 phone.setVoiceServiceStateOverride(hasService);
11591 } finally {
11592 Binder.restoreCallingIdentity(identity);
11593 }
11594 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011595
11596 /**
11597 * set removable eSIM as default eUICC.
11598 *
11599 * @hide
11600 */
11601 @Override
11602 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11603 enforceModifyPermission();
11604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11605
11606 final long identity = Binder.clearCallingIdentity();
11607 try {
11608 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11609 } finally {
11610 Binder.restoreCallingIdentity(identity);
11611 }
11612 }
11613
11614 /**
11615 * Returns whether the removable eSIM is default eUICC or not.
11616 *
11617 * @hide
11618 */
11619 @Override
11620 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11621 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11623
11624 final long identity = Binder.clearCallingIdentity();
11625 try {
11626 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11627 } finally {
11628 Binder.restoreCallingIdentity(identity);
11629 }
11630 }
11631
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011632 /**
11633 * Get the component name of the default app to direct respond-via-message intent for the
11634 * user associated with this subscription, update the cache if there is no respond-via-message
11635 * application currently configured for this user.
11636 * @return component name of the app and class to direct Respond Via Message intent to, or
11637 * {@code null} if the functionality is not supported.
11638 * @hide
11639 */
11640 @Override
11641 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11642 boolean updateIfNeeded) {
11643 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011644
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011645 Context context = getPhone(subId).getContext();
11646 UserHandle userHandle = null;
11647 final long identity = Binder.clearCallingIdentity();
11648 try {
11649 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11650 } finally {
11651 Binder.restoreCallingIdentity(identity);
11652 }
11653 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11654 updateIfNeeded, userHandle);
11655 }
Jack Yuf5badd92022-12-08 00:50:53 -080011656
11657 /**
11658 * Get the SIM state for the slot index.
11659 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11660 *
11661 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11662 */
11663 @Override
11664 @SimState
11665 public int getSimStateForSlotIndex(int slotIndex) {
11666 IccCardConstants.State simState;
11667 if (slotIndex < 0) {
11668 simState = IccCardConstants.State.UNKNOWN;
11669 } else {
11670 Phone phone = null;
11671 try {
11672 phone = PhoneFactory.getPhone(slotIndex);
11673 } catch (IllegalStateException e) {
11674 // ignore
11675 }
11676 if (phone == null) {
11677 simState = IccCardConstants.State.UNKNOWN;
11678 } else {
11679 IccCard icc = phone.getIccCard();
11680 if (icc == null) {
11681 simState = IccCardConstants.State.UNKNOWN;
11682 } else {
11683 simState = icc.getState();
11684 }
11685 }
11686 }
11687 return simState.ordinal();
11688 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011689
11690 /**
11691 * Get current cell broadcast ranges.
11692 */
11693 @Override
11694 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11695 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11696 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11697 "getCellBroadcastIdRanges");
11698 final long identity = Binder.clearCallingIdentity();
11699 try {
11700 return getPhone(subId).getCellBroadcastIdRanges();
11701 } finally {
11702 Binder.restoreCallingIdentity(identity);
11703 }
11704 }
11705
11706 /**
11707 * Set reception of cell broadcast messages with the list of the given ranges
11708 *
11709 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11710 */
11711 @Override
11712 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11713 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11714 @Nullable IIntegerConsumer callback) {
11715 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11716 "setCellBroadcastIdRanges");
11717 final long identity = Binder.clearCallingIdentity();
11718 try {
11719 Phone phone = getPhoneFromSubId(subId);
11720 if (DBG) {
11721 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11722 }
11723 phone.setCellBroadcastIdRanges(ranges, result -> {
11724 if (callback != null) {
11725 try {
11726 callback.accept(result);
11727 } catch (RemoteException e) {
11728 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
11729 }
11730 }
11731 });
11732 } finally {
11733 Binder.restoreCallingIdentity(identity);
11734 }
11735 }
11736}