blob: b8b730a435e756906c163857dd1a90f3a110298c [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;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080035import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070036import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000037import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080038import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000039import android.compat.annotation.ChangeId;
40import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070041import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070042import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.content.Context;
44import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070045import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070046import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070047import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.net.Uri;
49import android.os.AsyncResult;
50import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080051import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Bundle;
53import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080055import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.Looper;
57import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070058import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080059import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070060import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070061import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080062import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080063import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070064import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070065import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080066import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070068import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070070import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070071import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080072import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070073import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090074import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080075import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080076import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070077import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080078import android.telephony.AccessNetworkConstants;
79import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070080import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070081import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080082import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070083import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080084import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070085import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080086import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060087import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070088import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080089import android.telephony.CellIdentityCdma;
90import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070092import android.telephony.CellInfoGsm;
93import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070094import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070096import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070097import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070098import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080099import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700100import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800101import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700102import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800103import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800104import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700105import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800106import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800108import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800109import android.telephony.SignalStrengthUpdateRequest;
110import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800111import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800113import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700114import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800116import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800117import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800118import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800119import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000120import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000121import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000122import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700123import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700124import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800125import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800126import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700127import android.telephony.gba.GbaAuthRequest;
128import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700129import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800130import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000132import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700133import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000134import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700135import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800136import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700137import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800138import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000140import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700141import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800142import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800143import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800145import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700146import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800148import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800149
Andrew Lee312e8172014-10-23 17:01:36 -0700150import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800151import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800152import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800153import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700156import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700157import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800158import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800159import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700160import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800162import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700163import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800164import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800165import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800166import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700167import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000168import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800170import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800173import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800174import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700175import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700176import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700177import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700179import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800180import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700181import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700182import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700183import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700184import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800185import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800186import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700187import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000188import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700189import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700190import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800191import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800192import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800193import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700194import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000195import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800196import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700197import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800198import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700199import com.android.internal.telephony.imsphone.ImsPhone;
200import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000201import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800202import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800203import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
204import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700205import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700206import com.android.internal.telephony.uicc.IccIoResult;
207import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800208import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700209import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800210import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700211import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000212import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800213import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000214import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800215import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000216import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700217import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700218import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800219import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800220import com.android.phone.callcomposer.CallComposerPictureManager;
221import com.android.phone.callcomposer.CallComposerPictureTransfer;
222import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700223import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700224import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700225import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800226import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700227import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700228import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800229import com.android.services.telephony.TelecomAccountRegistry;
230import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800231import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800232
Hall Liu82694d52020-12-11 18:22:04 -0800233import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700234import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.io.IOException;
236import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700237import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800239import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000240import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800241import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800242import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800243import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800244import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100245import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700247import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800248import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800249import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700250import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800252import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800253import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
255/**
256 * Implementation of the ITelephony interface.
257 */
Santos Cordon117fee72014-05-16 17:56:12 -0700258public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 private static final String LOG_TAG = "PhoneInterfaceManager";
260 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
261 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800262 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700263
264 // Message codes used with mMainThreadHandler
265 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700266 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
267 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700268 private static final int CMD_OPEN_CHANNEL = 9;
269 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
270 private static final int CMD_CLOSE_CHANNEL = 11;
271 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800272 private static final int CMD_NV_READ_ITEM = 13;
273 private static final int EVENT_NV_READ_ITEM_DONE = 14;
274 private static final int CMD_NV_WRITE_ITEM = 15;
275 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
276 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
277 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700278 private static final int CMD_RESET_MODEM_CONFIG = 19;
279 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800280 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
281 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800282 private static final int CMD_SEND_ENVELOPE = 25;
283 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000284 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
285 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700286 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
287 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
288 private static final int CMD_EXCHANGE_SIM_IO = 31;
289 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800290 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
291 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700292 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
293 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700294 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
295 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700296 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
297 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
298 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
299 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700300 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
301 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
302 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
303 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700304 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800305 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
306 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000307 private static final int CMD_SWITCH_SLOTS = 50;
308 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700309 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
310 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
311 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
312 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
313 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
314 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
315 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
316 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700317 private static final int CMD_GET_ALL_CELL_INFO = 60;
318 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
319 private static final int CMD_GET_CELL_LOCATION = 62;
320 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700321 private static final int CMD_MODEM_REBOOT = 64;
322 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700323 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
324 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800325 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
326 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700327 private static final int CMD_GET_MODEM_STATUS = 70;
328 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700329 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
330 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700331 private static final int CMD_ERASE_MODEM_CONFIG = 74;
332 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800333 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
334 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
335 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
336 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800337 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
338 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800339 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800340 private static final int CMD_GET_CALL_FORWARDING = 83;
341 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
342 private static final int CMD_SET_CALL_FORWARDING = 85;
343 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
344 private static final int CMD_GET_CALL_WAITING = 87;
345 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
346 private static final int CMD_SET_CALL_WAITING = 89;
347 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700348 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
349 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
350 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
351 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700352 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
353 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800354 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
355 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800356 private static final int CMD_SET_DATA_THROTTLING = 99;
357 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800358 private static final int CMD_SET_SIM_POWER = 101;
359 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800360 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
361 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
362 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
363 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800364 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
365 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000366 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800367 private static final int CMD_GET_SLICING_CONFIG = 110;
368 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800369 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700370 private static final int CMD_ENABLE_VONR = 113;
371 private static final int EVENT_ENABLE_VONR_DONE = 114;
372 private static final int CMD_IS_VONR_ENABLED = 115;
373 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700374 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
375 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800377 // Parameters of select command.
378 private static final int SELECT_COMMAND = 0xA4;
379 private static final int SELECT_P1 = 0x04;
380 private static final int SELECT_P2 = 0;
381 private static final int SELECT_P3 = 0x10;
382
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000383 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
384 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 /** The singleton instance. */
387 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800388 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389
Wink Saville3ab207e2014-11-20 13:07:20 -0800390 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800391 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800392 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700393 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800394 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700395 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800396 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800397 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800398 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700399 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800400 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000401 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
Peter Wangdafb9ac2020-01-15 14:13:38 -0800403 /** User Activity */
404 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800405 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
406
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700407 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
408
Derek Tan97ebb422014-09-05 16:55:38 -0700409 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
410 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800411 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800412 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700413
Michelecea4cf22018-12-21 15:00:11 -0800414 // String to store multi SIM allowed
415 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
416
Derek Tan740e1672017-06-27 14:56:27 -0700417 // The AID of ISD-R.
418 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
419
yinxub1bed742017-04-17 11:45:04 -0700420 private NetworkScanRequestTracker mNetworkScanRequestTracker;
421
David Kelly5e06a7f2018-03-12 14:10:59 +0000422 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
423 private static final int MANUFACTURER_CODE_LENGTH = 8;
424
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800425 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800426 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800427
Sarah Chin2ec39f62022-08-31 17:03:26 -0700428 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
429 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
430
Derek Tan89e89d42014-07-08 17:00:10 -0700431 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700432 * Experiment flag to enable erase modem config on reset network, default value is false
433 */
434 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
435 "reset_network_erase_modem_config_enabled";
436
Rambo Wang0f050d82021-02-12 11:43:36 -0800437 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800438
sandeepjsb6c87872021-09-27 15:34:44 +0000439 /**
440 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
441 * one ICCID active at the same time.
442 * Apps should use below API signatures if targeting SDK is T and beyond.
443 *
444 * @hide
445 */
446 @ChangeId
447 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
448 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800449
Naina Nallurid63128d2019-09-17 14:10:30 -0700450 /**
Chen Xu540470b2021-12-14 17:15:47 -0800451 * Apps targeting on Android T and beyond will get exception whenever icc close channel
452 * operation fails.
453 */
454 @ChangeId
455 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
456 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
457
458 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 * A request object to use for transmitting data to an ICC.
460 */
461 private static final class IccAPDUArgument {
462 public int channel, cla, command, p1, p2, p3;
463 public String data;
464
465 public IccAPDUArgument(int channel, int cla, int command,
466 int p1, int p2, int p3, String data) {
467 this.channel = channel;
468 this.cla = cla;
469 this.command = command;
470 this.p1 = p1;
471 this.p2 = p2;
472 this.p3 = p3;
473 this.data = data;
474 }
475 }
476
477 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700478 * A request object to use for transmitting data to an ICC.
479 */
480 private static final class ManualNetworkSelectionArgument {
481 public OperatorInfo operatorInfo;
482 public boolean persistSelection;
483
484 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
485 this.operatorInfo = operatorInfo;
486 this.persistSelection = persistSelection;
487 }
488 }
489
Sarah Chin71b3a852022-09-28 15:54:19 -0700490 private static final class PurchasePremiumCapabilityArgument {
491 public @TelephonyManager.PremiumCapability int capability;
492 public @NonNull String appName;
493 public @NonNull IIntegerConsumer callback;
494
495 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
496 @NonNull String appName, @NonNull IIntegerConsumer callback) {
497 this.capability = capability;
498 this.appName = appName;
499 this.callback = callback;
500 }
501 }
502
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700503 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
505 * request after sending. The main thread will notify the request when it is complete.
506 */
507 private static final class MainThreadRequest {
508 /** The argument to use for the request */
509 public Object argument;
510 /** The result of the request that is run on the main thread */
511 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800512 // The subscriber id that this request applies to. Defaults to
513 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
514 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515
Nathan Harold92bed182018-10-12 18:16:49 -0700516 // In cases where subId is unavailable, the caller needs to specify the phone.
517 public Phone phone;
518
vagdeviaf9a5b92018-08-15 16:01:53 -0700519 public WorkSource workSource;
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 public MainThreadRequest(Object argument) {
522 this.argument = argument;
523 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800524
Nathan Harold92bed182018-10-12 18:16:49 -0700525 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
526 this.argument = argument;
527 if (phone != null) {
528 this.phone = phone;
529 }
530 this.workSource = workSource;
531 }
532
vagdeviaf9a5b92018-08-15 16:01:53 -0700533 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800534 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800535 if (subId != null) {
536 this.subId = subId;
537 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700538 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 }
541
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800542 private static final class IncomingThirdPartyCallArgs {
543 public final ComponentName component;
544 public final String callId;
545 public final String callerDisplayName;
546
547 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
548 String callerDisplayName) {
549 this.component = component;
550 this.callId = callId;
551 this.callerDisplayName = callerDisplayName;
552 }
553 }
554
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 /**
556 * A handler that processes messages on the main thread in the phone process. Since many
557 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
558 * inbound binder threads to the main thread in the phone process. The Binder thread
559 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
560 * on, which will be notified when the operation completes and will contain the result of the
561 * request.
562 *
563 * <p>If a MainThreadRequest object is provided in the msg.obj field,
564 * note that request.result must be set to something non-null for the calling thread to
565 * unblock.
566 */
567 private final class MainThreadHandler extends Handler {
568 @Override
569 public void handleMessage(Message msg) {
570 MainThreadRequest request;
571 Message onCompleted;
572 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000573 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800575 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576
577 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 case CMD_HANDLE_USSD_REQUEST: {
579 request = (MainThreadRequest) msg.obj;
580 final Phone phone = getPhoneFromRequest(request);
581 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800582 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700584
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 if (!isUssdApiAllowed(request.subId)) {
586 // Carrier does not support use of this API, return failure.
587 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
588 UssdResponse response = new UssdResponse(ussdRequest, null);
589 Bundle returnData = new Bundle();
590 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
591 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700592
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 request.result = true;
594 notifyRequester(request);
595 return;
596 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700597
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 try {
599 request.result = phone != null
600 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
601 } catch (CallStateException cse) {
602 request.result = false;
603 }
604 // Wake up the requesting thread
605 notifyRequester(request);
606 break;
pkanwar32d516d2016-10-14 19:37:38 -0700607 }
608
Yorke Lee716f67e2015-06-17 15:39:16 -0700609 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700610 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700611 final Phone phone = getPhoneFromRequest(request);
612 request.result = phone != null ?
613 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
614 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700615 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000623 uiccPort = getUiccPortFromRequest(request);
624 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800626 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800630 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000631 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800632 iccArgument.channel, iccArgument.cla, iccArgument.command,
633 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
634 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
641 if (ar.exception == null && ar.result != null) {
642 request.result = ar.result;
643 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800644 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 if (ar.result == null) {
646 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800647 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800649 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 } else {
651 loge("iccTransmitApduLogicalChannel: Unknown exception");
652 }
653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 break;
656
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
658 request = (MainThreadRequest) msg.obj;
659 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000660 uiccPort = getUiccPortFromRequest(request);
661 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800663 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 } else {
666 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000668 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800669 iccArgument.cla, iccArgument.command, iccArgument.p1,
670 iccArgument.p2,
671 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 }
673 break;
674
675 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result;
680 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800681 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 if (ar.result == null) {
683 loge("iccTransmitApduBasicChannel: Empty response");
684 } else if (ar.exception instanceof CommandException) {
685 loge("iccTransmitApduBasicChannel: CommandException: " +
686 ar.exception);
687 } else {
688 loge("iccTransmitApduBasicChannel: Unknown exception");
689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 break;
693
694 case CMD_EXCHANGE_SIM_IO:
695 request = (MainThreadRequest) msg.obj;
696 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000697 uiccPort = getUiccPortFromRequest(request);
698 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 } else {
703 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
704 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000705 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
707 iccArgument.data, onCompleted);
708 }
709 break;
710
711 case EVENT_EXCHANGE_SIM_IO_DONE:
712 ar = (AsyncResult) msg.obj;
713 request = (MainThreadRequest) ar.userObj;
714 if (ar.exception == null && ar.result != null) {
715 request.result = ar.result;
716 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 break;
721
Derek Tan4d5e5c12014-02-04 11:54:58 -0800722 case CMD_SEND_ENVELOPE:
723 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 uiccPort = getUiccPortFromRequest(request);
725 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800727 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800731 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800733 break;
734
735 case EVENT_SEND_ENVELOPE_DONE:
736 ar = (AsyncResult) msg.obj;
737 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700738 if (ar.exception == null && ar.result != null) {
739 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800740 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800741 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700742 if (ar.result == null) {
743 loge("sendEnvelopeWithStatus: Empty response");
744 } else if (ar.exception instanceof CommandException) {
745 loge("sendEnvelopeWithStatus: CommandException: " +
746 ar.exception);
747 } else {
748 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
749 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800750 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800752 break;
753
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 case CMD_OPEN_CHANNEL:
755 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000756 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800757 IccLogicalChannelRequest openChannelRequest =
758 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000759 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700760 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800761 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800762 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700763 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700764 } else {
765 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800766 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
767 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 break;
770
771 case EVENT_OPEN_CHANNEL_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700776 int[] result = (int[]) ar.result;
777 int channelId = result[0];
778 byte[] selectResponse = null;
779 if (result.length > 1) {
780 selectResponse = new byte[result.length - 1];
781 for (int i = 1; i < result.length; ++i) {
782 selectResponse[i - 1] = (byte) result[i];
783 }
784 }
785 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800786 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800787
788 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700789 if (uiccPort == null) {
790 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
791 } else {
792 IccLogicalChannelRequest channelRequest =
793 (IccLogicalChannelRequest) request.argument;
794 channelRequest.channel = channelId;
795 uiccPort.onLogicalChannelOpened(channelRequest);
796 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700797 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 if (ar.result == null) {
799 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700801 if (ar.exception != null) {
802 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
803 }
804
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700805 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700806 if (ar.exception instanceof CommandException) {
807 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800808 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700809 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700810 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700811 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700812 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700813 }
814 }
815 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800816 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700818 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700819 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700820 break;
821
822 case CMD_CLOSE_CHANNEL:
823 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000824 uiccPort = getUiccPortFromRequest(request);
825 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700826 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800827 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800828 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800829 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700830 } else {
831 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000832 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700833 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 break;
835
836 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null) {
840 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800841 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700842 if (uiccPort == null) {
843 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
844 } else {
845 final int channelId = (Integer) request.argument;
846 uiccPort.onLogicalChannelClosed(channelId);
847 }
Chen Xu540470b2021-12-14 17:15:47 -0800848 } else {
849 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800850 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800851 if (ar.exception instanceof CommandException) {
852 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
853 CommandException.Error error =
854 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800855 if (error == CommandException.Error.INVALID_ARGUMENTS) {
856 // should only throw exceptions from the binder threads.
857 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800858 "iccCloseLogicalChannel: invalid argument ");
859 }
860 } else {
861 loge("iccCloseLogicalChannel: Unknown exception");
862 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800863 request.result = (exception != null) ? exception :
864 new IllegalStateException(
865 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800866 }
867 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800868 break;
869
870 case CMD_NV_READ_ITEM:
871 request = (MainThreadRequest) msg.obj;
872 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800873 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
874 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800875 break;
876
877 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700882 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800883 request.result = "";
884 if (ar.result == null) {
885 loge("nvReadItem: Empty response");
886 } else if (ar.exception instanceof CommandException) {
887 loge("nvReadItem: CommandException: " +
888 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700889 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800890 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700891 }
892 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700893 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700894 break;
895
Jake Hambye994d462014-02-03 13:10:13 -0800896 case CMD_NV_WRITE_ITEM:
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
899 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800900 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700901 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800902 break;
903
904 case EVENT_NV_WRITE_ITEM_DONE:
905 handleNullReturnEvent(msg, "nvWriteItem");
906 break;
907
908 case CMD_NV_WRITE_CDMA_PRL:
909 request = (MainThreadRequest) msg.obj;
910 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800911 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
914 case EVENT_NV_WRITE_CDMA_PRL_DONE:
915 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
916 break;
917
chen xu6dac5ab2018-10-26 17:39:23 -0700918 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800919 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700920 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800922 break;
923
chen xu6dac5ab2018-10-26 17:39:23 -0700924 case EVENT_RESET_MODEM_CONFIG_DONE:
925 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800926 break;
927
Sooraj Sasindran37444802020-08-11 10:40:43 -0700928 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
929 request = (MainThreadRequest) msg.obj;
930 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
931 request);
932 Phone phone = getPhoneFromRequest(request);
933 if (phone != null) {
934 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
935 } else {
936 loge("isNRDualConnectivityEnabled: No phone object");
937 request.result = false;
938 notifyRequester(request);
939 }
940 break;
941 }
942
943 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 if (ar.exception == null && ar.result != null) {
947 request.result = ar.result;
948 } else {
949 // request.result must be set to something non-null
950 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700951 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700952 request.result = ar.result;
953 } else {
954 request.result = false;
955 }
956 if (ar.result == null) {
957 loge("isNRDualConnectivityEnabled: Empty response");
958 } else if (ar.exception instanceof CommandException) {
959 loge("isNRDualConnectivityEnabled: CommandException: "
960 + ar.exception);
961 } else {
962 loge("isNRDualConnectivityEnabled: Unknown exception");
963 }
964 }
965 notifyRequester(request);
966 break;
967
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700968 case CMD_IS_VONR_ENABLED: {
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
971 request);
972 Phone phone = getPhoneFromRequest(request);
973 if (phone != null) {
974 phone.isVoNrEnabled(onCompleted, request.workSource);
975 } else {
976 loge("isVoNrEnabled: No phone object");
977 request.result = false;
978 notifyRequester(request);
979 }
980 break;
981 }
982
983 case EVENT_IS_VONR_ENABLED_DONE:
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null && ar.result != null) {
987 request.result = ar.result;
988 } else {
989 // request.result must be set to something non-null
990 // for the calling thread to unblock
991 if (ar.result != null) {
992 request.result = ar.result;
993 } else {
994 request.result = false;
995 }
996 if (ar.result == null) {
997 loge("isVoNrEnabled: Empty response");
998 } else if (ar.exception instanceof CommandException) {
999 loge("isVoNrEnabled: CommandException: "
1000 + ar.exception);
1001 } else {
1002 loge("isVoNrEnabled: Unknown exception");
1003 }
1004 }
1005 notifyRequester(request);
1006 break;
1007
Sooraj Sasindran37444802020-08-11 10:40:43 -07001008 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1009 request = (MainThreadRequest) msg.obj;
1010 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1011 Phone phone = getPhoneFromRequest(request);
1012 if (phone != null) {
1013 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1014 request.workSource);
1015 } else {
1016 loge("enableNrDualConnectivity: No phone object");
1017 request.result =
1018 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1019 notifyRequester(request);
1020 }
1021 break;
1022 }
1023
1024 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception == null) {
1028 request.result =
1029 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1030 } else {
1031 request.result =
1032 TelephonyManager
1033 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1034 if (ar.exception instanceof CommandException) {
1035 CommandException.Error error =
1036 ((CommandException) (ar.exception)).getCommandError();
1037 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1038 request.result =
1039 TelephonyManager
1040 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001041 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1042 request.result =
1043 TelephonyManager
1044 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001045 }
1046 loge("enableNrDualConnectivity" + ": CommandException: "
1047 + ar.exception);
1048 } else {
1049 loge("enableNrDualConnectivity" + ": Unknown exception");
1050 }
1051 }
1052 notifyRequester(request);
1053 break;
1054 }
1055
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001056 case CMD_ENABLE_VONR: {
1057 request = (MainThreadRequest) msg.obj;
1058 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1059 Phone phone = getPhoneFromRequest(request);
1060 if (phone != null) {
1061 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1062 request.workSource);
1063 } else {
1064 loge("setVoNrEnabled: No phone object");
1065 request.result =
1066 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1067 notifyRequester(request);
1068 }
1069 break;
1070 }
1071
1072 case EVENT_ENABLE_VONR_DONE: {
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null) {
1076 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1077 } else {
1078 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1079 if (ar.exception instanceof CommandException) {
1080 CommandException.Error error =
1081 ((CommandException) (ar.exception)).getCommandError();
1082 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1083 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1084 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1085 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1086 } else {
1087 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1088 }
1089 loge("setVoNrEnabled" + ": CommandException: "
1090 + ar.exception);
1091 } else {
1092 loge("setVoNrEnabled" + ": Unknown exception");
1093 }
1094 }
1095 notifyRequester(request);
1096 break;
1097 }
1098
SongFerngWang3ef3e072020-12-21 16:41:52 +08001099 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001100 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001101 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1102 request);
1103 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001104 break;
1105
SongFerngWang3ef3e072020-12-21 16:41:52 +08001106 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null && ar.result != null) {
1110 request.result = ar.result; // Integer
1111 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301112 // request.result must be set to something non-null
1113 // for the calling thread to unblock
1114 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 loge("getAllowedNetworkTypesBitmask: CommandException: "
1119 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 }
1123 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001124 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001125 break;
1126
SongFerngWang3ef3e072020-12-21 16:41:52 +08001127 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1130 request);
1131 Pair<Integer, Long> reasonWithNetworkTypes =
1132 (Pair<Integer, Long>) request.argument;
1133 getPhoneFromRequest(request).setAllowedNetworkTypes(
1134 reasonWithNetworkTypes.first,
1135 reasonWithNetworkTypes.second,
1136 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 break;
1138
SongFerngWang3ef3e072020-12-21 16:41:52 +08001139 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1140 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 break;
1142
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001143 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1144 request = (MainThreadRequest)msg.obj;
1145 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001146 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001147 break;
1148
1149 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1150 ar = (AsyncResult)msg.obj;
1151 request = (MainThreadRequest)ar.userObj;
1152 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001153 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001154 break;
1155
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001156 case CMD_SET_VOICEMAIL_NUMBER:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1159 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001160 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1161 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001162 break;
1163
1164 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1165 handleNullReturnEvent(msg, "setVoicemailNumber");
1166 break;
1167
Stuart Scott54788802015-03-30 13:18:01 -07001168 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1169 request = (MainThreadRequest) msg.obj;
1170 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1171 request);
1172 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1173 break;
1174
1175 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1176 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1177 break;
1178
Shishir Agrawal302c8692015-06-19 13:49:39 -07001179 case CMD_PERFORM_NETWORK_SCAN:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1182 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1183 break;
1184
Hall Liu27d24262020-09-18 19:04:59 -07001185 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001188 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1189 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1190 request.argument;
1191 int callForwardingReason = args.first;
1192 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001193 break;
Hall Liu27d24262020-09-18 19:04:59 -07001194 }
1195 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001198 TelephonyManager.CallForwardingInfoCallback callback =
1199 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1200 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001202 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1204 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1205 // Service Class is a bit mask per 3gpp 27.007. Search for
1206 // any service for voice call.
1207 if ((callForwardInfo.serviceClass
1208 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001209 callForwardingInfo = new CallForwardingInfo(
1210 callForwardInfo.status
1211 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001212 callForwardInfo.reason,
1213 callForwardInfo.number,
1214 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001215 break;
1216 }
1217 }
1218 // Didn't find a call forward info for voice call.
1219 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001220 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1221 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001222 }
Hall Liu27d24262020-09-18 19:04:59 -07001223 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 } else {
1225 if (ar.result == null) {
1226 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1227 }
1228 if (ar.exception != null) {
1229 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1230 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 int errorCode = TelephonyManager
1232 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001233 if (ar.exception instanceof CommandException) {
1234 CommandException.Error error =
1235 ((CommandException) (ar.exception)).getCommandError();
1236 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 errorCode = TelephonyManager
1238 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager
1241 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001242 }
1243 }
Hall Liu27d24262020-09-18 19:04:59 -07001244 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 }
Shuo Qian4a594052020-01-23 11:59:30 -08001246 break;
Hall Liu27d24262020-09-18 19:04:59 -07001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248
Hall Liu27d24262020-09-18 19:04:59 -07001249 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001252 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001254 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1255 request.argument).first;
1256 request.phone.setCallForwardingOption(
1257 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001258 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001259 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001260 callForwardingInfoToSet.getReason(),
1261 callForwardingInfoToSet.getNumber(),
1262 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1263 break;
Hall Liu27d24262020-09-18 19:04:59 -07001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265
Hall Liu27d24262020-09-18 19:04:59 -07001266 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001269 Consumer<Integer> callback =
1270 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1271 request.argument).second;
1272 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001273 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001274 int errorCode = TelephonyManager.CallForwardingInfoCallback
1275 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001276 if (ar.exception instanceof CommandException) {
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001280 errorCode = TelephonyManager.CallForwardingInfoCallback
1281 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001282 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001283 errorCode = TelephonyManager.CallForwardingInfoCallback
1284 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
1286 }
1287 callback.accept(errorCode);
1288 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001290 }
Shuo Qian4a594052020-01-23 11:59:30 -08001291 break;
Hall Liu27d24262020-09-18 19:04:59 -07001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293
Hall Liu27d24262020-09-18 19:04:59 -07001294 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001295 request = (MainThreadRequest) msg.obj;
1296 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1297 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1298 break;
Hall Liu27d24262020-09-18 19:04:59 -07001299 }
Shuo Qian4a594052020-01-23 11:59:30 -08001300
Hall Liu27d24262020-09-18 19:04:59 -07001301 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001304 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001305 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001306 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001307 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 // Service Class is a bit mask per 3gpp 27.007.
1309 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001310 if (callForwardResults.length > 1
1311 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001312 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001313 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001314 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1315 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001316 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001317 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001318 }
1319 } else {
1320 if (ar.result == null) {
1321 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1322 }
1323 if (ar.exception != null) {
1324 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1325 }
1326 if (ar.exception instanceof CommandException) {
1327 CommandException.Error error =
1328 ((CommandException) (ar.exception)).getCommandError();
1329 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001331 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1333 callWaitingStatus =
1334 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001335 }
1336 }
1337 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001339 break;
Hall Liu27d24262020-09-18 19:04:59 -07001340 }
Shuo Qian4a594052020-01-23 11:59:30 -08001341
Hall Liu27d24262020-09-18 19:04:59 -07001342 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 request = (MainThreadRequest) msg.obj;
1344 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001345 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1346 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001347 break;
Hall Liu27d24262020-09-18 19:04:59 -07001348 }
Shuo Qian4a594052020-01-23 11:59:30 -08001349
Hall Liu27d24262020-09-18 19:04:59 -07001350 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001353 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1354 Consumer<Integer> callback =
1355 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1356 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001357 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001358 if (ar.exception instanceof CommandException) {
1359 CommandException.Error error =
1360 ((CommandException) (ar.exception)).getCommandError();
1361 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1362 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001363 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1364 callback.accept(
1365 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001366 } else {
1367 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1368 }
1369 } else {
1370 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1371 }
1372 } else {
1373 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1374 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001375 }
Shuo Qian4a594052020-01-23 11:59:30 -08001376 break;
Hall Liu27d24262020-09-18 19:04:59 -07001377 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001378 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
1381 CellNetworkScanResult cellScanResult;
1382 if (ar.exception == null && ar.result != null) {
1383 cellScanResult = new CellNetworkScanResult(
1384 CellNetworkScanResult.STATUS_SUCCESS,
1385 (List<OperatorInfo>) ar.result);
1386 } else {
1387 if (ar.result == null) {
1388 loge("getCellNetworkScanResults: Empty response");
1389 }
1390 if (ar.exception != null) {
1391 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1392 }
1393 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1394 if (ar.exception instanceof CommandException) {
1395 CommandException.Error error =
1396 ((CommandException) (ar.exception)).getCommandError();
1397 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1398 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1399 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1400 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1401 }
1402 }
1403 cellScanResult = new CellNetworkScanResult(errorCode, null);
1404 }
1405 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001406 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 break;
1408
1409 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1410 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001411 ManualNetworkSelectionArgument selArg =
1412 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001413 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1414 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001415 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1416 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001417 break;
1418
1419 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception == null) {
1423 request.result = true;
1424 } else {
1425 request.result = false;
1426 loge("setNetworkSelectionModeManual " + ar.exception);
1427 }
1428 notifyRequester(request);
1429 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 break;
1431
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 case CMD_GET_MODEM_ACTIVITY_INFO:
1433 request = (MainThreadRequest) msg.obj;
1434 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001435 if (defaultPhone != null) {
1436 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001437 } else {
1438 ResultReceiver result = (ResultReceiver) request.argument;
1439 Bundle bundle = new Bundle();
1440 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001441 new ModemActivityInfo(0, 0, 0,
1442 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001443 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001444 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001445 break;
1446
Hall Liud0f208c2020-10-14 16:54:44 -07001447 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001450 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001451 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001452 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001453 if (mLastModemActivityInfo == null) {
1454 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1455 mLastModemActivitySpecificInfo[0] =
1456 new ActivityStatsTechSpecificInfo(
1457 0,
1458 0,
1459 new int[ModemActivityInfo.getNumTxPowerLevels()],
1460 0);
1461 mLastModemActivityInfo =
1462 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1463 }
1464
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001465 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 // Update the last modem activity info and the result of the request.
1467 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1468 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001469 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001470 }
Kai Shi917fdc62022-11-28 14:01:02 -08001471 // This is needed to decouple ret from mLastModemActivityInfo
1472 // We don't want to return mLastModemActivityInfo which is updated
1473 // inside mergeModemActivityInfo()
1474 ret = new ModemActivityInfo(
1475 mLastModemActivityInfo.getTimestampMillis(),
1476 mLastModemActivityInfo.getSleepTimeMillis(),
1477 mLastModemActivityInfo.getIdleTimeMillis(),
1478 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001479
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001480 } else {
1481 if (ar.result == null) {
1482 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001483 error = TelephonyManager.ModemActivityInfoException
1484 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001485 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001486 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001487 error = TelephonyManager.ModemActivityInfoException
1488 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489 } else {
1490 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001491 error = TelephonyManager.ModemActivityInfoException
1492 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 }
1494 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001496 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001497 bundle.putParcelable(
1498 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001499 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001500 } else {
1501 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1502 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001503 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001504 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001506 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001507
Meng Wang1a7c35a2016-05-05 20:56:15 -07001508 case CMD_SET_ALLOWED_CARRIERS:
1509 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001510 CarrierRestrictionRules argument =
1511 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001513 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 break;
1515
1516 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1517 ar = (AsyncResult) msg.obj;
1518 request = (MainThreadRequest) ar.userObj;
1519 if (ar.exception == null && ar.result != null) {
1520 request.result = ar.result;
1521 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001522 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1523 if (ar.exception instanceof CommandException) {
1524 loge("setAllowedCarriers: CommandException: " + ar.exception);
1525 CommandException.Error error =
1526 ((CommandException) (ar.exception)).getCommandError();
1527 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1528 request.result =
1529 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1530 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531 } else {
1532 loge("setAllowedCarriers: Unknown exception");
1533 }
1534 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001535 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 break;
1537
1538 case CMD_GET_ALLOWED_CARRIERS:
1539 request = (MainThreadRequest) msg.obj;
1540 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001541 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 break;
1543
1544 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
1547 if (ar.exception == null && ar.result != null) {
1548 request.result = ar.result;
1549 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001550 request.result = new IllegalStateException(
1551 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001552 if (ar.result == null) {
1553 loge("getAllowedCarriers: Empty response");
1554 } else if (ar.exception instanceof CommandException) {
1555 loge("getAllowedCarriers: CommandException: " +
1556 ar.exception);
1557 } else {
1558 loge("getAllowedCarriers: Unknown exception");
1559 }
1560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001561 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 break;
1563
Nathan Haroldb3014052017-01-25 15:57:32 -08001564 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1565 ar = (AsyncResult) msg.obj;
1566 request = (MainThreadRequest) ar.userObj;
1567 if (ar.exception == null && ar.result != null) {
1568 request.result = ar.result;
1569 } else {
1570 request.result = new IllegalArgumentException(
1571 "Failed to retrieve Forbidden Plmns");
1572 if (ar.result == null) {
1573 loge("getForbiddenPlmns: Empty response");
1574 } else {
1575 loge("getForbiddenPlmns: Unknown exception");
1576 }
1577 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001578 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001579 break;
1580
1581 case CMD_GET_FORBIDDEN_PLMNS:
1582 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001583 uiccPort = getUiccPortFromRequest(request);
1584 if (uiccPort == null) {
1585 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001586 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001587 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001588 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001589 break;
1590 }
1591 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001592 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001593 if (uiccApp == null) {
1594 loge("getForbiddenPlmns() no app with specified type -- "
1595 + appType);
1596 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001597 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001598 break;
1599 } else {
1600 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1601 + " specified type -- " + appType);
1602 }
1603 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1604 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1605 onCompleted);
1606 break;
1607
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001608 case CMD_SWITCH_SLOTS:
1609 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001610 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001611 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001612 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001613 break;
1614
1615 case EVENT_SWITCH_SLOTS_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001619 notifyRequester(request);
1620 break;
1621 case CMD_GET_NETWORK_SELECTION_MODE:
1622 request = (MainThreadRequest) msg.obj;
1623 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1624 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1625 break;
1626
1627 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception != null) {
1631 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1632 } else {
1633 int mode = ((int[]) ar.result)[0];
1634 if (mode == 0) {
1635 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1636 } else {
1637 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1638 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001639 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 notifyRequester(request);
1641 break;
1642 case CMD_GET_CDMA_ROAMING_MODE:
1643 request = (MainThreadRequest) msg.obj;
1644 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1645 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1646 break;
1647 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 if (ar.exception != null) {
1651 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1652 } else {
1653 request.result = ((int[]) ar.result)[0];
1654 }
1655 notifyRequester(request);
1656 break;
1657 case CMD_SET_CDMA_ROAMING_MODE:
1658 request = (MainThreadRequest) msg.obj;
1659 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1660 int mode = (int) request.argument;
1661 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1662 break;
1663 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 request.result = ar.exception == null;
1667 notifyRequester(request);
1668 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001669 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1670 request = (MainThreadRequest) msg.obj;
1671 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1672 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1673 break;
1674 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 if (ar.exception != null) {
1678 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1679 } else {
1680 request.result = ((int[]) ar.result)[0];
1681 }
1682 notifyRequester(request);
1683 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1685 request = (MainThreadRequest) msg.obj;
1686 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1687 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001688 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1689 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001690 break;
1691 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1692 ar = (AsyncResult) msg.obj;
1693 request = (MainThreadRequest) ar.userObj;
1694 request.result = ar.exception == null;
1695 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001696 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 case CMD_GET_ALL_CELL_INFO:
1698 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001699 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001700 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001702 case EVENT_GET_ALL_CELL_INFO_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001705 // If a timeout occurs, the response will be null
1706 request.result = (ar.exception == null && ar.result != null)
1707 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001708 synchronized (request) {
1709 request.notifyAll();
1710 }
1711 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001712 case CMD_REQUEST_CELL_INFO_UPDATE:
1713 request = (MainThreadRequest) msg.obj;
1714 request.phone.requestCellInfoUpdate(request.workSource,
1715 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1716 break;
1717 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1718 ar = (AsyncResult) msg.obj;
1719 request = (MainThreadRequest) ar.userObj;
1720 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1721 try {
1722 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001723 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001724 cb.onError(
1725 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1726 ar.exception.getClass().getName(),
1727 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001728 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001729 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001730 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001731 } else {
1732 // use the result as returned
1733 cb.onCellInfo((List<CellInfo>) ar.result);
1734 }
1735 } catch (RemoteException re) {
1736 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1737 }
1738 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001739 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 request = (MainThreadRequest) msg.obj;
1741 WorkSource ws = (WorkSource) request.argument;
1742 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001743 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001744 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001745 }
1746 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 ar = (AsyncResult) msg.obj;
1748 request = (MainThreadRequest) ar.userObj;
1749 if (ar.exception == null) {
1750 request.result = ar.result;
1751 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001752 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001753 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001754 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001755 }
1756
1757 synchronized (request) {
1758 request.notifyAll();
1759 }
1760 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001761 }
chen xu6dac5ab2018-10-26 17:39:23 -07001762 case CMD_MODEM_REBOOT:
1763 request = (MainThreadRequest) msg.obj;
1764 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001765 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001766 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001767 case EVENT_CMD_MODEM_REBOOT_DONE:
1768 handleNullReturnEvent(msg, "rebootModem");
1769 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001770 case CMD_REQUEST_ENABLE_MODEM:
1771 request = (MainThreadRequest) msg.obj;
1772 boolean enable = (boolean) request.argument;
1773 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001774 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001775 PhoneConfigurationManager.getInstance()
1776 .enablePhone(request.phone, enable, onCompleted);
1777 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001778 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001779 ar = (AsyncResult) msg.obj;
1780 request = (MainThreadRequest) ar.userObj;
1781 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001782 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001783 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001784 if ((boolean) request.result) {
1785 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1786 updateModemStateMetrics();
1787 } else {
1788 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1789 + ar.exception);
1790 }
1791 notifyRequester(request);
1792 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001793 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001794 case CMD_GET_MODEM_STATUS:
1795 request = (MainThreadRequest) msg.obj;
1796 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1797 PhoneConfigurationManager.getInstance()
1798 .getPhoneStatusFromModem(request.phone, onCompleted);
1799 break;
1800 case EVENT_GET_MODEM_STATUS_DONE:
1801 ar = (AsyncResult) msg.obj;
1802 request = (MainThreadRequest) ar.userObj;
1803 int id = request.phone.getPhoneId();
1804 if (ar.exception == null && ar.result != null) {
1805 request.result = ar.result;
1806 //update the cache as modem status has changed
1807 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1808 (boolean) request.result);
1809 } else {
1810 // Return true if modem status cannot be retrieved. For most cases,
1811 // modem status is on. And for older version modems, GET_MODEM_STATUS
1812 // and disable modem are not supported. Modem is always on.
1813 // TODO: this should be fixed in R to support a third
1814 // status UNKNOWN b/131631629
1815 request.result = true;
1816 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1817 + ar.exception);
1818 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001819 notifyRequester(request);
1820 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001821 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1822 request = (MainThreadRequest) msg.obj;
1823 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1824 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1825 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1826 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1827 break;
1828 }
1829 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1833 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1834 args.second.accept(ar.exception == null);
1835 notifyRequester(request);
1836 break;
1837 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001838 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1839 request = (MainThreadRequest) msg.obj;
1840 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1841 Phone phone = getPhoneFromRequest(request);
1842 if (phone != null) {
1843 phone.getSystemSelectionChannels(onCompleted);
1844 } else {
1845 loge("getSystemSelectionChannels: No phone object");
1846 request.result = new ArrayList<RadioAccessSpecifier>();
1847 notifyRequester(request);
1848 }
1849 break;
1850 }
1851 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 if (ar.exception == null && ar.result != null) {
1855 request.result = ar.result;
1856 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001857 request.result = new IllegalStateException(
1858 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001859 if (ar.result == null) {
1860 loge("getSystemSelectionChannels: Empty response");
1861 } else {
1862 loge("getSystemSelectionChannels: Unknown exception");
1863 }
1864 }
1865 notifyRequester(request);
1866 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001867 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1868 ar = (AsyncResult) msg.obj;
1869 request = (MainThreadRequest) ar.userObj;
1870 if (ar.exception == null && ar.result != null) {
1871 request.result = ar.result;
1872 } else {
1873 request.result = -1;
1874 loge("Failed to set Forbidden Plmns");
1875 if (ar.result == null) {
1876 loge("setForbidenPlmns: Empty response");
1877 } else if (ar.exception != null) {
1878 loge("setForbiddenPlmns: Exception: " + ar.exception);
1879 request.result = -1;
1880 } else {
1881 loge("setForbiddenPlmns: Unknown exception");
1882 }
1883 }
1884 notifyRequester(request);
1885 break;
1886 case CMD_SET_FORBIDDEN_PLMNS:
1887 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001888 uiccPort = getUiccPortFromRequest(request);
1889 if (uiccPort == null) {
1890 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001891 request.result = -1;
1892 notifyRequester(request);
1893 break;
1894 }
1895 Pair<Integer, List<String>> setFplmnsArgs =
1896 (Pair<Integer, List<String>>) request.argument;
1897 appType = setFplmnsArgs.first;
1898 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001899 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001900 if (uiccApp == null) {
1901 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1902 request.result = -1;
1903 loge("Failed to get UICC App");
1904 notifyRequester(request);
1905 } else {
1906 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1907 ((SIMRecords) uiccApp.getIccRecords())
1908 .setForbiddenPlmns(onCompleted, fplmns);
1909 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001910 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001911 case CMD_ERASE_MODEM_CONFIG:
1912 request = (MainThreadRequest) msg.obj;
1913 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1914 defaultPhone.eraseModemConfig(onCompleted);
1915 break;
1916 case EVENT_ERASE_MODEM_CONFIG_DONE:
1917 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001918 break;
zoey chene02881a2019-12-30 16:11:23 +08001919
Kai Shif70f46f2021-03-03 13:59:46 -08001920 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1921 request = (MainThreadRequest) msg.obj;
1922 request.result = defaultPhone.eraseDataInSharedPreferences();
1923 notifyRequester(request);
1924 break;
1925
zoey chene02881a2019-12-30 16:11:23 +08001926 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1927 request = (MainThreadRequest) msg.obj;
1928 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1929 Pair<String, String> changed = (Pair<String, String>) request.argument;
1930 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1931 changed.first, changed.second, onCompleted);
1932 break;
1933 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1934 ar = (AsyncResult) msg.obj;
1935 request = (MainThreadRequest) ar.userObj;
1936 if (ar.exception == null) {
1937 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001938 // If the operation is successful, update the PIN storage
1939 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1940 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001941 UiccController.getInstance().getPinStorage()
1942 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001943 } else {
1944 request.result = msg.arg1;
1945 }
1946 notifyRequester(request);
1947 break;
1948
Michele Berionne5e411512020-11-13 02:36:59 +00001949 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001950 request = (MainThreadRequest) msg.obj;
1951 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1952 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1953 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1954 enabled.first, enabled.second, onCompleted);
1955 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001956 }
zoey chene02881a2019-12-30 16:11:23 +08001957 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1958 ar = (AsyncResult) msg.obj;
1959 request = (MainThreadRequest) ar.userObj;
1960 if (ar.exception == null) {
1961 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001962 // If the operation is successful, update the PIN storage
1963 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1964 int phoneId = getPhoneFromRequest(request).getPhoneId();
1965 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001966 UiccController.getInstance().getPinStorage()
1967 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001968 } else {
1969 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1970 }
zoey chene02881a2019-12-30 16:11:23 +08001971 } else {
1972 request.result = msg.arg1;
1973 }
Michele Berionne5e411512020-11-13 02:36:59 +00001974
1975
zoey chene02881a2019-12-30 16:11:23 +08001976 notifyRequester(request);
1977 break;
1978
Peter Wangdafb9ac2020-01-15 14:13:38 -08001979 case MSG_NOTIFY_USER_ACTIVITY:
1980 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001981 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001982 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1983 getDefaultPhone().getContext().sendBroadcastAsUser(
1984 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1985 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001986
1987 case CMD_SET_DATA_THROTTLING: {
1988 request = (MainThreadRequest) msg.obj;
1989 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1990 DataThrottlingRequest dataThrottlingRequest =
1991 (DataThrottlingRequest) request.argument;
1992 Phone phone = getPhoneFromRequest(request);
1993 if (phone != null) {
1994 phone.setDataThrottling(onCompleted,
1995 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1996 dataThrottlingRequest.getCompletionDurationMillis());
1997 } else {
1998 loge("setDataThrottling: No phone object");
1999 request.result =
2000 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2001 notifyRequester(request);
2002 }
2003
2004 break;
2005 }
2006 case EVENT_SET_DATA_THROTTLING_DONE:
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009
2010 if (ar.exception == null) {
2011 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2012 } else if (ar.exception instanceof CommandException) {
2013 loge("setDataThrottling: CommandException: " + ar.exception);
2014 CommandException.Error error =
2015 ((CommandException) (ar.exception)).getCommandError();
2016
2017 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2018 request.result = TelephonyManager
2019 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2020 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2021 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002022 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2023 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002024 } else {
2025 request.result =
2026 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2027 }
2028 } else {
2029 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2030 }
2031 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2032 notifyRequester(request);
2033 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002034
2035 case CMD_SET_SIM_POWER: {
2036 request = (MainThreadRequest) msg.obj;
2037 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2038 request = (MainThreadRequest) msg.obj;
2039 int stateToSet =
2040 ((Pair<Integer, IIntegerConsumer>)
2041 request.argument).first;
2042 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2043 break;
2044 }
2045 case EVENT_SET_SIM_POWER_DONE: {
2046 ar = (AsyncResult) msg.obj;
2047 request = (MainThreadRequest) ar.userObj;
2048 IIntegerConsumer callback =
2049 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2050 if (ar.exception != null) {
2051 loge("setSimPower exception: " + ar.exception);
2052 int errorCode = TelephonyManager.CallForwardingInfoCallback
2053 .RESULT_ERROR_UNKNOWN;
2054 if (ar.exception instanceof CommandException) {
2055 CommandException.Error error =
2056 ((CommandException) (ar.exception)).getCommandError();
2057 if (error == CommandException.Error.SIM_ERR) {
2058 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2059 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2060 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2061 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2062 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2063 } else {
2064 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2065 }
2066 }
2067 try {
2068 callback.accept(errorCode);
2069 } catch (RemoteException e) {
2070 // Ignore if the remote process is no longer available to call back.
2071 Log.w(LOG_TAG, "setSimPower: callback not available.");
2072 }
2073 } else {
2074 try {
2075 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2076 } catch (RemoteException e) {
2077 // Ignore if the remote process is no longer available to call back.
2078 Log.w(LOG_TAG, "setSimPower: callback not available.");
2079 }
2080 }
2081 break;
2082 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002083 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2084 request = (MainThreadRequest) msg.obj;
2085
2086 final Phone phone = getPhoneFromRequest(request);
2087 if (phone == null || phone.getServiceStateTracker() == null) {
2088 request.result = new IllegalStateException("Phone or SST is null");
2089 notifyRequester(request);
2090 break;
2091 }
2092
2093 Pair<Integer, SignalStrengthUpdateRequest> pair =
2094 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2095 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2096 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002097 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002098 request.subId, pair.first /*callingUid*/,
2099 pair.second /*request*/, onCompleted);
2100 break;
2101 }
2102 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2103 ar = (AsyncResult) msg.obj;
2104 request = (MainThreadRequest) ar.userObj;
2105 // request.result will be the exception of ar if present, true otherwise.
2106 // Be cautious not to leave result null which will wait() forever
2107 request.result = ar.exception != null ? ar.exception : true;
2108 notifyRequester(request);
2109 break;
2110 }
2111 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2112 request = (MainThreadRequest) msg.obj;
2113
2114 Phone phone = getPhoneFromRequest(request);
2115 if (phone == null || phone.getServiceStateTracker() == null) {
2116 request.result = new IllegalStateException("Phone or SST is null");
2117 notifyRequester(request);
2118 break;
2119 }
2120
2121 Pair<Integer, SignalStrengthUpdateRequest> pair =
2122 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2123 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2124 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002125 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002126 request.subId, pair.first /*callingUid*/,
2127 pair.second /*request*/, onCompleted);
2128 break;
2129 }
2130 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2131 ar = (AsyncResult) msg.obj;
2132 request = (MainThreadRequest) ar.userObj;
2133 request.result = ar.exception != null ? ar.exception : true;
2134 notifyRequester(request);
2135 break;
2136 }
Jordan Liu109698e2020-11-24 14:50:34 -08002137
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002138 case CMD_GET_SLICING_CONFIG: {
2139 request = (MainThreadRequest) msg.obj;
2140 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2141 request.phone.getSlicingConfig(onCompleted);
2142 break;
2143 }
2144 case EVENT_GET_SLICING_CONFIG_DONE: {
2145 ar = (AsyncResult) msg.obj;
2146 request = (MainThreadRequest) ar.userObj;
2147 ResultReceiver result = (ResultReceiver) request.argument;
2148
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002149 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002150 Bundle bundle = new Bundle();
2151 int resultCode = 0;
2152 if (ar.exception != null) {
2153 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2154 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002155 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002156 } else if (ar.result == null) {
2157 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002158 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002159 } else {
2160 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002161 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2162 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002163 }
2164
2165 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002166 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002167 }
2168 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2169 result.send(resultCode, bundle);
2170 notifyRequester(request);
2171 break;
2172 }
2173
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175 request = (MainThreadRequest) msg.obj;
2176 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002177 PurchasePremiumCapabilityArgument arg =
2178 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002179 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002180 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002181 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002182 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002183
Sarah Chin71b3a852022-09-28 15:54:19 -07002184 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002185 ar = (AsyncResult) msg.obj;
2186 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002187 PurchasePremiumCapabilityArgument arg =
2188 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002189 try {
2190 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002191 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002192 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002193 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002194 + ", result= "
2195 + TelephonyManager.convertPurchaseResultToString(result));
2196 } catch (RemoteException e) {
2197 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002198 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002199 + " failed: " + e;
2200 if (DBG) log(logStr);
2201 AnomalyReporter.reportAnomaly(
2202 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2203 }
2204 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002205 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002206
Michele Berionne5e411512020-11-13 02:36:59 +00002207 case CMD_PREPARE_UNATTENDED_REBOOT:
2208 request = (MainThreadRequest) msg.obj;
2209 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002210 UiccController.getInstance().getPinStorage()
2211 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002212 notifyRequester(request);
2213 break;
2214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 default:
2216 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2217 break;
2218 }
2219 }
Jake Hambye994d462014-02-03 13:10:13 -08002220
Pengquan Menga1bb6272018-09-06 09:59:22 -07002221 private void notifyRequester(MainThreadRequest request) {
2222 synchronized (request) {
2223 request.notifyAll();
2224 }
2225 }
2226
Jake Hambye994d462014-02-03 13:10:13 -08002227 private void handleNullReturnEvent(Message msg, String command) {
2228 AsyncResult ar = (AsyncResult) msg.obj;
2229 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2230 if (ar.exception == null) {
2231 request.result = true;
2232 } else {
2233 request.result = false;
2234 if (ar.exception instanceof CommandException) {
2235 loge(command + ": CommandException: " + ar.exception);
2236 } else {
2237 loge(command + ": Unknown exception");
2238 }
2239 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002240 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
2244 /**
2245 * Posts the specified command to be executed on the main thread,
2246 * waits for the request to complete, and returns the result.
2247 * @see #sendRequestAsync
2248 */
2249 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002250 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2251 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002252 }
2253
2254 /**
2255 * Posts the specified command to be executed on the main thread,
2256 * waits for the request to complete, and returns the result.
2257 * @see #sendRequestAsync
2258 */
2259 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2260 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002261 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002262 }
2263
2264 /**
2265 * Posts the specified command to be executed on the main thread,
2266 * waits for the request to complete, and returns the result.
2267 * @see #sendRequestAsync
2268 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002269 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002270 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2271 }
2272
2273 /**
2274 * Posts the specified command to be executed on the main thread,
2275 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2276 * if not timeout or null otherwise.
2277 * @see #sendRequestAsync
2278 */
2279 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2280 long timeoutInMs) {
2281 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002282 }
2283
2284 /**
2285 * Posts the specified command to be executed on the main thread,
2286 * waits for the request to complete, and returns the result.
2287 * @see #sendRequestAsync
2288 */
Nathan Harold92bed182018-10-12 18:16:49 -07002289 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002290 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002291 }
2292
2293 /**
2294 * Posts the specified command to be executed on the main thread,
2295 * waits for the request to complete, and returns the result.
2296 * @see #sendRequestAsync
2297 */
2298 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002299 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2300 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002301 }
2302
2303 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002304 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2305 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2306 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002307 * @see #sendRequestAsync
2308 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002309 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2310 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2312 throw new RuntimeException("This method will deadlock if called from the main thread.");
2313 }
2314
Nathan Harold92bed182018-10-12 18:16:49 -07002315 MainThreadRequest request = null;
2316 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2317 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2318 } else if (phone != null) {
2319 request = new MainThreadRequest(argument, phone, workSource);
2320 } else {
2321 request = new MainThreadRequest(argument, subId, workSource);
2322 }
2323
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 Message msg = mMainThreadHandler.obtainMessage(command, request);
2325 msg.sendToTarget();
2326
Rambo Wang0f050d82021-02-12 11:43:36 -08002327
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 if (timeoutInMs >= 0) {
2330 // Wait for at least timeoutInMs before returning null request result
2331 long now = SystemClock.elapsedRealtime();
2332 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002333 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002334 try {
2335 request.wait(deadline - now);
2336 } catch (InterruptedException e) {
2337 // Do nothing, go back and check if request is completed or timeout
2338 } finally {
2339 now = SystemClock.elapsedRealtime();
2340 }
2341 }
2342 } else {
2343 // Wait for the request to complete
2344 while (request.result == null) {
2345 try {
2346 request.wait();
2347 } catch (InterruptedException e) {
2348 // Do nothing, go back and wait until the request is complete
2349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 }
2351 }
2352 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002353 if (request.result == null) {
2354 Log.wtf(LOG_TAG,
2355 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 return request.result;
2358 }
2359
2360 /**
2361 * Asynchronous ("fire and forget") version of sendRequest():
2362 * Posts the specified command to be executed on the main thread, and
2363 * returns immediately.
2364 * @see #sendRequest
2365 */
2366 private void sendRequestAsync(int command) {
2367 mMainThreadHandler.sendEmptyMessage(command);
2368 }
2369
2370 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002371 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002372 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002373 */
2374 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002375 sendRequestAsync(command, argument, null, null);
2376 }
2377
2378 /**
2379 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2380 * @see {@link #sendRequest(int,Object)}
2381 */
2382 private void sendRequestAsync(
2383 int command, Object argument, Phone phone, WorkSource workSource) {
2384 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002385 Message msg = mMainThreadHandler.obtainMessage(command, request);
2386 msg.sendToTarget();
2387 }
2388
2389 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 * Initialize the singleton PhoneInterfaceManager instance.
2391 * This is only done once, at startup, from PhoneApp.onCreate().
2392 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002393 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 synchronized (PhoneInterfaceManager.class) {
2395 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002396 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 } else {
2398 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2399 }
2400 return sInstance;
2401 }
2402 }
2403
2404 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002405 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002408 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002409 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002411 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002413 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002414 mTelephonySharedPreferences =
2415 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002416 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002417 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002418 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002419 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002420 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002421 mTelephony2gUpdater = new Telephony2gUpdater(
2422 Executors.newSingleThreadExecutor(), mApp);
2423 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 publish();
2425 }
2426
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002427 @VisibleForTesting
2428 public SharedPreferences getSharedPreferences() {
2429 return mTelephonySharedPreferences;
2430 }
2431
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002432 private Phone getDefaultPhone() {
2433 Phone thePhone = getPhone(getDefaultSubscription());
2434 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2435 }
2436
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 private void publish() {
2438 if (DBG) log("publish: " + this);
2439
Peter Wangc035ce42020-01-08 21:00:22 -08002440 TelephonyFrameworkInitializer
2441 .getTelephonyServiceManager()
2442 .getTelephonyServiceRegisterer()
2443 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Stuart Scott584921c2015-01-15 17:10:34 -08002446 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002447 if (request.phone != null) {
2448 return request.phone;
2449 } else {
2450 return getPhoneFromSubId(request.subId);
2451 }
2452 }
2453
2454 private Phone getPhoneFromSubId(int subId) {
2455 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2456 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002457 }
2458
Rambo Wange53e07d2022-05-10 13:01:13 -07002459 @Nullable
2460 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002461 Phone phone = getPhoneFromRequest(request);
2462 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002463 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002464 }
2465
Wink Saville36469e72014-06-11 15:17:00 -07002466 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002467 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002468 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470
Kai Shif70f46f2021-03-03 13:59:46 -08002471 private void sendEraseModemConfig(@NonNull Phone phone) {
2472 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2473 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2474 }
2475
2476 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2477 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2478 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002479 }
2480
Peter Wang44b186e2020-01-13 23:33:09 -08002481 private boolean isImsAvailableOnDevice() {
2482 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2483 if (pm == null) {
2484 // For some reason package manger is not available.. This will fail internally anyway,
2485 // so do not throw error and allow.
2486 return true;
2487 }
2488 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2489 }
2490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002492 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002493 }
2494
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 if (DBG) log("dial: " + number);
2497 // No permission check needed here: This is just a wrapper around the
2498 // ACTION_DIAL intent, which is available to any app since it puts up
2499 // the UI before it does anything.
2500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 String url = createTelUrl(number);
2504 if (url == null) {
2505 return;
2506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 // PENDING: should we just silently fail if phone is offhook or ringing?
2509 PhoneConstants.State state = mCM.getState(subId);
2510 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2511 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2512 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2513 mApp.startActivity(intent);
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518 }
2519
2520 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002521 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002522 }
2523
Wink Savilleb564aae2014-10-23 10:18:09 -07002524 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 if (DBG) log("call: " + number);
2526
2527 // This is just a wrapper around the ACTION_CALL intent, but we still
2528 // need to do a permission check since we're calling startActivity()
2529 // from the context of the phone app.
2530 enforceCallPermission();
2531
Jordan Liu1617b712019-07-10 15:06:26 -07002532 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 != AppOpsManager.MODE_ALLOWED) {
2534 return;
2535 }
2536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 String url = createTelUrl(number);
2540 if (url == null) {
2541 return;
2542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544 boolean isValid = false;
2545 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2546 if (slist != null) {
2547 for (SubscriptionInfo subInfoRecord : slist) {
2548 if (subInfoRecord.getSubscriptionId() == subId) {
2549 isValid = true;
2550 break;
2551 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002552 }
Wink Saville08874612014-08-31 19:19:58 -07002553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 if (!isValid) {
2555 return;
2556 }
Wink Saville08874612014-08-31 19:19:58 -07002557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2559 intent.putExtra(SUBSCRIPTION_KEY, subId);
2560 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2561 mApp.startActivity(intent);
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 }
2566
Wink Savilleb564aae2014-10-23 10:18:09 -07002567 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002568 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002569 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2570 }
2571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002573 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002574 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2575 }
2576
Wink Savilleb564aae2014-10-23 10:18:09 -07002577 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579
2580 final long identity = Binder.clearCallingIdentity();
2581 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002582 Phone phone = getPhone(subId);
2583 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584 checkSimPin.start();
2585 return checkSimPin.unlockSim(null, pin);
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 }
2590
Wink Savilleb564aae2014-10-23 10:18:09 -07002591 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
2594 final long identity = Binder.clearCallingIdentity();
2595 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002596 Phone phone = getPhone(subId);
2597 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 checkSimPuk.start();
2599 return checkSimPuk.unlockSim(puk, pin);
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
2605 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002606 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 * a synchronous one.
2608 */
2609 private static class UnlockSim extends Thread {
2610
2611 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002612 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613
2614 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002615 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2616 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617
2618 // For replies from SimCard interface
2619 private Handler mHandler;
2620
2621 // For async handler to identify request type
2622 private static final int SUPPLY_PIN_COMPLETE = 100;
2623
Michele Berionne5e411512020-11-13 02:36:59 +00002624 UnlockSim(int phoneId, IccCard simCard) {
2625 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 mSimCard = simCard;
2627 }
2628
2629 @Override
2630 public void run() {
2631 Looper.prepare();
2632 synchronized (UnlockSim.this) {
2633 mHandler = new Handler() {
2634 @Override
2635 public void handleMessage(Message msg) {
2636 AsyncResult ar = (AsyncResult) msg.obj;
2637 switch (msg.what) {
2638 case SUPPLY_PIN_COMPLETE:
2639 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2640 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002641 mRetryCount = msg.arg1;
2642 if (ar.exception != null) {
2643 if (ar.exception instanceof CommandException &&
2644 ((CommandException)(ar.exception)).getCommandError()
2645 == CommandException.Error.PASSWORD_INCORRECT) {
2646 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002647 } //When UiccCardApp dispose,handle message and return exception
2648 else if (ar.exception instanceof CommandException &&
2649 ((CommandException) (ar.exception)).getCommandError()
2650 == CommandException.Error.ABORTED) {
2651 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002652 } else {
2653 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2654 }
2655 } else {
2656 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 mDone = true;
2659 UnlockSim.this.notifyAll();
2660 }
2661 break;
2662 }
2663 }
2664 };
2665 UnlockSim.this.notifyAll();
2666 }
2667 Looper.loop();
2668 }
2669
2670 /*
2671 * Use PIN or PUK to unlock SIM card
2672 *
2673 * If PUK is null, unlock SIM card with PIN
2674 *
2675 * If PUK is not null, unlock SIM card with PUK and set PIN code
2676 */
Wink Saville9de0f752013-10-22 19:04:03 -07002677 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678
2679 while (mHandler == null) {
2680 try {
2681 wait();
2682 } catch (InterruptedException e) {
2683 Thread.currentThread().interrupt();
2684 }
2685 }
2686 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2687
2688 if (puk == null) {
2689 mSimCard.supplyPin(pin, callback);
2690 } else {
2691 mSimCard.supplyPuk(puk, pin, callback);
2692 }
2693
2694 while (!mDone) {
2695 try {
2696 Log.d(LOG_TAG, "wait for done");
2697 wait();
2698 } catch (InterruptedException e) {
2699 // Restore the interrupted status
2700 Thread.currentThread().interrupt();
2701 }
2702 }
2703 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002704 int[] resultArray = new int[2];
2705 resultArray[0] = mResult;
2706 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002707
2708 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002709 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002710 }
2711
Wink Saville9de0f752013-10-22 19:04:03 -07002712 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 }
2714 }
2715
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002716 /**
2717 * This method has been removed due to privacy and stability concerns.
2718 */
2719 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002721 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2722 return;
Wink Saville36469e72014-06-11 15:17:00 -07002723 }
2724
Nathan Harold1f889d82020-06-04 17:05:26 -07002725 @Override
2726 public void updateServiceLocationWithPackageName(String callingPackage) {
2727 mApp.getSystemService(AppOpsManager.class)
2728 .checkPackage(Binder.getCallingUid(), callingPackage);
2729
Nathan Haroldf096d982020-11-18 17:18:06 -08002730 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002731 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2732 // Callers targeting S have no business invoking this method.
2733 return;
2734 }
2735
2736 LocationAccessPolicy.LocationPermissionResult locationResult =
2737 LocationAccessPolicy.checkLocationPermission(mApp,
2738 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2739 .setCallingPackage(callingPackage)
2740 .setCallingFeatureId(null)
2741 .setCallingPid(Binder.getCallingPid())
2742 .setCallingUid(Binder.getCallingUid())
2743 .setMethod("updateServiceLocation")
2744 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2745 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2746 .build());
2747 // Apps that lack location permission have no business calling this method;
2748 // however, because no permission was declared in the public API, denials must
2749 // all be "soft".
2750 switch (locationResult) {
2751 case DENIED_HARD: /* fall through */
2752 case DENIED_SOFT:
2753 return;
2754 }
2755
2756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002759 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002761 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762 }
2763 } finally {
2764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 }
2767
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002768 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002769 @Override
2770 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002771 return isRadioOnWithFeature(callingPackage, null);
2772 }
2773
2774
2775 @Override
2776 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2777 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2778 callingFeatureId);
2779 }
2780
2781 @Deprecated
2782 @Override
2783 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2784 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002785 }
2786
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002788 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2789 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002791 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002792 return false;
2793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 return isRadioOnForSubscriber(subId);
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002801 }
2802
2803 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 final Phone phone = getPhone(subId);
2807 if (phone != null) {
2808 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2809 } else {
2810 return false;
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
2817 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002818 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
Wink Saville36469e72014-06-11 15:17:00 -07002820
Wink Savilleb564aae2014-10-23 10:18:09 -07002821 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 final Phone phone = getPhone(subId);
2827 if (phone != null) {
2828 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002832 }
Wink Saville36469e72014-06-11 15:17:00 -07002833 }
2834
2835 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002836 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002837 }
2838
Wink Savilleb564aae2014-10-23 10:18:09 -07002839 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002840 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 final Phone phone = getPhone(subId);
2845 if (phone == null) {
2846 return false;
2847 }
2848 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2849 toggleRadioOnOffForSubscriber(subId);
2850 }
2851 return true;
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 }
Wink Saville36469e72014-06-11 15:17:00 -07002856
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002857 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002858 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002859 /*
2860 * If any of the Radios are available, it will need to be
2861 * shutdown. So return true if any Radio is available.
2862 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2866 Phone phone = PhoneFactory.getPhone(i);
2867 if (phone != null && phone.isRadioAvailable()) return true;
2868 }
2869 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2870 return false;
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002873 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002874 }
2875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002877 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 enforceModifyPermission();
2879
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2883 logv("Shutting down Phone " + i);
2884 shutdownRadioUsingPhoneId(i);
2885 }
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002888 }
2889 }
2890
2891 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002892 Phone phone = PhoneFactory.getPhone(phoneId);
2893 if (phone != null && phone.isRadioAvailable()) {
2894 phone.shutdownRadio();
2895 }
2896 }
2897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2904 if (defaultPhone != null) {
2905 defaultPhone.setRadioPower(turnOn);
2906 return true;
2907 } else {
2908 loge("There's no default phone.");
2909 return false;
2910 }
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002913 }
Wink Saville36469e72014-06-11 15:17:00 -07002914 }
2915
Wink Savilleb564aae2014-10-23 10:18:09 -07002916 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 final Phone phone = getPhone(subId);
2922 if (phone != null) {
2923 phone.setRadioPower(turnOn);
2924 return true;
2925 } else {
2926 return false;
2927 }
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002933 /**
2934 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2935 * no reason to power it off. When any of the voters want to power it off, it will be turned
2936 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2937 * powering it off, and these radio off votes will be cleared.
2938 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2939 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2940 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2941 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2942 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2943 * check its vote.
2944 *
2945 * @param subId The subscription ID.
2946 * @param reason The reason for powering off radio.
2947 * @return true on success and false on failure.
2948 */
2949 public boolean requestRadioPowerOffForReason(int subId,
2950 @TelephonyManager.RadioPowerReason int reason) {
2951 enforceModifyPermission();
2952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 final Phone phone = getPhone(subId);
2956 if (phone != null) {
2957 phone.setRadioPowerForReason(false, reason);
2958 return true;
2959 } else {
2960 return false;
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 }
2966
2967 /**
2968 * Remove the vote on powering off the radio for a reason, as requested by
2969 * {@link requestRadioPowerOffForReason}.
2970 *
2971 * @param subId The subscription ID.
2972 * @param reason The reason for powering off radio.
2973 * @return true on success and false on failure.
2974 */
2975 public boolean clearRadioPowerOffForReason(int subId,
2976 @TelephonyManager.RadioPowerReason int reason) {
2977 enforceModifyPermission();
2978
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 final Phone phone = getPhone(subId);
2982 if (phone != null) {
2983 phone.setRadioPowerForReason(true, reason);
2984 return true;
2985 } else {
2986 return false;
2987 }
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 }
2992
2993 /**
2994 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2995 *
2996 * @param subId The subscription ID.
2997 * @param callingPackage The package making the call.
2998 * @param callingFeatureId The feature in the package.
2999 * @return List of reasons for powering off radio.
3000 */
3001 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3002 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3003
3004 final long identity = Binder.clearCallingIdentity();
3005 List result = new ArrayList();
3006 try {
3007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3008 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3009 return result;
3010 }
3011
3012 final Phone phone = getPhone(subId);
3013 if (phone != null) {
3014 result.addAll(phone.getRadioPowerOffReasons());
3015 }
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
3019 return result;
3020 }
3021
Wink Saville36469e72014-06-11 15:17:00 -07003022 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003023 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003024 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
Jack Yu285100e2022-12-02 22:48:35 -08003029 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 final Phone phone = getPhone(subId);
3031 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003032 phone.getDataSettingsManager().setDataEnabled(
3033 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 return true;
3035 } else {
3036 return false;
3037 }
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 }
3042
Wink Saville36469e72014-06-11 15:17:00 -07003043 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003044 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003045 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
Jack Yu285100e2022-12-02 22:48:35 -08003050 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051 final Phone phone = getPhone(subId);
3052 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003053 phone.getDataSettingsManager().setDataEnabled(
3054 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 return true;
3056 } else {
3057 return false;
3058 }
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 }
3063
Sanket Padawe356d7632015-06-22 14:03:32 -07003064 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003065 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 final Phone phone = getPhone(subId);
3069 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003070 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 } else {
3072 return false;
3073 }
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077 }
3078
3079 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003080 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003081 }
3082
pkanwarae03a6b2016-11-06 20:37:09 -08003083 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 enforceCallPermission();
3085
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3089 return;
3090 }
3091 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3092 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
pkanwar32d516d2016-10-14 19:37:38 -07003096 };
3097
Wink Savilleb564aae2014-10-23 10:18:09 -07003098 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003100
3101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3104 return false;
3105 }
3106 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 }
3111
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003112 /**
3113 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3114 * tag on getCallState Binder call.
3115 */
3116 @Deprecated
3117 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003119 if (CompatChanges.isChangeEnabled(
3120 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3121 Binder.getCallingUid())) {
3122 // Do not allow this API to be called on API version 31+, it should only be
3123 // called on old apps using this Binder call directly.
3124 throw new SecurityException("This method can only be used for applications "
3125 + "targeting API version 30 or less.");
3126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 final long identity = Binder.clearCallingIdentity();
3128 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003129 Phone phone = getPhone(getDefaultSubscription());
3130 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3131 PhoneConstantConversions.convertCallState(phone.getState());
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
3138 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3139 if (CompatChanges.isChangeEnabled(
3140 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3141 Binder.getCallingUid())) {
3142 // Check READ_PHONE_STATE for API version 31+
3143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3144 featureId, "getCallStateForSubscription")) {
3145 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3146 + "targeting API level 31+.");
3147 }
3148 }
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3153 PhoneConstantConversions.convertCallState(phone.getState());
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003160 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003161 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003162 }
3163
3164 @Override
3165 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003168 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003170 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 } else {
3172 return PhoneConstantConversions.convertDataState(
3173 PhoneConstants.DataState.DISCONNECTED);
3174 }
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 }
3179
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003181 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003182 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003183 }
3184
3185 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003186 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003189 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003191 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 } else {
3193 return TelephonyManager.DATA_ACTIVITY_NONE;
3194 }
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199
3200 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003201 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003202 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003203 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003204
3205 LocationAccessPolicy.LocationPermissionResult locationResult =
3206 LocationAccessPolicy.checkLocationPermission(mApp,
3207 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3208 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003209 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003210 .setCallingPid(Binder.getCallingPid())
3211 .setCallingUid(Binder.getCallingUid())
3212 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003213 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003214 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3215 .build());
3216 switch (locationResult) {
3217 case DENIED_HARD:
3218 throw new SecurityException("Not allowed to access cell location");
3219 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003220 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3221 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 }
3223
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003228 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003229 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
Svetoslav64fad262015-04-14 14:35:21 -07003233 }
3234
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003236 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003237 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3238 // registered cell info, so return a NULL country instead.
3239 final long identity = Binder.clearCallingIdentity();
3240 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003241 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3242 // Get default phone in this case.
3243 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3244 }
Jack Yu285100e2022-12-02 22:48:35 -08003245 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003247 if (phone == null) return "";
3248 ServiceStateTracker sst = phone.getServiceStateTracker();
3249 if (sst == null) return "";
3250 LocaleTracker lt = sst.getLocaleTracker();
3251 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003252 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003256 }
3257
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003258 /**
3259 * This method was removed due to potential issues caused by performing partial
3260 * updates of service state, and lack of a credible use case.
3261 *
3262 * This has the ability to break the telephony implementation by disabling notification of
3263 * changes in device connectivity. DO NOT USE THIS!
3264 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003265 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 public void enableLocationUpdates() {
3267 mApp.enforceCallingOrSelfPermission(
3268 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003269 }
3270
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003271 /**
3272 * This method was removed due to potential issues caused by performing partial
3273 * updates of service state, and lack of a credible use case.
3274 *
3275 * This has the ability to break the telephony implementation by disabling notification of
3276 * changes in device connectivity. DO NOT USE THIS!
3277 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 @Override
3279 public void disableLocationUpdates() {
3280 mApp.enforceCallingOrSelfPermission(
3281 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 }
3283
3284 @Override
3285 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003286 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3287 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003288 try {
3289 mApp.getSystemService(AppOpsManager.class)
3290 .checkPackage(Binder.getCallingUid(), callingPackage);
3291 } catch (SecurityException e) {
3292 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3293 throw e;
3294 }
3295
Nathan Haroldf096d982020-11-18 17:18:06 -08003296 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003297 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3298 throw new SecurityException(
3299 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3300 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003301
Jordan Liu1617b712019-07-10 15:06:26 -07003302 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003303 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3304 return null;
3305 }
Svetoslav64fad262015-04-14 14:35:21 -07003306
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003307 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003309 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003310 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003311
Nathan Haroldf180aac2018-06-01 18:43:55 -07003312 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3313 for (CellInfo ci : info) {
3314 if (ci instanceof CellInfoGsm) {
3315 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3316 } else if (ci instanceof CellInfoWcdma) {
3317 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003319 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003320 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 }
3322
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003323 private List<CellInfo> getCachedCellInfo() {
3324 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3325 for (Phone phone : PhoneFactory.getPhones()) {
3326 List<CellInfo> info = phone.getAllCellInfo();
3327 if (info != null) cellInfos.addAll(info);
3328 }
3329 return cellInfos;
3330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331
3332 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003333 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003335 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003336
3337 LocationAccessPolicy.LocationPermissionResult locationResult =
3338 LocationAccessPolicy.checkLocationPermission(mApp,
3339 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3340 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003341 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003342 .setCallingPid(Binder.getCallingPid())
3343 .setCallingUid(Binder.getCallingUid())
3344 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003345 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003346 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3347 .build());
3348 switch (locationResult) {
3349 case DENIED_HARD:
3350 throw new SecurityException("Not allowed to access cell info");
3351 case DENIED_SOFT:
3352 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 }
3354
Nathan Haroldf096d982020-11-18 17:18:06 -08003355 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003356 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3357 return getCachedCellInfo();
3358 }
3359
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003360 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003361 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3365 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003366 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003367 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003368 if (info != null) cellInfos.addAll(info);
3369 }
3370 return cellInfos;
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003373 }
3374 }
3375
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003376 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003377 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3378 String callingFeatureId) {
3379 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3380 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003381 }
3382
3383 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003384 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3385 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003386 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003387 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003388 }
3389
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003390 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3391 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003392 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003393 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003394
3395 LocationAccessPolicy.LocationPermissionResult locationResult =
3396 LocationAccessPolicy.checkLocationPermission(mApp,
3397 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3398 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003399 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003400 .setCallingPid(Binder.getCallingPid())
3401 .setCallingUid(Binder.getCallingUid())
3402 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003403 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3404 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003405 .build());
3406 switch (locationResult) {
3407 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003408 if (TelephonyPermissions
3409 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003410 // Safetynet logging for b/154934934
3411 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3412 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003413 throw new SecurityException("Not allowed to access cell info");
3414 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003415 if (TelephonyPermissions
3416 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003417 // Safetynet logging for b/154934934
3418 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3419 }
Nathan Harold5320c422019-05-09 10:26:08 -07003420 try {
3421 cb.onCellInfo(new ArrayList<CellInfo>());
3422 } catch (RemoteException re) {
3423 // Drop without consequences
3424 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003425 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003426 }
3427
Nathan Harolda939a962019-05-09 10:13:47 -07003428
3429 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003430 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3431
3432 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3433 }
3434
3435 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003436 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003437 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003442 Phone phone = getPhone(subId);
3443 if (phone == null) {
3444 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3445 } else {
3446 phone.setCellInfoListRate(rateInMillis, workSource);
3447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 }
3452
Shishir Agrawala9f32182016-04-12 12:00:16 -07003453 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003454 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003455 Phone phone = PhoneFactory.getPhone(slotIndex);
3456 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003457 return null;
3458 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003459 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003460 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003461 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003462 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003463 return null;
3464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 return phone.getImei();
3469 } finally {
3470 Binder.restoreCallingIdentity(identity);
3471 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003472 }
3473
3474 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003475 public String getTypeAllocationCodeForSlot(int slotIndex) {
3476 Phone phone = PhoneFactory.getPhone(slotIndex);
3477 String tac = null;
3478 if (phone != null) {
3479 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003480 try {
3481 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3482 } catch (IndexOutOfBoundsException e) {
3483 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3484 return null;
3485 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003486 }
3487 return tac;
3488 }
3489
3490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003491 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003492 try {
3493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3494 } catch (SecurityException se) {
3495 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3496 throw new SecurityException("Package " + callingPackage + " does not belong to "
3497 + Binder.getCallingUid());
3498 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003499 Phone phone = PhoneFactory.getPhone(slotIndex);
3500 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003501 return null;
3502 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003503
Jeff Davidson913390f2018-02-23 17:11:49 -08003504 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003505 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003506 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003507 return null;
3508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 return phone.getMeid();
3513 } finally {
3514 Binder.restoreCallingIdentity(identity);
3515 }
Jack Yu2af8d712017-03-15 17:14:14 -07003516 }
3517
3518 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003519 public String getManufacturerCodeForSlot(int slotIndex) {
3520 Phone phone = PhoneFactory.getPhone(slotIndex);
3521 String manufacturerCode = null;
3522 if (phone != null) {
3523 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003524 try {
3525 manufacturerCode =
3526 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3527 } catch (IndexOutOfBoundsException e) {
3528 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3529 return null;
3530 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003531 }
3532 return manufacturerCode;
3533 }
3534
3535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3537 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003538 Phone phone = PhoneFactory.getPhone(slotIndex);
3539 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003540 return null;
3541 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003542 int subId = phone.getSubId();
3543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 mApp, subId, callingPackage, callingFeatureId,
3545 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003546 return null;
3547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 return phone.getDeviceSvn();
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003555 }
3556
fionaxu43304da2017-11-27 22:51:16 -08003557 @Override
3558 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 final Phone phone = getPhone(subId);
3562 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
fionaxu43304da2017-11-27 22:51:16 -08003566 }
3567
3568 @Override
3569 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 final Phone phone = getPhone(subId);
3573 return phone == null ? null : phone.getCarrierName();
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
fionaxu43304da2017-11-27 22:51:16 -08003577 }
3578
calvinpanffe225e2018-11-01 19:43:06 +08003579 @Override
chen xu0026ca62019-03-06 15:28:50 -08003580 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 final Phone phone = getPhone(subId);
3584 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003585 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
3589 }
3590
3591 @Override
chen xu0026ca62019-03-06 15:28:50 -08003592 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003596 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
3600 }
3601
chen xu651eec72018-11-11 19:03:44 -08003602 @Override
chen xu864e11c2018-12-06 22:10:03 -08003603 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3604 if (!isSubscriptionMccMnc) {
3605 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3606 }
chen xu651eec72018-11-11 19:03:44 -08003607 final Phone phone = PhoneFactory.getPhone(slotIndex);
3608 if (phone == null) {
3609 return TelephonyManager.UNKNOWN_CARRIER_ID;
3610 }
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003619 //
3620 // Internal helper methods.
3621 //
3622
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003623 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003624 * Make sure the caller is the calling package itself
3625 *
3626 * @throws SecurityException if the caller is not the calling package
3627 */
3628 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3629 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003630 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3631 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003632 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003633 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003634 } catch (PackageManager.NameNotFoundException e) {
3635 // packageUid is -1
3636 }
3637 if (packageUid != callingUid) {
3638 throw new SecurityException(message + ": Package " + callingPackage
3639 + " does not belong to " + callingUid);
3640 }
3641 }
3642
3643 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3645 *
3646 * @throws SecurityException if the caller does not have the required permission
3647 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003648 @VisibleForTesting
3649 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003650 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3651 }
3652
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003653 /**
3654 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3655 *
3656 * @throws SecurityException if the caller does not have the required permission
3657 */
3658 @VisibleForTesting
3659 public void enforceReadPermission() {
3660 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
3661 }
3662
Shuo Qian3b6ee772019-11-13 17:43:31 -08003663 private void enforceActiveEmergencySessionPermission() {
3664 mApp.enforceCallingOrSelfPermission(
3665 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3666 }
3667
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003668 /**
3669 * Make sure the caller has the CALL_PHONE permission.
3670 *
3671 * @throws SecurityException if the caller does not have the required permission
3672 */
3673 private void enforceCallPermission() {
3674 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3675 }
3676
paulhu5a773602019-08-23 19:17:33 +08003677 private void enforceSettingsPermission() {
3678 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003679 }
3680
Michele Berionne5e411512020-11-13 02:36:59 +00003681 private void enforceRebootPermission() {
3682 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3683 }
3684
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003685 private String createTelUrl(String number) {
3686 if (TextUtils.isEmpty(number)) {
3687 return null;
3688 }
3689
Jake Hambye994d462014-02-03 13:10:13 -08003690 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003691 }
3692
Ihab Awadf9e92732013-12-05 18:02:52 -08003693 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003694 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3695 }
3696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003697 private static void logv(String msg) {
3698 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3699 }
3700
Ihab Awadf9e92732013-12-05 18:02:52 -08003701 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003702 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3703 }
3704
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003705 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003706 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003707 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003708 }
3709
Sanket Padawe356d7632015-06-22 14:03:32 -07003710 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003711 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 final Phone phone = PhoneFactory.getPhone(slotIndex);
3715 if (phone == null) {
3716 return PhoneConstants.PHONE_TYPE_NONE;
3717 } else {
3718 return phone.getPhoneType();
3719 }
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003723 }
3724
3725 /**
3726 * Returns the CDMA ERI icon index to display
3727 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003729 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3730 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3731 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003732 }
3733
Sanket Padawe356d7632015-06-22 14:03:32 -07003734 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003735 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3736 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003737 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003738 mApp, subId, callingPackage, callingFeatureId,
3739 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003740 return -1;
3741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 final Phone phone = getPhone(subId);
3746 if (phone != null) {
3747 return phone.getCdmaEriIconIndex();
3748 } else {
3749 return -1;
3750 }
3751 } finally {
3752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003754 }
3755
3756 /**
3757 * Returns the CDMA ERI icon mode,
3758 * 0 - ON
3759 * 1 - FLASHING
3760 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003762 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3763 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3764 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003765 }
3766
Sanket Padawe356d7632015-06-22 14:03:32 -07003767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003768 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3769 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003771 mApp, subId, callingPackage, callingFeatureId,
3772 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003773 return -1;
3774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775
3776 final long identity = Binder.clearCallingIdentity();
3777 try {
3778 final Phone phone = getPhone(subId);
3779 if (phone != null) {
3780 return phone.getCdmaEriIconMode();
3781 } else {
3782 return -1;
3783 }
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003787 }
3788
3789 /**
3790 * Returns the CDMA ERI text,
3791 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003792 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003793 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3794 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3795 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003796 }
3797
Sanket Padawe356d7632015-06-22 14:03:32 -07003798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003799 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3800 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003802 mApp, subId, callingPackage, callingFeatureId,
3803 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003804 return null;
3805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
3810 if (phone != null) {
3811 return phone.getCdmaEriText();
3812 } else {
3813 return null;
3814 }
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003818 }
3819
3820 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003821 * Returns the CDMA MDN.
3822 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003824 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3826 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827
3828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003831 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 return phone.getLine1Number();
3833 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003834 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 return null;
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003839 }
3840 }
3841
3842 /**
3843 * Returns the CDMA MIN.
3844 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003845 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003846 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3848 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849
3850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
3853 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3854 return phone.getCdmaMin();
3855 } else {
3856 return null;
3857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003860 }
3861 }
3862
Hall Liud892bec2018-11-30 14:51:45 -08003863 @Override
3864 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3865 INumberVerificationCallback callback, String callingPackage) {
3866 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3867 != PERMISSION_GRANTED) {
3868 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3869 }
3870 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3871
3872 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3873 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003874 throw new SecurityException("Calling package must be configured in the device config: "
3875 + "calling package: " + callingPackage
3876 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003877 }
3878
3879 if (range == null) {
3880 throw new NullPointerException("Range must be non-null");
3881 }
3882
3883 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003884 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003885
3886 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3887 }
3888
Junda Liuca05d5d2014-08-14 22:36:34 -07003889 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003890 * Returns true if CDMA provisioning needs to run.
3891 */
3892 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 final long identity = Binder.clearCallingIdentity();
3894 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003895 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 } finally {
3897 Binder.restoreCallingIdentity(identity);
3898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003899 }
3900
3901 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003902 * Sets the voice mail number of a given subId.
3903 */
3904 @Override
3905 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003906 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3907 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908
3909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3912 new Pair<String, String>(alphaTag, number), new Integer(subId));
3913 return success;
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
3916 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003917 }
3918
Ta-wei Yen87c49842016-05-13 21:19:52 -07003919 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003920 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3921 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003922 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3923 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003924 if (!TextUtils.equals(callingPackage, systemDialer)) {
3925 throw new SecurityException("caller must be system dialer");
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3931 if (phoneAccountHandle == null) {
3932 return null;
3933 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003934 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 } finally {
3936 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003937 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003938 }
3939
3940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003941 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3942 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003945 mApp, subId, callingPackage, callingFeatureId,
3946 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003947 return null;
3948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003950 final long identity = Binder.clearCallingIdentity();
3951 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003953 } finally {
3954 Binder.restoreCallingIdentity(identity);
3955 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003956 }
3957
3958 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003959 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3960 VisualVoicemailSmsFilterSettings settings) {
3961 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962
3963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003966 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003970 }
3971
3972 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003973 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975
3976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003979 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003983 }
3984
3985 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003986 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3987 String callingPackage, int subId) {
3988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003993 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 } finally {
3995 Binder.restoreCallingIdentity(identity);
3996 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003997 }
3998
3999 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004000 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004006 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004010 }
4011
4012 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004013 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4014 String callingAttributionTag, int subId, String number, int port, String text,
4015 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004017 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004018 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004019 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004020 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4021 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004022 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004023
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004024 /**
fionaxu0152e512016-11-14 13:36:14 -08004025 * Sets the voice activation state of a given subId.
4026 */
4027 @Override
4028 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4030 mApp, subId, "setVoiceActivationState");
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.setVoiceActivationState(activationState);
4037 } else {
4038 loge("setVoiceActivationState fails with invalid subId: " + subId);
4039 }
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004042 }
4043 }
4044
4045 /**
4046 * Sets the data activation state of a given subId.
4047 */
4048 @Override
4049 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4051 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 final Phone phone = getPhone(subId);
4056 if (phone != null) {
4057 phone.setDataActivationState(activationState);
4058 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004059 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060 }
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004063 }
4064 }
4065
4066 /**
4067 * Returns the voice activation state of a given subId.
4068 */
4069 @Override
4070 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072
fionaxu0152e512016-11-14 13:36:14 -08004073 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 if (phone != null) {
4077 return phone.getVoiceActivationState();
4078 } else {
4079 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4080 }
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004083 }
4084 }
4085
4086 /**
4087 * Returns the data activation state of a given subId.
4088 */
4089 @Override
4090 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092
fionaxu0152e512016-11-14 13:36:14 -08004093 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 if (phone != null) {
4097 return phone.getDataActivationState();
4098 } else {
4099 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4100 }
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004103 }
4104 }
4105
4106 /**
Wink Saville36469e72014-06-11 15:17:00 -07004107 * Returns the unread count of voicemails for a subId
4108 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004109 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004110 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4111 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004113 mApp, subId, callingPackage, callingFeatureId,
4114 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004115 return 0;
4116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 final Phone phone = getPhone(subId);
4120 if (phone != null) {
4121 return phone.getVoiceMessageCount();
4122 } else {
4123 return 0;
4124 }
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004128 }
4129
4130 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004131 * returns true, if the device is in a state where both voice and data
4132 * are supported simultaneously. This can change based on location or network condition.
4133 */
4134 @Override
4135 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 final Phone phone = getPhone(subId);
4139 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004143 }
4144
4145 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004146 * Send the dialer code if called from the current default dialer or the caller has
4147 * carrier privilege.
4148 * @param inputCode The dialer code to send
4149 */
4150 @Override
4151 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004152 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004153 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004154 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4155 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004156 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004157 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004158 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004163 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
fionaxu235cc5e2017-03-06 22:25:57 -08004167 }
4168
Pengquan Menga1bb6272018-09-06 09:59:22 -07004169 @Override
4170 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004171 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004172 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004173 mApp, subId, "getNetworkSelectionMode");
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 if (!isActiveSubscription(subId)) {
4177 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4178 }
4179 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004182 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004183 }
4184
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004186 public boolean isInEmergencySmsMode() {
4187 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 for (Phone phone : PhoneFactory.getPhones()) {
4191 if (phone.isInEmergencySmsMode()) {
4192 return true;
4193 }
4194 }
4195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
4198 return false;
4199 }
4200
shilu366312e2019-12-17 09:28:10 -08004201 /**
4202 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4203 * @param subId The subscription to use to check the configuration.
4204 * @param c The callback that will be used to send the result.
4205 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004206 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004207 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4208 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004209 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004210 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004211
4212 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4213 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4214 "IMS not available on device.");
4215 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 final long token = Binder.clearCallingIdentity();
4217 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004218 int slotId = getSlotIndexOrException(subId);
4219 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004220
4221 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4222 if (controller != null) {
4223 ImsManager imsManager = controller.getImsManager(subId);
4224 if (imsManager != null) {
4225 imsManager.addRegistrationCallbackForSubscription(c, subId);
4226 } else {
4227 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4228 }
4229 } else {
4230 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4231 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004232 } catch (ImsException e) {
4233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 } finally {
4235 Binder.restoreCallingIdentity(token);
4236 }
4237 }
4238
shilu366312e2019-12-17 09:28:10 -08004239 /**
4240 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4241 * @param subId The subscription to use to check the configuration.
4242 * @param c The callback that will be used to send the result.
4243 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004245 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004246 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004247 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004248 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4249 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4250 }
Meng Wangafbc5852019-09-19 17:37:13 -07004251 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004252
Meng Wangafbc5852019-09-19 17:37:13 -07004253 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004254 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4255 if (controller != null) {
4256 ImsManager imsManager = controller.getImsManager(subId);
4257 if (imsManager != null) {
4258 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4259 } else {
4260 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4261 + "is inactive, ignoring unregister.");
4262 // If the ImsManager is not valid, just return, since the callback
4263 // will already have been removed internally.
4264 }
4265 }
Meng Wangafbc5852019-09-19 17:37:13 -07004266 } finally {
4267 Binder.restoreCallingIdentity(token);
4268 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 }
4270
Brad Ebingera34a6c22019-10-22 17:36:18 -07004271 /**
4272 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4273 */
4274 @Override
4275 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4276 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4277 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4278 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4279 "IMS not available on device.");
4280 }
4281 final long token = Binder.clearCallingIdentity();
4282 try {
4283 Phone phone = getPhone(subId);
4284 if (phone == null) {
4285 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4286 + subId + "'");
4287 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4288 }
4289 phone.getImsRegistrationState(regState -> {
4290 try {
4291 consumer.accept((regState == null)
4292 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4293 } catch (RemoteException e) {
4294 // Ignore if the remote process is no longer available to call back.
4295 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4296 }
4297 });
4298 } finally {
4299 Binder.restoreCallingIdentity(token);
4300 }
4301 }
4302
4303 /**
4304 * Get the transport type for the IMS service registration state.
4305 */
4306 @Override
4307 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004308 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004309 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004310 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4311 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4312 "IMS not available on device.");
4313 }
4314 final long token = Binder.clearCallingIdentity();
4315 try {
4316 Phone phone = getPhone(subId);
4317 if (phone == null) {
4318 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4319 + subId + "'");
4320 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4321 }
4322 phone.getImsRegistrationTech(regTech -> {
4323 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4324 int regTechConverted = (regTech == null)
4325 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4326 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4327 regTechConverted);
4328 try {
4329 consumer.accept(regTechConverted);
4330 } catch (RemoteException e) {
4331 // Ignore if the remote process is no longer available to call back.
4332 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4333 }
4334 });
4335 } finally {
4336 Binder.restoreCallingIdentity(token);
4337 }
4338 }
4339
shilu366312e2019-12-17 09:28:10 -08004340 /**
4341 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4342 * @param subId The subscription to use to check the configuration.
4343 * @param c The callback that will be used to send the result.
4344 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004346 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4347 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004348 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004349 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004350 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4351 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4352 "IMS not available on device.");
4353 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 final long token = Binder.clearCallingIdentity();
4355 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004356 int slotId = getSlotIndexOrException(subId);
4357 verifyImsMmTelConfiguredOrThrow(slotId);
4358 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004359 } catch (ImsException e) {
4360 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 } finally {
4362 Binder.restoreCallingIdentity(token);
4363 }
4364 }
4365
shilu366312e2019-12-17 09:28:10 -08004366 /**
4367 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4368 * @param subId The subscription to use to check the configuration.
4369 * @param c The callback that will be used to send the result.
4370 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004372 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004374 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004375 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4376 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4377 }
Meng Wangafbc5852019-09-19 17:37:13 -07004378
4379 final long token = Binder.clearCallingIdentity();
4380 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004381 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004382 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004383 } catch (ImsException e) {
4384 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4385 + "is inactive, ignoring unregister.");
4386 // If the subscription is no longer active, just return, since the callback
4387 // will already have been removed internally.
4388 } finally {
4389 Binder.restoreCallingIdentity(token);
4390 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 }
4392
4393 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004394 public boolean isCapable(int subId, int capability, int regTech) {
4395 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 final long token = Binder.clearCallingIdentity();
4397 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004398 int slotId = getSlotIndexOrException(subId);
4399 verifyImsMmTelConfiguredOrThrow(slotId);
4400 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4401 } catch (com.android.ims.ImsException e) {
4402 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4403 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004404 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004405 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4406 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004407 } finally {
4408 Binder.restoreCallingIdentity(token);
4409 }
4410 }
4411
4412 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004413 public boolean isAvailable(int subId, int capability, int regTech) {
4414 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 final long token = Binder.clearCallingIdentity();
4416 try {
4417 Phone phone = getPhone(subId);
4418 if (phone == null) return false;
4419 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004420 } catch (com.android.ims.ImsException e) {
4421 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4422 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004423 } finally {
4424 Binder.restoreCallingIdentity(token);
4425 }
4426 }
4427
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004428 /**
4429 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4430 * subscription.
4431 * @param subId The subscription to use to check the configuration.
4432 * @param callback The callback that will be used to send the result.
4433 * @param capability The MmTelFeature capability that will be used to send the result.
4434 * @param transportType The transport type of the MmTelFeature capability.
4435 */
4436 @Override
4437 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4438 int transportType) {
4439 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004440 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4441 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4442 "IMS not available on device.");
4443 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004444 final long token = Binder.clearCallingIdentity();
4445 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004446 int slotId = getSlotIndex(subId);
4447 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4448 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4449 + subId + "'");
4450 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4451 }
4452 verifyImsMmTelConfiguredOrThrow(slotId);
4453 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4454 transportType, aBoolean -> {
4455 try {
4456 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4457 } catch (RemoteException e) {
4458 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4459 + "running. Ignore");
4460 }
4461 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004464 } finally {
4465 Binder.restoreCallingIdentity(token);
4466 }
4467 }
4468
shilu366312e2019-12-17 09:28:10 -08004469 /**
4470 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4471 * @param subId The subscription to use to check the configuration.
4472 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 @Override
4474 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004475 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004476 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004477
Brad Ebinger35c841c2018-10-01 10:40:55 -07004478 final long token = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004481 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004483 } catch (ImsException e) {
4484 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 } finally {
4486 Binder.restoreCallingIdentity(token);
4487 }
4488 }
4489
4490 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004491 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004493 "setAdvancedCallingSettingEnabled");
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. The
4498 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004500 } catch (ImsException e) {
4501 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
4505 }
4506
shilu366312e2019-12-17 09:28:10 -08004507 /**
4508 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4509 * @param subId The subscription to use to check the configuration.
4510 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004512 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004513 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004514 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004515 final long identity = Binder.clearCallingIdentity();
4516 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004517 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004518 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004520 } catch (ImsException e) {
4521 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 }
4526
4527 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004528 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004530 "setVtSettingEnabled");
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. The
4535 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004536 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 } catch (ImsException e) {
4538 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
4542 }
4543
shilu366312e2019-12-17 09:28:10 -08004544 /**
4545 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4546 * @param subId The subscription to use to check the configuration.
4547 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004548 @Override
4549 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004550 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004551 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004552 final long identity = Binder.clearCallingIdentity();
4553 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004554 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004555 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004557 } catch (ImsException e) {
4558 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
4562 }
4563
4564 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004565 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004567 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004568 final long identity = Binder.clearCallingIdentity();
4569 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004570 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004571 // This setting doesn't require an active ImsService connection, so do not verify. The
4572 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004573 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004574 } catch (ImsException e) {
4575 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
4579 }
4580
shilu366312e2019-12-17 09:28:10 -08004581 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004582 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4583 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4584 * @param subId The subscription to use to check the configuration.
4585 */
4586 @Override
4587 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004588 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004589 mApp, subId, "isCrossSimCallingEnabledByUser");
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004592 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004593 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004595 } catch (ImsException e) {
4596 throw new ServiceSpecificException(e.getCode());
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
4600 }
4601
4602 /**
4603 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4604 * Requires MODIFY_PHONE_STATE permission.
4605 * @param subId The subscription to use to check the configuration.
4606 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4607 * false otherwise
4608 */
4609 @Override
4610 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4612 "setCrossSimCallingEnabled");
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004615 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004616 // This setting doesn't require an active ImsService connection, so do not verify. The
4617 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004619 } catch (ImsException e) {
4620 throw new ServiceSpecificException(e.getCode());
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
4624 }
4625
4626 /**
shilu366312e2019-12-17 09:28:10 -08004627 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4628 * @param subId The subscription to use to check the configuration.
4629 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004631
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004633 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004634 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 final long identity = Binder.clearCallingIdentity();
4636 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004637 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004638 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004639 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004640 } catch (ImsException e) {
4641 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004642 } finally {
4643 Binder.restoreCallingIdentity(identity);
4644 }
4645 }
4646
4647 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004648 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004650 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004653 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004654 // This setting doesn't require an active ImsService connection, so do not verify. The
4655 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004656 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004657 } catch (ImsException e) {
4658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4667 "setVoWiFiNonPersistent");
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004671 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004672 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004673 } catch (ImsException e) {
4674 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678 }
4679
shilu366312e2019-12-17 09:28:10 -08004680 /**
4681 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4682 * @param subId The subscription to use to check the configuration.
4683 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004684 @Override
4685 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004686 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004687 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 final long identity = Binder.clearCallingIdentity();
4689 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004691 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (ImsException e) {
4694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
4701 public void setVoWiFiModeSetting(int subId, int mode) {
4702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4703 "setVoWiFiModeSetting");
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004706 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004707 // This setting doesn't require an active ImsService connection, so do not verify. The
4708 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004710 } catch (ImsException e) {
4711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
4715 }
4716
4717 @Override
4718 public int getVoWiFiRoamingModeSetting(int subId) {
4719 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4720 final long identity = Binder.clearCallingIdentity();
4721 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004722 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004723 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004724 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004725 } catch (ImsException e) {
4726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
4730 }
4731
4732 @Override
4733 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4735 "setVoWiFiRoamingModeSetting");
4736 final long identity = Binder.clearCallingIdentity();
4737 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004738 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004739 // This setting doesn't require an active ImsService connection, so do not verify. The
4740 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004741 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004742 } catch (ImsException e) {
4743 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
4747 }
4748
4749 @Override
4750 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4752 "setRttCapabilityEnabled");
4753 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. The
4757 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004758 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004759 } catch (ImsException e) {
4760 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
4764 }
4765
shilu366312e2019-12-17 09:28:10 -08004766 /**
4767 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4768 * @param subId The subscription to use to check the configuration.
4769 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 @Override
4771 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004772 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004773 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004774 final long identity = Binder.clearCallingIdentity();
4775 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004776 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004777 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004778 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004779 } catch (ImsException e) {
4780 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
4784 }
4785
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004786 @Override
4787 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4788 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004789
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004790 final long identity = Binder.clearCallingIdentity();
4791 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004792 if (!isImsAvailableOnDevice()) {
4793 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4794 "IMS not available on device.");
4795 }
4796 int slotId = getSlotIndexOrException(subId);
4797 verifyImsMmTelConfiguredOrThrow(slotId);
4798 ImsManager.getInstance(mApp, slotId)
4799 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004800 } catch (ImsException e) {
4801 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004802 } finally {
4803 Binder.restoreCallingIdentity(identity);
4804 }
4805 }
4806
4807 @Override
4808 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4809 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004810
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004811 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004812 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4813 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4814 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004815 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004816 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004817 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004818 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004819 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4820 + "is inactive, ignoring unregister.");
4821 // If the subscription is no longer active, just return, since the callback will already
4822 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004823 } finally {
4824 Binder.restoreCallingIdentity(identity);
4825 }
4826 }
4827
joonhunshincffb7fc2021-11-28 07:32:01 +00004828 @Override
4829 public void registerFeatureProvisioningChangedCallback(int subId,
4830 IFeatureProvisioningCallback callback) {
4831 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4832 mApp, subId, "registerFeatureProvisioningChangedCallback");
4833
4834 final long identity = Binder.clearCallingIdentity();
4835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4836 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4837 }
4838
joonhunshin91bc1952022-04-29 08:47:15 +00004839 try {
4840 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4841 if (controller == null) {
4842 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4843 "Device does not support IMS");
4844 }
4845 controller.addFeatureProvisioningChangedCallback(subId, callback);
4846 } finally {
4847 Binder.restoreCallingIdentity(identity);
4848 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004849 }
4850
4851 @Override
4852 public void unregisterFeatureProvisioningChangedCallback(int subId,
4853 IFeatureProvisioningCallback callback) {
4854 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4855 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4856
4857 final long identity = Binder.clearCallingIdentity();
4858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4860 }
4861
joonhunshin91bc1952022-04-29 08:47:15 +00004862 try {
4863 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4864 if (controller == null) {
4865 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4866 return;
4867 }
4868 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004872 }
allenwtsu99c623b2020-01-03 18:24:23 +08004873
4874 private void checkModifyPhoneStatePermission(int subId, String message) {
4875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4876 message);
4877 }
4878
allenwtsu99c623b2020-01-03 18:24:23 +08004879 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004880 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004881 boolean isProvisioned) {
4882 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4883
4884 final long identity = Binder.clearCallingIdentity();
4885 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004886 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4887 if (controller == null) {
4888 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4889 return;
4890 }
4891 controller.setRcsProvisioningStatusForCapability(
4892 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
allenwtsu99c623b2020-01-03 18:24:23 +08004896 }
4897
4898
4899 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004900 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4901 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4902 mApp, subId, "getRcsProvisioningStatusForCapability");
4903
allenwtsu99c623b2020-01-03 18:24:23 +08004904 final long identity = Binder.clearCallingIdentity();
4905 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004906 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4907 if (controller == null) {
4908 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4909
4910 // device does not support IMS, this method will return true always.
4911 return true;
4912 }
4913 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
4917 }
4918
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004919 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004920 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4921 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004922 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004923
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004926 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4927 if (controller == null) {
4928 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4929 return;
4930 }
4931 controller.setImsProvisioningStatusForCapability(
4932 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
4936 }
4937
4938 @Override
4939 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004940 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4941 mApp, subId, "getProvisioningStatusForCapability");
4942
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 final long identity = Binder.clearCallingIdentity();
4944 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004945 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4946 if (controller == null) {
4947 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004948
joonhunshin91bc1952022-04-29 08:47:15 +00004949 // device does not support IMS, this method will return true always.
4950 return true;
4951 }
4952 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
4956 }
4957
4958 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004959 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4960 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4961 mApp, subId, "isProvisioningRequiredForCapability");
4962
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004965 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4966 if (controller == null) {
4967 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4968
4969 // device does not support IMS, this method will return false
4970 return false;
4971 }
4972 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004975 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004976 }
4977
4978 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004979 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4980 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4981 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004982
joonhunshincffb7fc2021-11-28 07:32:01 +00004983 final long identity = Binder.clearCallingIdentity();
4984 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004985 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4986 if (controller == null) {
4987 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4988
4989 // device does not support IMS, this method will return false
4990 return false;
4991 }
4992 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 }
4997
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004999 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005000 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5001 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5002 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005003 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5004 mApp, subId, "getImsProvisioningInt");
5005
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005006 final long identity = Binder.clearCallingIdentity();
5007 try {
5008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005009 int slotId = getSlotIndex(subId);
5010 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5011 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5012 + subId + "' for key:" + key);
5013 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5014 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005015
joonhunshin91bc1952022-04-29 08:47:15 +00005016 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5017 if (controller == null) {
5018 loge("getImsProvisioningInt: Device does not support IMS");
5019
5020 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5021 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5022 }
5023 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005024 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5025 return retVal;
5026 }
5027
calvinpanb5a34062021-02-08 19:59:36 +08005028 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005029 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005030 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5031 + subId + "' for key:" + key);
5032 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
5036 }
5037
5038 @Override
5039 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005040 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5041 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5042 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005043 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5044 mApp, subId, "getImsProvisioningString");
5045
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005049 int slotId = getSlotIndex(subId);
5050 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5051 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5052 + subId + "' for key:" + key);
5053 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5054 }
calvinpanb5a34062021-02-08 19:59:36 +08005055 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005056 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005057 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5058 + subId + "' for key:" + key);
5059 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
5063 }
5064
5065 @Override
5066 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005067 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5068 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5069 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5071 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005072
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 int slotId = getSlotIndex(subId);
5077 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5078 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5079 + subId + "' for key:" + key);
5080 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5081 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005082
joonhunshin91bc1952022-04-29 08:47:15 +00005083 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5084 if (controller == null) {
5085 loge("setImsProvisioningInt: Device does not support IMS");
5086
5087 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5088 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5089 }
5090 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005091 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5092 return retVal;
5093 }
5094
calvinpanb5a34062021-02-08 19:59:36 +08005095 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5096 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005097 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005098 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005099 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
5105 @Override
5106 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5108 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5109 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5111 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005115 int slotId = getSlotIndex(subId);
5116 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5117 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5118 + subId + "' for key:" + key);
5119 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5120 }
calvinpanb5a34062021-02-08 19:59:36 +08005121 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5122 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005123 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005124 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005125 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005126 } finally {
5127 Binder.restoreCallingIdentity(identity);
5128 }
5129 }
5130
Brad Ebinger919631e2021-06-02 17:46:35 -07005131 /**
5132 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5133 * for the given slot ID or no ImsResolver instance has been created.
5134 * @param slotId The slot ID that the IMS service is created for.
5135 * @throws ImsException If there is no ImsService configured for this slot.
5136 */
5137 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5138 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5139 ImsFeature.FEATURE_MMTEL)) {
5140 throw new ImsException("This subscription does not support MMTEL over IMS",
5141 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5142 }
5143 }
5144
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005145 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005146 int slotId = SubscriptionManager.getSlotIndex(subId);
5147 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005148 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5149 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005150 }
5151 return slotId;
5152 }
5153
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005154 private int getSlotIndex(int subId) {
5155 int slotId = SubscriptionManager.getSlotIndex(subId);
5156 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5157 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5158 }
5159 return slotId;
5160 }
5161
Wink Saville36469e72014-06-11 15:17:00 -07005162 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005163 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005164 */
5165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005166 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5167 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005168 try {
5169 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5170 } catch (SecurityException se) {
5171 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5172 throw new SecurityException("Package " + callingPackage + " does not belong to "
5173 + Binder.getCallingUid());
5174 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005175 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005176 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005177 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005178 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005179 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005180 mApp, subId, callingPackage, callingFeatureId,
5181 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005182 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5183 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 final Phone phone = getPhone(subId);
5188 if (phone != null) {
5189 return phone.getServiceState().getDataNetworkType();
5190 } else {
5191 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5192 }
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005196 }
5197
5198 /**
5199 * Returns the data network type
5200 */
5201 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005202 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005203 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005204 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005205 }
5206
5207 /**
5208 * Returns the data network type for a subId
5209 */
5210 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005211 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5212 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005213 String functionName = "getDataNetworkTypeForSubscriber";
5214 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5215 mApp, functionName)) {
5216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5217 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5219 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005220 }
5221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 final Phone phone = getPhone(subId);
5225 if (phone != null) {
5226 return phone.getServiceState().getDataNetworkType();
5227 } else {
5228 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5229 }
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005233 }
5234
5235 /**
Wink Saville36469e72014-06-11 15:17:00 -07005236 * Returns the Voice network type for a subId
5237 */
5238 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005239 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5240 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005241 String functionName = "getVoiceNetworkTypeForSubscriber";
5242 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5243 mApp, functionName)) {
5244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5245 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5246 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5247 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005248 }
5249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 final long identity = Binder.clearCallingIdentity();
5251 try {
5252 final Phone phone = getPhone(subId);
5253 if (phone != null) {
5254 return phone.getServiceState().getVoiceNetworkType();
5255 } else {
5256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5257 }
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005261 }
5262
5263 /**
5264 * @return true if a ICC card is present
5265 */
5266 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005267 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005268 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005269 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005270 }
5271
5272 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005273 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005274 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005275 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005276 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 final Phone phone = PhoneFactory.getPhone(slotIndex);
5280 if (phone != null) {
5281 return phone.getIccCard().hasIccCard();
5282 } else {
5283 return false;
5284 }
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005288 }
5289
5290 /**
5291 * Return if the current radio is LTE on CDMA. This
5292 * is a tri-state return value as for a period of time
5293 * the mode may be unknown.
5294 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005295 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005296 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005297 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005298 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005300 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5301 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5302 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005303 }
5304
Sanket Padawe356d7632015-06-22 14:03:32 -07005305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005306 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5307 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005308 try {
5309 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5310 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005311 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5312 }
5313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 final Phone phone = getPhone(subId);
5317 if (phone == null) {
5318 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5319 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005320 return TelephonyProperties.lte_on_cdma_device()
5321 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 }
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005325 }
Wink Saville36469e72014-06-11 15:17:00 -07005326 }
5327
Wink Saville36469e72014-06-11 15:17:00 -07005328 /**
5329 * {@hide}
5330 * Returns Default subId, 0 in the case of single standby.
5331 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005332 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005333 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005334 }
5335
Shishir Agrawala9f32182016-04-12 12:00:16 -07005336 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005337 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005338 }
5339
Wink Savilleb564aae2014-10-23 10:18:09 -07005340 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005341 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005342 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005343
Pengquan Menge92a50d2018-09-21 15:54:48 -07005344 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005345 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5346 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5347 mApp.getOpPackageName(), mApp.getFeatureId());
5348 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005349 return mSubscriptionController.isActiveSubId(subId);
5350 }
5351
Ihab Awadf2177b72013-11-25 13:33:23 -08005352 /**
5353 * @see android.telephony.TelephonyManager.WifiCallingChoices
5354 */
5355 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 final long identity = Binder.clearCallingIdentity();
5357 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005358 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5360 getWhenToMakeWifiCallsDefaultPreference());
5361 } finally {
5362 Binder.restoreCallingIdentity(identity);
5363 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005364 }
5365
5366 /**
5367 * @see android.telephony.TelephonyManager.WifiCallingChoices
5368 */
5369 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005373 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005378 }
5379
Sailesh Nepald1e68152013-12-12 19:08:02 -08005380 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005381 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005382 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005383 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005384
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005385 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5386 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5387 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005388 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005389 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5390 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005391 }
5392 return PhoneFactory.getPhone(phoneId);
5393 }
5394
Shishir Agrawal566b7612013-10-28 14:41:00 -07005395 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005396 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005397 @NonNull IccLogicalChannelRequest request) {
5398 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5399 /*message=*/ "iccOpenLogicalChannel");
5400
5401 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5402 // Verify that the callingPackage in the request belongs to the calling UID
5403 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5404
5405 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005406 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005407
Rambo Wanga1782702021-11-10 20:15:19 -08005408 private Phone getPhoneFromValidIccLogicalChannelRequest(
5409 @NonNull IccLogicalChannelRequest request, String message) {
5410 Phone phone;
5411 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5413 mApp, request.subId, message);
5414 phone = getPhoneFromSubId(request.subId);
5415 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5416 enforceModifyPermission();
5417 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5418 } else {
5419 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005420 }
Rambo Wanga1782702021-11-10 20:15:19 -08005421 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005422 }
5423
5424 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005425 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005428 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005430 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5431 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005432 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5433 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 loge("The calling package is not allowed to access ISD-R.");
5435 throw new SecurityException(
5436 "The calling package is not allowed to access ISD-R.");
5437 }
Derek Tan740e1672017-06-27 14:56:27 -07005438 }
Derek Tan740e1672017-06-27 14:56:27 -07005439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005441 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5442 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 return response;
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005447 }
5448
5449 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005450 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5451 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5452 /*message=*/"iccCloseLogicalChannel");
5453
5454 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5455
5456 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005457 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005458
Rambo Wanga1782702021-11-10 20:15:19 -08005459 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5460 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005461 // before this feature is enabled, this API should only return false if
5462 // the operation fails instead of throwing runtime exception for
5463 // backward-compatibility.
5464 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5465 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005468 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005469 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 }
Chen Xue9d737e2022-01-01 23:41:31 -08005471 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005472 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005473 Boolean success = false;
5474 if (result instanceof RuntimeException) {
5475 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005476 if (shouldThrowExceptionOnFailure) {
5477 throw (RuntimeException) result;
5478 } else {
5479 return false;
5480 }
Chen Xue9d737e2022-01-01 23:41:31 -08005481 } else if (result instanceof Boolean) {
5482 success = (Boolean) result;
5483 } else {
5484 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5485 }
Rambo Wanga1782702021-11-10 20:15:19 -08005486 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 return success;
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005490 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005491 }
5492
5493 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005494 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005495 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5497 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005498 if (DBG) {
5499 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5500 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5501 + p3 + " data=" + data);
5502 }
5503 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5504 command, p1, p2, p3, data);
5505 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005506
Jordan Liu4c733742019-02-28 12:03:40 -08005507 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005508 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5509 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005510 enforceModifyPermission();
5511 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005512 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5513 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5514 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005515 }
5516 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005517 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5518 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005519 }
5520
5521 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5522 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005525 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 return "";
5527 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005530 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5531 null /* workSource */);
5532 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 // Append the returned status code to the end of the response payload.
5535 String s = Integer.toHexString(
5536 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5537 if (response.payload != null) {
5538 s = IccUtils.bytesToHexString(response.payload) + s;
5539 }
5540 return s;
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005543 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005544 }
Jake Hambye994d462014-02-03 13:10:13 -08005545
Evan Charltonc66da362014-05-16 14:06:40 -07005546 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005547 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5548 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5550 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005552 if (DBG) {
5553 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5554 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5555 }
5556 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5557 cla, command, p1, p2, p3, data);
5558 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005559
Jordan Liu4c733742019-02-28 12:03:40 -08005560 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005561 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5562 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005563 enforceModifyPermission();
5564 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5565 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005566 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5567 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5568 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005569 }
5570
5571 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005572 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5573 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005574 }
5575
5576 // open APDU basic channel assuming the caller has sufficient permissions
5577 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5578 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5582 && TextUtils.equals(ISDR_AID, data)) {
5583 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005584 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5585 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 if (bestComponent == null
5587 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5588 loge("The calling package is not allowed to select ISD-R.");
5589 throw new SecurityException(
5590 "The calling package is not allowed to select ISD-R.");
5591 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005592 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005595 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5596 null /* workSource */);
5597 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 // Append the returned status code to the end of the response payload.
5600 String s = Integer.toHexString(
5601 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5602 if (response.payload != null) {
5603 s = IccUtils.bytesToHexString(response.payload) + s;
5604 }
5605 return s;
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005608 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005609 }
5610
5611 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005612 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005613 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 if (DBG) {
5620 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5621 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5622 }
5623
5624 IccIoResult response =
5625 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5626 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5627 subId);
5628
5629 if (DBG) {
5630 log("Exchange SIM_IO [R]" + response);
5631 }
5632
5633 byte[] result = null;
5634 int length = 2;
5635 if (response.payload != null) {
5636 length = 2 + response.payload.length;
5637 result = new byte[length];
5638 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5639 } else {
5640 result = new byte[length];
5641 }
5642
5643 result[length - 1] = (byte) response.sw2;
5644 result[length - 2] = (byte) response.sw1;
5645 return result;
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005648 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005649 }
5650
Nathan Haroldb3014052017-01-25 15:57:32 -08005651 /**
5652 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5653 * on a particular subscription
5654 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005655 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5656 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005658 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005659 return null;
5660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 if (appType != TelephonyManager.APPTYPE_USIM
5665 && appType != TelephonyManager.APPTYPE_SIM) {
5666 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5667 return null;
5668 }
5669 Object response = sendRequest(
5670 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5671 if (response instanceof String[]) {
5672 return (String[]) response;
5673 }
yincheng zhao2737e882019-09-06 17:06:54 -07005674 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005676 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005679 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005680 }
5681
yincheng zhao2737e882019-09-06 17:06:54 -07005682 /**
5683 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5684 * subscription.
5685 *
5686 * @param subId the id of the subscription.
5687 * @param appType the uicc app type, must be USIM or SIM.
5688 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5689 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005690 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005691 * @return number of fplmns that is successfully written to the SIM.
5692 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005693 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5694 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5696 mApp, subId, "setForbiddenPlmns");
5697
yincheng zhao2737e882019-09-06 17:06:54 -07005698 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5699 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5700 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5701 }
5702 if (fplmns == null) {
5703 throw new IllegalArgumentException("Fplmn List provided is null");
5704 }
5705 for (String fplmn : fplmns) {
5706 if (!CellIdentity.isValidPlmn(fplmn)) {
5707 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5708 }
5709 }
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 Object response = sendRequest(
5713 CMD_SET_FORBIDDEN_PLMNS,
5714 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5715 subId);
5716 return (int) response;
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
5720 }
5721
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005722 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005723 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5725 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5730 if (response.payload == null) {
5731 return "";
5732 }
Evan Charltonc66da362014-05-16 14:06:40 -07005733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 // Append the returned status code to the end of the response payload.
5735 String s = Integer.toHexString(
5736 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5737 s = IccUtils.bytesToHexString(response.payload) + s;
5738 return s;
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Evan Charltonc66da362014-05-16 14:06:40 -07005742 }
5743
Jake Hambye994d462014-02-03 13:10:13 -08005744 /**
5745 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5746 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5747 *
5748 * @param itemID the ID of the item to read
5749 * @return the NV item as a String, or null on error.
5750 */
5751 @Override
5752 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005753 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5755 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005760 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5762 return value;
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Jake Hambye994d462014-02-03 13:10:13 -08005766 }
5767
5768 /**
5769 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5770 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5771 *
5772 * @param itemID the ID of the item to read
5773 * @param itemValue the value to write, as a String
5774 * @return true on success; false on any failure
5775 */
5776 @Override
5777 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005778 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5780 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5785 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005786 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5788 return success;
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
Jake Hambye994d462014-02-03 13:10:13 -08005792 }
5793
5794 /**
5795 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5796 * Used for device configuration by some CDMA operators.
5797 *
5798 * @param preferredRoamingList byte array containing the new PRL
5799 * @return true on success; false on any failure
5800 */
5801 @Override
5802 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5804 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5809 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5810 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5811 return success;
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
Jake Hambye994d462014-02-03 13:10:13 -08005815 }
5816
5817 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005818 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005819 * Used for device configuration by some CDMA operators.
5820 *
chen xu6dac5ab2018-10-26 17:39:23 -07005821 * @param slotIndex - device slot.
5822 *
Jake Hambye994d462014-02-03 13:10:13 -08005823 * @return true on success; false on any failure
5824 */
5825 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005826 public boolean resetModemConfig(int slotIndex) {
5827 Phone phone = PhoneFactory.getPhone(slotIndex);
5828 if (phone != null) {
5829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5830 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831
chen xu6dac5ab2018-10-26 17:39:23 -07005832 final long identity = Binder.clearCallingIdentity();
5833 try {
5834 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5835 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5836 return success;
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 }
chen xu6dac5ab2018-10-26 17:39:23 -07005841 return false;
5842 }
5843
5844 /**
5845 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5846 *
5847 * @param slotIndex - device slot.
5848 *
5849 * @return true on success; false on any failure
5850 */
5851 @Override
5852 public boolean rebootModem(int slotIndex) {
5853 Phone phone = PhoneFactory.getPhone(slotIndex);
5854 if (phone != null) {
5855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5856 mApp, phone.getSubId(), "rebootModem");
5857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5861 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5862 return success;
5863 } finally {
5864 Binder.restoreCallingIdentity(identity);
5865 }
5866 }
5867 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005868 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005869
Brad Ebinger51f743a2017-01-23 13:50:20 -08005870 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005871 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5872 * {@link #disableIms(int)}.
5873 * @param slotIndex device slot.
5874 */
5875 public void resetIms(int slotIndex) {
5876 enforceModifyPermission();
5877
5878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 if (mImsResolver == null) {
5881 // may happen if the does not support IMS.
5882 return;
5883 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005884 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
5888 }
5889
5890 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005891 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5892 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005893 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005894 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896
5897 final long identity = Binder.clearCallingIdentity();
5898 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005900 // may happen if the device does not support IMS.
5901 return;
5902 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005903 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 } finally {
5905 Binder.restoreCallingIdentity(identity);
5906 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005907 }
5908
5909 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005910 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5911 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005912 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005913 public void disableIms(int slotId) {
5914 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915
5916 final long identity = Binder.clearCallingIdentity();
5917 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005919 // may happen if the device does not support IMS.
5920 return;
5921 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005922 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005926 }
5927
5928 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005929 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5930 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005931 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005932 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005933 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935
5936 final long identity = Binder.clearCallingIdentity();
5937 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005939 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5940 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005941 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005942 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005946 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005947 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005948 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5949 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005950 @Override
5951 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005952 enforceModifyPermission();
5953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005957 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
5961 }
5962
5963 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005964 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005965 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005966 */
5967 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969
5970 final long identity = Binder.clearCallingIdentity();
5971 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005972 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005973 // may happen if the device does not support IMS.
5974 return null;
5975 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005976 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005980 }
5981
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005982 /**
5983 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005984 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005985 */
5986 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 final long identity = Binder.clearCallingIdentity();
5990 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005991 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005992 // may happen if the device does not support IMS.
5993 return null;
5994 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005995 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005999 }
6000
Brad Ebinger884c07b2018-02-15 16:17:40 -08006001 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006002 * Sets the ImsService Package Name that Telephony will bind to.
6003 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006004 * @param slotIndex the slot ID that the ImsService should bind for.
6005 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006006 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006007 * @param featureTypes An integer array of feature types associated with a packageName.
6008 * @param packageName The name of the package that the current configuration will be replaced
6009 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006010 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006011 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006012 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6013 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006016 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 final long identity = Binder.clearCallingIdentity();
6019 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006020 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006021 // may happen if the device does not support IMS.
6022 return false;
6023 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006024 Map<Integer, String> featureConfig = new HashMap<>();
6025 for (int featureType : featureTypes) {
6026 featureConfig.put(featureType, packageName);
6027 }
6028 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6029 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006033 }
6034
6035 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006036 * Clears any carrier ImsService overrides for the slot index specified that were previously
6037 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6038 *
6039 * This should only be used for testing.
6040 *
6041 * @param slotIndex the slot ID that the ImsService should bind for.
6042 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6043 */
6044 @Override
6045 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6047 "clearCarrierImsServiceOverride");
6048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006049 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006050
6051 final long identity = Binder.clearCallingIdentity();
6052 try {
6053 if (mImsResolver == null) {
6054 // may happen if the device does not support IMS.
6055 return false;
6056 }
6057 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
6061 }
6062
6063 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006064 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006065 *
6066 * @param slotId The slot that the ImsService is associated with.
6067 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6068 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006069 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006070 * @return the package name of the ImsService configuration.
6071 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006072 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6073 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006074 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006075 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6076 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 final long identity = Binder.clearCallingIdentity();
6079 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006080 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006081 // may happen if the device does not support IMS.
6082 return "";
6083 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006084 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006085 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6086 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006090 }
6091
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006092 /**
6093 * Get the MmTelFeature state associated with the requested subscription id.
6094 * @param subId The subscription that the MmTelFeature is associated with.
6095 * @param callback A callback with an integer containing the
6096 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6097 */
6098 @Override
6099 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6100 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006101 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6102 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6103 "IMS not available on device.");
6104 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006105 final long token = Binder.clearCallingIdentity();
6106 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006107 int slotId = getSlotIndex(subId);
6108 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6109 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6110 + subId + "'");
6111 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6112 }
6113 verifyImsMmTelConfiguredOrThrow(slotId);
6114 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6115 try {
6116 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6117 } catch (RemoteException e) {
6118 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6119 + "Ignore");
6120 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006121 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006122 } catch (ImsException e) {
6123 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006124 } finally {
6125 Binder.restoreCallingIdentity(token);
6126 }
6127 }
6128
Daniel Brightbb5840b2021-01-12 15:48:18 -08006129 /**
6130 * Sets the ims registration state on all valid {@link Phone}s.
6131 */
6132 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134
6135 final long identity = Binder.clearCallingIdentity();
6136 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006137 // NOTE: Before S, this method only set the default phone.
6138 for (final Phone phone : PhoneFactory.getPhones()) {
6139 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6140 phone.setImsRegistrationState(registered);
6141 }
6142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
Wink Saville36469e72014-06-11 15:17:00 -07006146 }
6147
6148 /**
Stuart Scott54788802015-03-30 13:18:01 -07006149 * Set the network selection mode to automatic.
6150 *
6151 */
6152 @Override
6153 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6155 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
shilufc958392020-01-20 11:36:01 -08006159 if (!isActiveSubscription(subId)) {
6160 return;
6161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006163 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6164 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
Stuart Scott54788802015-03-30 13:18:01 -07006168 }
6169
Jack Yud10cdd42020-09-28 20:28:01 -07006170 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006171 * Ask the radio to connect to the input network and change selection mode to manual.
6172 *
6173 * @param subId the id of the subscription.
6174 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6175 * the operator to attach to.
6176 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6177 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6178 * normal network selection next time.
6179 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006180 */
6181 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006182 public boolean setNetworkSelectionModeManual(
6183 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6185 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006186
Jack Yu285100e2022-12-02 22:48:35 -08006187 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006188 if (!isActiveSubscription(subId)) {
6189 return false;
6190 }
6191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006193 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006195 if (DBG) {
6196 log("setNetworkSelectionModeManual: subId: " + subId
6197 + " operator: " + operatorInfo);
6198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006203 }
shilu84f6e8b2019-12-19 13:58:01 -08006204 /**
6205 * Get the manual network selection
6206 *
6207 * @param subId the id of the subscription.
6208 *
6209 * @return the previously saved user selected PLMN
6210 */
6211 @Override
6212 public String getManualNetworkSelectionPlmn(int subId) {
6213 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006214 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006215 mApp, subId, "getManualNetworkSelectionPlmn");
6216
6217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006220 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006221 }
6222
6223 final Phone phone = getPhone(subId);
6224 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006225 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006226 }
6227 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6228 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6229 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006234
6235 /**
6236 * Scans for available networks.
6237 */
6238 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006239 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6240 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6242 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006243 LocationAccessPolicy.LocationPermissionResult locationResult =
6244 LocationAccessPolicy.checkLocationPermission(mApp,
6245 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6246 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006247 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006248 .setCallingPid(Binder.getCallingPid())
6249 .setCallingUid(Binder.getCallingUid())
6250 .setMethod("getCellNetworkScanResults")
6251 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006252 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6253 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006254 .build());
6255 switch (locationResult) {
6256 case DENIED_HARD:
6257 throw new SecurityException("Not allowed to access scan results -- location");
6258 case DENIED_SOFT:
6259 return null;
6260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261
Pengquan Menga1bb6272018-09-06 09:59:22 -07006262 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 try {
6264 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006265 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 } finally {
6268 Binder.restoreCallingIdentity(identity);
6269 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006270 }
6271
6272 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006273 * Get the call forwarding info, given the call forwarding reason.
6274 */
6275 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006276 public void getCallForwarding(int subId, int callForwardingReason,
6277 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006278 enforceReadPrivilegedPermission("getCallForwarding");
6279 long identity = Binder.clearCallingIdentity();
6280 try {
6281 if (DBG) {
6282 log("getCallForwarding: subId " + subId
6283 + " callForwardingReason" + callForwardingReason);
6284 }
Hall Liu27d24262020-09-18 19:04:59 -07006285
6286 Phone phone = getPhone(subId);
6287 if (phone == null) {
6288 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006289 callback.onError(
6290 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006291 } catch (RemoteException e) {
6292 // ignore
6293 }
6294 return;
6295 }
6296
6297 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6298 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6299 @Override
6300 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6301 try {
6302 callback.onCallForwardingInfoAvailable(info);
6303 } catch (RemoteException e) {
6304 // ignore
6305 }
6306 }
6307
6308 @Override
6309 public void onError(int error) {
6310 try {
6311 callback.onError(error);
6312 } catch (RemoteException e) {
6313 // ignore
6314 }
6315 }
6316 });
6317 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
6321 }
6322
6323 /**
6324 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6325 * reason, the number to forward, and the timeout before the forwarding is attempted.
6326 */
6327 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006328 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6329 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006330 enforceModifyPermission();
6331 long identity = Binder.clearCallingIdentity();
6332 try {
6333 if (DBG) {
6334 log("setCallForwarding: subId " + subId
6335 + " callForwardingInfo" + callForwardingInfo);
6336 }
Hall Liu27d24262020-09-18 19:04:59 -07006337
6338 Phone phone = getPhone(subId);
6339 if (phone == null) {
6340 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006341 callback.accept(
6342 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006343 } catch (RemoteException e) {
6344 // ignore
6345 }
6346 return;
6347 }
6348
6349 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6350 FunctionalUtils.ignoreRemoteException(callback::accept));
6351
6352 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
6356 }
6357
6358 /**
Hall Liu27d24262020-09-18 19:04:59 -07006359 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006360 */
6361 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006362 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006363 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006364 long identity = Binder.clearCallingIdentity();
6365 try {
Hall Liu27d24262020-09-18 19:04:59 -07006366 Phone phone = getPhone(subId);
6367 if (phone == null) {
6368 try {
6369 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6370 } catch (RemoteException e) {
6371 // ignore
6372 }
6373 return;
6374 }
SongFerngWang0e767992021-03-31 22:08:45 +08006375 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6376 PersistableBundle c = configManager.getConfigForSubId(subId);
6377 boolean requireUssd = c.getBoolean(
6378 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006379
Shuo Qian4a594052020-01-23 11:59:30 -08006380 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006381 if (requireUssd) {
6382 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6383 getSubscriptionCarrierId(subId));
6384 String newUssdCommand = "";
6385 try {
6386 newUssdCommand = carrierXmlParser.getFeature(
6387 CarrierXmlParser.FEATURE_CALL_WAITING)
6388 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6389 } catch (NullPointerException e) {
6390 loge("Failed to generate USSD number" + e);
6391 }
6392 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6393 mMainThreadHandler, callback, carrierXmlParser,
6394 CarrierXmlParser.SsEntry.SSAction.QUERY);
6395 final String ussdCommand = newUssdCommand;
6396 Executors.newSingleThreadExecutor().execute(() -> {
6397 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6398 });
6399 } else {
6400 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6401 callback::accept);
6402 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6403 }
Shuo Qian4a594052020-01-23 11:59:30 -08006404 } finally {
6405 Binder.restoreCallingIdentity(identity);
6406 }
6407 }
6408
6409 /**
Hall Liu27d24262020-09-18 19:04:59 -07006410 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006411 */
6412 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006413 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006414 enforceModifyPermission();
6415 long identity = Binder.clearCallingIdentity();
6416 try {
Hall Liu27d24262020-09-18 19:04:59 -07006417 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6418
6419 Phone phone = getPhone(subId);
6420 if (phone == null) {
6421 try {
6422 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6423 } catch (RemoteException e) {
6424 // ignore
6425 }
6426 return;
6427 }
6428
SongFerngWang0e767992021-03-31 22:08:45 +08006429 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6430 PersistableBundle c = configManager.getConfigForSubId(subId);
6431 boolean requireUssd = c.getBoolean(
6432 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006433
SongFerngWang0e767992021-03-31 22:08:45 +08006434 if (DBG) log("getCallWaitingStatus: subId " + subId);
6435 if (requireUssd) {
6436 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6437 getSubscriptionCarrierId(subId));
6438 CarrierXmlParser.SsEntry.SSAction ssAction =
6439 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6440 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6441 String newUssdCommand = "";
6442 try {
6443 newUssdCommand = carrierXmlParser.getFeature(
6444 CarrierXmlParser.FEATURE_CALL_WAITING)
6445 .makeCommand(ssAction, null);
6446 } catch (NullPointerException e) {
6447 loge("Failed to generate USSD number" + e);
6448 }
6449 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6450 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6451 final String ussdCommand = newUssdCommand;
6452 Executors.newSingleThreadExecutor().execute(() -> {
6453 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6454 });
6455 } else {
6456 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6457 FunctionalUtils.ignoreRemoteException(callback::accept));
6458
6459 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6460 }
Shuo Qian4a594052020-01-23 11:59:30 -08006461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
6464 }
6465
6466 /**
yinxub1bed742017-04-17 11:45:04 -07006467 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006468 *
yinxub1bed742017-04-17 11:45:04 -07006469 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006470 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6471 * location related information which will be sent if the caller already possess
6472 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006473 * @param request contains the radio access networks with bands/channels to scan
6474 * @param messenger callback messenger for scan results or errors
6475 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006476 * @return the id of the requested scan which can be used to stop the scan.
6477 */
6478 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006479 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6480 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006481 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6483 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006484 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006485 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6486 if (!renounceFineLocationAccess) {
6487 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6488 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6489 .setCallingPackage(callingPackage)
6490 .setCallingFeatureId(callingFeatureId)
6491 .setCallingPid(Binder.getCallingPid())
6492 .setCallingUid(Binder.getCallingUid())
6493 .setMethod("requestNetworkScan")
6494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6495 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6496 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6497 .build());
6498 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006499 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006500 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6501 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006502 if (e != null) {
6503 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6504 throw e;
6505 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006506 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006507 return TelephonyScanManager.INVALID_SCAN_ID;
6508 }
6509 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510 }
Hall Liu912dfd32019-04-25 14:02:26 -07006511 int callingUid = Binder.getCallingUid();
6512 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006516 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006517 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006518 } finally {
6519 Binder.restoreCallingIdentity(identity);
6520 }
yinxu504e1392017-04-12 16:03:22 -07006521 }
6522
Hall Liub2ac8ef2019-02-28 15:56:23 -08006523 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006524 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006525 boolean hasCarrierPriv;
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6529 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
Hall Liu558027f2019-05-15 19:14:05 -07006533 boolean hasNetworkScanPermission =
6534 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6535 == PERMISSION_GRANTED;
6536
6537 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6538 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6539 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006540 }
6541
6542 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6543 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006544 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6545 return new SecurityException("Specific channels must not be"
6546 + " scanned without location access.");
6547 }
6548 }
6549 }
6550
Hall Liub2ac8ef2019-02-28 15:56:23 -08006551 return null;
6552 }
6553
yinxu504e1392017-04-12 16:03:22 -07006554 /**
6555 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006556 *
6557 * @param subId id of the subscription
6558 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006559 */
6560 @Override
6561 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6563 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564
Hall Liu912dfd32019-04-25 14:02:26 -07006565 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 final long identity = Binder.clearCallingIdentity();
6567 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006568 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569 } finally {
6570 Binder.restoreCallingIdentity(identity);
6571 }
yinxu504e1392017-04-12 16:03:22 -07006572 }
6573
6574 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006575 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006576 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006577 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006578 */
6579 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006580 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006581 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006582 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006583 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584
6585 final long identity = Binder.clearCallingIdentity();
6586 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006587 if (DBG) log("getAllowedNetworkTypesBitmask");
6588 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6589 int networkTypesBitmask = (result != null ? result[0] : -1);
6590 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6591 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006595 }
6596
6597 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006598 * Get the allowed network types for certain reason.
6599 *
6600 * @param subId the id of the subscription.
6601 * @param reason the reason the allowed network type change is taking place
6602 * @return the allowed network types.
6603 */
6604 @Override
6605 public long getAllowedNetworkTypesForReason(int subId,
6606 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006607 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006608 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006609 final long identity = Binder.clearCallingIdentity();
6610 try {
6611 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
6615 }
6616
6617 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006618 * Enable/Disable E-UTRA-NR Dual Connectivity
6619 * @param subId subscription id of the sim card
6620 * @param nrDualConnectivityState expected NR dual connectivity state
6621 * This can be passed following states
6622 * <ol>
6623 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6624 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6625 * <li>Disable NR dual connectivity and force secondary cell to be released
6626 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6627 * </ol>
6628 * @return operation result.
6629 */
6630 @Override
6631 public int setNrDualConnectivityState(int subId,
6632 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6634 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006635 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006636 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6637 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6638 }
6639
Sooraj Sasindran37444802020-08-11 10:40:43 -07006640 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6641 final long identity = Binder.clearCallingIdentity();
6642 try {
6643 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6644 nrDualConnectivityState, subId,
6645 workSource);
6646 if (DBG) log("enableNRDualConnectivity result: " + result);
6647 return result;
6648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
6651 }
6652
6653 /**
6654 * Is E-UTRA-NR Dual Connectivity enabled
6655 * @return true if dual connectivity is enabled else false
6656 */
6657 @Override
6658 public boolean isNrDualConnectivityEnabled(int subId) {
6659 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006660 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006661 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006662 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006663 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6664 return false;
6665 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006666 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
6669 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6670 null, subId, workSource);
6671 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6672 return isEnabled;
6673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
6676 }
6677
6678 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006679 * Set the allowed network types of the device and
6680 * provide the reason triggering the allowed network change.
6681 *
6682 * @param subId the id of the subscription.
6683 * @param reason the reason the allowed network type change is taking place
6684 * @param allowedNetworkTypes the allowed network types.
6685 * @return true on success; false on any failure.
6686 */
6687 @Override
6688 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006689 @TelephonyManager.AllowedNetworkTypesReason int reason,
6690 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6692 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006693 // If the caller only has carrier privileges, then they should not be able to override
6694 // any network types which were set for security reasons.
6695 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6696 != PERMISSION_GRANTED
6697 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6698 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6699 throw new SecurityException(
6700 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6701 + " reason "
6702 + reason);
6703 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006704 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006705 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6706 return false;
6707 }
6708 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6709 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006710 return false;
6711 }
6712
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006713 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6714 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6715
6716
6717 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6718 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6719 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006720 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006721
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006722 final long identity = Binder.clearCallingIdentity();
6723 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006724 Boolean success = (Boolean) sendRequest(
6725 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6726 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6727
6728 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6729 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
6733 }
6734
6735 /**
Miaoa84611c2019-03-15 09:21:10 +08006736 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006737 *
Miaoa84611c2019-03-15 09:21:10 +08006738 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006739 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006740 * @hide
6741 */
6742 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006743 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 try {
Miaoa84611c2019-03-15 09:21:10 +08006748 if (phone != null) {
6749 return phone.hasMatchedTetherApnSetting();
6750 } else {
6751 return false;
6752 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 } finally {
6754 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006755 }
Junda Liu475951f2014-11-07 16:45:03 -08006756 }
6757
6758 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006759 * Get the user enabled state of Mobile Data.
6760 *
6761 * TODO: remove and use isUserDataEnabled.
6762 * This can't be removed now because some vendor codes
6763 * calls through ITelephony directly while they should
6764 * use TelephonyManager.
6765 *
6766 * @return true on enabled
6767 */
6768 @Override
6769 public boolean getDataEnabled(int subId) {
6770 return isUserDataEnabled(subId);
6771 }
6772
6773 /**
6774 * Get whether mobile data is enabled per user setting.
6775 *
6776 * There are other factors deciding whether mobile data is actually enabled, but they are
6777 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006778 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006779 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6780 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006781 *
6782 * @return {@code true} if data is enabled else {@code false}
6783 */
6784 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006785 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006786 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006787 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006788 try {
6789 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6790 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006791 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006792 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6793 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006794 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006796 mApp, subId, functionName);
6797
Robert Greenwalt646120a2014-05-23 11:54:03 -07006798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799
6800 final long identity = Binder.clearCallingIdentity();
6801 try {
Jack Yu285100e2022-12-02 22:48:35 -08006802 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6804 Phone phone = PhoneFactory.getPhone(phoneId);
6805 if (phone != null) {
6806 boolean retVal = phone.isUserDataEnabled();
6807 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6808 return retVal;
6809 } else {
6810 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6811 return false;
6812 }
6813 } finally {
6814 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006815 }
6816 }
6817
6818 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006819 * Checks if the device is capable of mobile data by considering whether whether the
6820 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6821 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006822 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006823 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006824 */
6825 @Override
6826 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006827 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006828 try {
6829 try {
6830 mApp.enforceCallingOrSelfPermission(
6831 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006832 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006833 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006834 try {
6835 mApp.enforceCallingOrSelfPermission(
6836 android.Manifest.permission.READ_PHONE_STATE,
6837 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006838 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006839 mApp.enforceCallingOrSelfPermission(
6840 permission.READ_BASIC_PHONE_STATE, functionName);
6841 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006842 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006843 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006844 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846
6847 final long identity = Binder.clearCallingIdentity();
6848 try {
Jack Yu285100e2022-12-02 22:48:35 -08006849 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850 Phone phone = PhoneFactory.getPhone(phoneId);
6851 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006852 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006853 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 return retVal;
6855 } else {
6856 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6857 return false;
6858 }
6859 } finally {
6860 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006861 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006862 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006863
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006864 /**
6865 * Check if data is enabled for a specific reason
6866 * @param subId Subscription index
6867 * @param reason the reason the data enable change is taking place
6868 * @return {@code true} if the overall data is enabled; {@code false} if not.
6869 */
6870 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006871 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006872 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006873 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006874 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006875 try {
6876 mApp.enforceCallingOrSelfPermission(
6877 android.Manifest.permission.ACCESS_NETWORK_STATE,
6878 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006879 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006880 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6881 functionName);
6882 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006883 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006884 try {
6885 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006886 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006887 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006889 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006890 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006891 }
6892
6893
6894 final long identity = Binder.clearCallingIdentity();
6895 try {
Jack Yu285100e2022-12-02 22:48:35 -08006896 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006897 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006898 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006899 + " reason=" + reason);
6900 }
6901 Phone phone = PhoneFactory.getPhone(phoneId);
6902 if (phone != null) {
6903 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006904 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006905 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006906 return retVal;
6907 } else {
6908 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006909 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006910 + subId + " retVal=false");
6911 }
6912 return false;
6913 }
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
6917 }
6918
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006919 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006920 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 // No permission needed; this only lets the caller inspect their own status.
6922 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006923 }
Junda Liu29340342014-07-10 15:23:27 -07006924
6925 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006926 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006927 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006928 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6929 }
6930
6931 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6932 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006933 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006934 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006935 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6936 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006937 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6938 if (cpt == null) {
6939 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006940 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6941 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006942 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006943 }
6944
6945 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006946 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006947 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006948 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006949 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006950 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006951 Phone phone = getPhone(subId);
6952 if (phone == null) {
6953 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6954 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6955 }
6956 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6957 if (cpt == null) {
6958 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006959 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6960 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006961 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006962 }
6963
6964 @Override
6965 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006966 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006967 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6968 }
6969
6970 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006971 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006972 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006973 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006974 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006975 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6976 Phone phone = PhoneFactory.getPhone(phoneId);
6977 if (phone == null) {
6978 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006979 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006980 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6981 if (cpt == null) {
6982 continue;
6983 }
6984 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006985 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6986 break;
6987 }
6988 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006989 return result;
Junda Liu29340342014-07-10 15:23:27 -07006990 }
Derek Tan89e89d42014-07-08 17:00:10 -07006991
6992 @Override
Junda Liue64de782015-04-16 17:19:16 -07006993 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006994 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006995 Phone phone = PhoneFactory.getPhone(phoneId);
6996 if (phone == null) {
6997 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006998 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006999 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7000 if (cpt == null) {
7001 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007002 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007003 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007004 }
7005
Amith Yamasani6e118872016-02-19 12:53:51 -08007006 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007007 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007008 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007009 Phone phone = PhoneFactory.getPhone(phoneId);
7010 if (phone == null) {
7011 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007012 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007013 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7014 if (cpt == null) {
7015 return Collections.emptyList();
7016 }
7017 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007018 }
7019
chen xuf7e9fe82019-05-09 19:31:02 -07007020 @Override
7021 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007022 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007023 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007024 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007025 try {
7026 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7027 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7028 }
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007031 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007032 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007033 }
7034
Rambo Wang6812ffb2022-03-15 16:54:17 -07007035 @Override
7036 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7037 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7038
7039 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7040 if (phone == null) {
7041 return null;
7042 }
7043 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7044 if (cpt == null) {
7045 return null;
7046 }
7047 return cpt.getCarrierServicePackageName();
7048 }
7049
Wink Savilleb564aae2014-10-23 10:18:09 -07007050 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007051 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007052 UiccPort port = phone == null ? null : phone.getUiccPort();
7053 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007054 return null;
7055 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007056 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007057 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007058 return null;
7059 }
7060 return iccId;
7061 }
7062
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007063 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007064 public void setCallComposerStatus(int subId, int status) {
7065 enforceModifyPermission();
7066
7067 final long identity = Binder.clearCallingIdentity();
7068 try {
7069 Phone phone = getPhone(subId);
7070 if (phone != null) {
7071 Phone defaultPhone = phone.getImsPhone();
7072 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7073 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7074 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007075 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7076 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007077 }
7078 }
Shuo Qian284ae752020-12-22 19:10:14 -08007079 } catch (ImsException e) {
7080 throw new ServiceSpecificException(e.getCode());
7081 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007082 Binder.restoreCallingIdentity(identity);
7083 }
7084 }
7085
7086 @Override
7087 public int getCallComposerStatus(int subId) {
7088 enforceReadPrivilegedPermission("getCallComposerStatus");
7089
7090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 Phone phone = getPhone(subId);
7093 if (phone != null) {
7094 Phone defaultPhone = phone.getImsPhone();
7095 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7096 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7097 return imsPhone.getCallComposerStatus();
7098 }
7099 }
7100 } finally {
7101 Binder.restoreCallingIdentity(identity);
7102 }
7103 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7104 }
7105
7106 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007107 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7108 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007109 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007110 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 final String iccId = getIccId(subId);
7115 final Phone phone = getPhone(subId);
7116 if (phone == null) {
7117 return false;
7118 }
7119 final String subscriberId = phone.getSubscriberId();
7120
7121 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007122 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 + subscriberId + " to " + number);
7124 }
7125
7126 if (TextUtils.isEmpty(iccId)) {
7127 return false;
7128 }
7129
7130 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7131
7132 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7133 if (alphaTag == null) {
7134 editor.remove(alphaTagPrefKey);
7135 } else {
7136 editor.putString(alphaTagPrefKey, alphaTag);
7137 }
7138
7139 // Record both the line number and IMSI for this ICCID, since we need to
7140 // track all merged IMSIs based on line number
7141 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7142 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7143 if (number == null) {
7144 editor.remove(numberPrefKey);
7145 editor.remove(subscriberPrefKey);
7146 } else {
7147 editor.putString(numberPrefKey, number);
7148 editor.putString(subscriberPrefKey, subscriberId);
7149 }
7150
7151 editor.commit();
7152 return true;
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007155 }
Derek Tan7226c842014-07-02 17:42:23 -07007156 }
7157
7158 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007159 public String getLine1NumberForDisplay(int subId, String callingPackage,
7160 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007161 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007163 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007164 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007165 return null;
7166 }
Derek Tan97ebb422014-09-05 16:55:38 -07007167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 final long identity = Binder.clearCallingIdentity();
7169 try {
7170 String iccId = getIccId(subId);
7171 if (iccId != null) {
7172 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7173 if (DBG_MERGE) {
7174 log("getLine1NumberForDisplay returning "
7175 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7176 }
7177 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
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 }
7185
7186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007187 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7188 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007190 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007191 return null;
7192 }
Derek Tan97ebb422014-09-05 16:55:38 -07007193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 String iccId = getIccId(subId);
7197 if (iccId != null) {
7198 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7199 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7200 }
7201 return null;
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007204 }
Derek Tan7226c842014-07-02 17:42:23 -07007205 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007206
7207 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007208 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7209 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007210 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7211 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007213 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007214 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007215 return null;
7216 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007217
Jordan Liub49b04b2019-05-06 14:45:15 -07007218 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7219 // the process, where TelephonyManager was instantiated.
7220 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007221 final long identity = Binder.clearCallingIdentity();
7222 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007223 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final TelephonyManager tele = TelephonyManager.from(context);
7225 final SubscriptionManager sub = SubscriptionManager.from(context);
7226
7227 // Figure out what subscribers are currently active
7228 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229
Jordan Liub49b04b2019-05-06 14:45:15 -07007230 // Only consider subs which match the current subId
7231 // This logic can be simplified. See b/131189269 for progress.
7232 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007233 activeSubscriberIds.add(tele.getSubscriberId(subId));
7234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
7236 // First pass, find a number override for an active subscriber
7237 String mergeNumber = null;
7238 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7239 for (String key : prefs.keySet()) {
7240 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7241 final String subscriberId = (String) prefs.get(key);
7242 if (activeSubscriberIds.contains(subscriberId)) {
7243 final String iccId = key.substring(
7244 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7245 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7246 mergeNumber = (String) prefs.get(numberKey);
7247 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007248 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 + " for active subscriber " + subscriberId);
7250 }
7251 if (!TextUtils.isEmpty(mergeNumber)) {
7252 break;
7253 }
7254 }
7255 }
7256 }
7257
7258 // Shortcut when no active merged subscribers
7259 if (TextUtils.isEmpty(mergeNumber)) {
7260 return null;
7261 }
7262
7263 // Second pass, find all subscribers under that line override
7264 final ArraySet<String> result = new ArraySet<>();
7265 for (String key : prefs.keySet()) {
7266 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7267 final String number = (String) prefs.get(key);
7268 if (mergeNumber.equals(number)) {
7269 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7270 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7271 final String subscriberId = (String) prefs.get(subscriberKey);
7272 if (!TextUtils.isEmpty(subscriberId)) {
7273 result.add(subscriberId);
7274 }
7275 }
7276 }
7277 }
7278
7279 final String[] resultArray = result.toArray(new String[result.size()]);
7280 Arrays.sort(resultArray);
7281 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007282 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7284 }
7285 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007286 } finally {
7287 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007288 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007289 }
7290
7291 @Override
zoey chen38003472019-12-13 17:16:31 +08007292 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7293 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007294
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 final TelephonyManager telephonyManager = mApp.getSystemService(
7298 TelephonyManager.class);
7299 String subscriberId = telephonyManager.getSubscriberId(subId);
7300 if (subscriberId == null) {
7301 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007302 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007303 + subId);
7304 }
7305 return null;
7306 }
7307
Jack Yu285100e2022-12-02 22:48:35 -08007308 ParcelUuid groupUuid;
7309 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7310 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7311 .getSubscriptionInfo(subId);
7312 groupUuid = info.getGroupUuid();
7313 } else {
7314 final SubscriptionInfo info = mSubscriptionController
7315 .getSubscriptionInfo(subId);
7316 groupUuid = info.getGroupUuid();
7317 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007318 // If it doesn't belong to any group, return just subscriberId of itself.
7319 if (groupUuid == null) {
7320 return new String[]{subscriberId};
7321 }
7322
7323 // Get all subscriberIds from the group.
7324 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007325 List<SubscriptionInfo> groupInfos;
7326 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7327 groupInfos = SubscriptionManagerService.getInstance()
7328 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7329 mApp.getAttributionTag());
7330 } else {
7331 groupInfos = mSubscriptionController
7332 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7333 mApp.getAttributionTag());
7334 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007335 for (SubscriptionInfo subInfo : groupInfos) {
7336 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7337 if (subscriberId != null) {
7338 mergedSubscriberIds.add(subscriberId);
7339 }
7340 }
7341
7342 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
7345
7346 }
7347 }
7348
7349 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007350 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007351 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007352 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353
7354 final long identity = Binder.clearCallingIdentity();
7355 try {
7356 final Phone phone = getPhone(subId);
7357 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
7360 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007361 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007362
7363 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007364 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007365 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7366 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007367 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7368 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369
7370 final long identity = Binder.clearCallingIdentity();
7371 try {
7372 final Phone phone = getPhone(subId);
7373 if (phone == null) {
7374 return false;
7375 }
7376 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7377 cdmaNonRoamingList);
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007380 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007381 }
7382
7383 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007384 @Deprecated
7385 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7386 enforceModifyPermission();
7387
7388 int returnValue = 0;
7389 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007390 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007391 if(result.exception == null) {
7392 if (result.result != null) {
7393 byte[] responseData = (byte[])(result.result);
7394 if(responseData.length > oemResp.length) {
7395 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7396 responseData.length + "bytes. Buffer Size is " +
7397 oemResp.length + "bytes.");
7398 }
7399 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7400 returnValue = responseData.length;
7401 }
7402 } else {
7403 CommandException ex = (CommandException) result.exception;
7404 returnValue = ex.getCommandError().ordinal();
7405 if(returnValue > 0) returnValue *= -1;
7406 }
7407 } catch (RuntimeException e) {
7408 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7409 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7410 if(returnValue > 0) returnValue *= -1;
7411 }
7412
7413 return returnValue;
7414 }
7415
7416 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007417 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007418 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007419 try {
7420 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007421 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007422 mApp, phone.getSubId(), "getRadioAccessFamily");
7423 } catch (SecurityException e) {
7424 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7425 throw e;
7426 }
chen xub97461a2018-10-26 14:17:57 -07007427 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007428 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007429 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 final long identity = Binder.clearCallingIdentity();
7432 try {
chen xub97461a2018-10-26 14:17:57 -07007433 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007434 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007435 mApp, phone.getSubId(), "getRadioAccessFamily");
7436 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
chen xub97461a2018-10-26 14:17:57 -07007440 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007441 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007442
7443 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007444 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007445 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007446 try {
7447 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7448 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007449 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007450 }
7451 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007452 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007453 }
7454 RoleManager rm = mApp.getSystemService(RoleManager.class);
7455 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7456 if (!dialerRoleHolders.contains(callingPackage)) {
7457 throw new SecurityException("App must be the dialer role holder to"
7458 + " upload a call composer pic");
7459 }
7460
7461 Executors.newSingleThreadExecutor().execute(() -> {
7462 ByteArrayOutputStream output = new ByteArrayOutputStream(
7463 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7464 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7465 boolean readUntilEnd = false;
7466 int totalBytesRead = 0;
7467 byte[] buffer = new byte[16 * 1024];
7468 while (true) {
7469 int numRead;
7470 try {
7471 numRead = input.read(buffer);
7472 } catch (IOException e) {
7473 try {
7474 fd.checkError();
7475 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7476 null);
7477 } catch (IOException e1) {
7478 // This means that the other side closed explicitly with an error. If this
7479 // happens, log and ignore.
7480 loge("Remote end of call composer picture pipe closed: " + e1);
7481 }
7482 break;
7483 }
7484 if (numRead == -1) {
7485 readUntilEnd = true;
7486 break;
7487 }
7488 totalBytesRead += numRead;
7489 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7490 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7491 try {
7492 input.close();
7493 } catch (IOException e) {
7494 // ignore
7495 }
7496 break;
7497 }
7498 output.write(buffer, 0, numRead);
7499 }
7500 // Generally, the remote end will close the file descriptors. The only case where we
7501 // close is above, where the picture size is too big.
7502
7503 try {
7504 fd.checkError();
7505 } catch (IOException e) {
7506 loge("Remote end for call composer closed with an error: " + e);
7507 return;
7508 }
7509
Hall Liuaa4211e2021-01-20 15:43:39 -08007510 if (!readUntilEnd) {
7511 loge("Did not finish reading entire image; aborting");
7512 return;
7513 }
Hall Liu82694d52020-12-11 18:22:04 -08007514
Hall Liuaa4211e2021-01-20 15:43:39 -08007515 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7516 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7517 new CallComposerPictureTransfer.Factory() {},
7518 imageData,
7519 (result) -> {
7520 if (result.first != null) {
7521 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7522 Bundle outputResult = new Bundle();
7523 outputResult.putParcelable(
7524 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7525 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7526 outputResult);
7527 } else {
7528 callback.send(result.second, null);
7529 }
7530 }
7531 );
Hall Liu82694d52020-12-11 18:22:04 -08007532 });
7533 }
7534
7535 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007536 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007537 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007538 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539
7540 final long identity = Binder.clearCallingIdentity();
7541 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 ImsManager.getInstance(defaultPhone.getContext(),
7543 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007547 }
7548
7549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007550 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007551 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7553 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007554 return false;
7555 }
Svet Ganovb320e182015-04-16 12:30:10 -07007556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 final long identity = Binder.clearCallingIdentity();
7558 try {
7559 // Check the user preference and the system-level IMS setting. Even if the user has
7560 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7561 // In the long run, we may instead need to check if there exists a connection service
7562 // which can support video calling.
7563 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007564 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 return imsManager.isVtEnabledByPlatform()
7566 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7567 && imsManager.isVtEnabledByUser();
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007571 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007572
Andrew Leea1239f22015-03-02 17:44:07 -08007573 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7575 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007577 mApp, subId, callingPackage, callingFeatureId,
7578 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 return false;
7580 }
7581
7582 final long identity = Binder.clearCallingIdentity();
7583 try {
7584 CarrierConfigManager configManager =
7585 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007586 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
Andrew Leea1239f22015-03-02 17:44:07 -08007591 }
7592
7593 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007594 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007596 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 return false;
7598 }
7599
7600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 CarrierConfigManager configManager =
7603 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007604 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
Andrew Leea1239f22015-03-02 17:44:07 -08007609 }
7610
Andrew Lee9431b832015-03-09 18:46:45 -07007611 @Override
7612 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007613 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007614 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007615 }
7616
7617 @Override
7618 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 final long identity = Binder.clearCallingIdentity();
7620 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007621 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 } finally {
7623 Binder.restoreCallingIdentity(identity);
7624 }
Andrew Lee9431b832015-03-09 18:46:45 -07007625 }
7626
Hall Liuf6668912018-10-31 17:05:23 -07007627 /**
7628 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7629 * support for the feature and device firmware support.
7630 *
7631 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7632 */
7633 @Override
7634 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007636 final Phone phone = getPhone(subscriptionId);
7637 if (phone == null) {
7638 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7639 return false;
7640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007641 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007642 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7644 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007645 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 return isCarrierSupported && isDeviceSupported;
7647 } finally {
7648 Binder.restoreCallingIdentity(identity);
7649 }
Hall Liu98187582018-01-22 19:15:32 -08007650 }
7651
Hall Liuf6668912018-10-31 17:05:23 -07007652 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007653 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7654 * RTT setting, will return true if the device and carrier both support RTT.
7655 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007656 */
7657 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658 final long identity = Binder.clearCallingIdentity();
7659 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007660 boolean isRttSupported = isRttSupported(subscriptionId);
7661 boolean isUserRttSettingOn = Settings.Secure.getInt(
7662 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7663 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7664 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7665 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 } finally {
7667 Binder.restoreCallingIdentity(identity);
7668 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007669 }
7670
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007671 @Deprecated
7672 @Override
7673 public String getDeviceId(String callingPackage) {
7674 return getDeviceIdWithFeature(callingPackage, null);
7675 }
7676
Sanket Padawe7310cc72015-01-14 09:53:20 -08007677 /**
7678 * Returns the unique device ID of phone, for example, the IMEI for
7679 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7680 *
7681 * <p>Requires Permission:
7682 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7683 */
7684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007685 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007686 try {
7687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7688 } catch (SecurityException se) {
7689 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7690 throw new SecurityException("Package " + callingPackage + " does not belong to "
7691 + Binder.getCallingUid());
7692 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007693 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007694 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007695 return null;
7696 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007697 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007698 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007699 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007700 return null;
7701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
7705 return phone.getDeviceId();
7706 } finally {
7707 Binder.restoreCallingIdentity(identity);
7708 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007709 }
7710
Ping Sunc67b7c22016-03-02 19:16:45 +08007711 /**
7712 * {@hide}
7713 * Returns the IMS Registration Status on a particular subid
7714 *
7715 * @param subId
7716 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007717 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007718 Phone phone = getPhone(subId);
7719 if (phone != null) {
7720 return phone.isImsRegistered();
7721 } else {
7722 return false;
7723 }
7724 }
7725
Santos Cordon7a1885b2015-02-03 11:15:19 -08007726 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007727 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007728 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007730 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007731 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7732 }
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
7738 }
7739 }
7740
7741 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007742 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007743 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007744 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007745 mApp,
7746 subscriptionId,
7747 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007748 final long identity = Binder.clearCallingIdentity();
7749 try {
7750 Phone phone = getPhone(subscriptionId);
7751 if (phone == null) {
7752 return null;
7753 }
7754 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7755 } finally {
7756 Binder.restoreCallingIdentity(identity);
7757 }
7758 }
7759
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007760 /**
7761 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007762 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007763 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 Phone phone = getPhone(subId);
7767 if (phone != null) {
7768 return phone.isWifiCallingEnabled();
7769 } else {
7770 return false;
7771 }
7772 } finally {
7773 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007774 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007775 }
7776
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007777 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007778 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007779 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007780 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 final long identity = Binder.clearCallingIdentity();
7782 try {
7783 Phone phone = getPhone(subId);
7784 if (phone != null) {
7785 return phone.isVideoEnabled();
7786 } else {
7787 return false;
7788 }
7789 } finally {
7790 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007791 }
7792 }
7793
7794 /**
7795 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7796 * defined in {@link ImsRegistrationImplBase}.
7797 */
7798 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 Phone phone = getPhone(subId);
7802 if (phone != null) {
7803 return phone.getImsRegistrationTech();
7804 } else {
7805 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7806 }
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007809 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007810 }
7811
Stuart Scott8eef64f2015-04-08 15:13:54 -07007812 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007813 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007814 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007815 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7816 return;
7817 }
Kai Shif70f46f2021-03-03 13:59:46 -08007818 Phone defaultPhone = getDefaultPhone();
7819 if (defaultPhone != null) {
7820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7821 mApp, getDefaultPhone().getSubId(), "factoryReset");
7822 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007823 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007824
Svet Ganovcc087f82015-05-12 20:35:54 -07007825 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007826 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7827 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007828 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007829 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007830 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007831 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007832 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007833 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007834 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007835 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007836 // There has been issues when Sms raw table somehow stores orphan
7837 // fragments. They lead to garbled message when new fragments come
7838 // in and combined with those stale ones. In case this happens again,
7839 // user can reset all network settings which will clean up this table.
7840 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007841 // Clean up IMS settings as well here.
7842 int slotId = getSlotIndex(subId);
7843 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7844 ImsManager.getInstance(mApp, slotId).factoryReset();
7845 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007846
Kai Shif70f46f2021-03-03 13:59:46 -08007847 if (defaultPhone == null) {
7848 return;
7849 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007850 // Erase modem config if erase modem on network setting is enabled.
7851 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7852 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7853 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007854 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007855 }
Kai Shif70f46f2021-03-03 13:59:46 -08007856
7857 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007858 } finally {
7859 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007860 }
7861 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007862
SongFerngWangfd89b102021-05-27 22:44:54 +08007863 @VisibleForTesting
7864 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7865 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7866 return;
7867 }
7868 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7869 RILConstants.PREFERRED_NETWORK_MODE);
7870 SubscriptionManager.setSubscriptionProperty(subId,
7871 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7872 "user=" + defaultNetworkType);
7873 phone.loadAllowedNetworksFromSubscriptionDatabase();
7874 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7875 defaultNetworkType, null);
7876 }
7877
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007878 private void cleanUpSmsRawTable(Context context) {
7879 ContentResolver resolver = context.getContentResolver();
7880 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7881 resolver.delete(uri, null, null);
7882 }
7883
Narayan Kamath1c496c22015-04-16 14:40:19 +01007884 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007885 public String getSimLocaleForSubscriber(int subId) {
7886 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7887 final Phone phone = getPhone(subId);
7888 if (phone == null) {
7889 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007890 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892 final long identity = Binder.clearCallingIdentity();
7893 try {
Jack Yu285100e2022-12-02 22:48:35 -08007894 SubscriptionInfo info;
7895 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7896 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7897 phone.getContext().getOpPackageName(),
7898 phone.getContext().getAttributionTag());
7899 if (info == null) {
7900 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7901 return null;
7902 }
7903 } else {
7904 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7905 phone.getContext().getOpPackageName(),
7906 phone.getContext().getAttributionTag());
7907 if (info == null) {
7908 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7909 return null;
7910 }
chen xu6291c472019-02-04 12:55:53 -08007911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 // Try and fetch the locale from the carrier properties or from the SIM language
7913 // preferences (EF-PL and EF-LI)...
7914 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007916 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7917 if (localeFromDefaultSim != null) {
7918 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7919 if (DBG) log("Using locale from subId: " + subId + " locale: "
7920 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007921 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007922 } else {
7923 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 }
7925 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 // The SIM language preferences only store a language (e.g. fr = French), not an
7928 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7929 // the SIM and carrier preferences does not include a country we add the country
7930 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007931 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007933 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007934 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 }
7936
7937 if (DBG) log("No locale found - returning null");
7938 return null;
7939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007942 }
7943
tom hsu0b59d292022-09-29 23:49:21 +08007944 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007945 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007946 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007947 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007948 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007949 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7950 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007951 Locale.forLanguageTag(localeTag).getCountry())) {
7952 return localeTag;
7953 }
7954 }
7955 return inputLocale.toLanguageTag();
7956 }
7957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 /**
7959 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7960 */
7961 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007962 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7963 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7964 mApp.getOpPackageName(), mApp.getAttributionTag());
7965 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007966 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007967 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007968 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007969
Gary Jian3aa9a762022-01-24 16:41:19 +08007970 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7971 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007972
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007973 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007974 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7975 * representing the state of the modem.
7976 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007977 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7978 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007979 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007980 */
7981 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007982 public void requestModemActivityInfo(ResultReceiver result) {
7983 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985
7986 final long identity = Binder.clearCallingIdentity();
7987 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007988 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 } finally {
7990 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007991 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007992 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007993
Siddharth Rayb8114062018-06-17 15:02:38 -07007994 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7995 // less than total activity duration.
7996 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7997 if (info == null) {
7998 return false;
7999 }
8000 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008001 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
8002 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8003
Siddharth Rayb8114062018-06-17 15:02:38 -07008004 return (info.isValid()
8005 && (info.getSleepTimeMillis() <= activityDurationMs)
8006 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07008007 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07008008 && (totalTxTimeMs <= activityDurationMs));
8009 }
8010
Gary Jian3aa9a762022-01-24 16:41:19 +08008011 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8012 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8013 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8014 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8015
8016 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8017 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8018 }
8019
8020 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8021 mLastModemActivityInfo.setReceiveTimeMillis(
8022 rat,
8023 freq,
8024 info.getReceiveTimeMillis(rat, freq)
8025 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8026 }
8027
8028 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8029 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8030 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8031 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8032
8033 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8034 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8035 }
8036 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8037 mLastModemActivityInfo.setReceiveTimeMillis(
8038 rat,
8039 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8040 }
8041
8042 /**
8043 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8044 * @param info recent ModemActivityInfo
8045 */
8046 private void mergeModemActivityInfo(ModemActivityInfo info) {
8047 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008048 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008049 boolean matched;
8050 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8051 matched = false;
8052 int rat = info.getSpecificInfoRat(i);
8053 int freq = info.getSpecificInfoFrequencyRange(i);
8054 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8055 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8056 //if it already exists
8057 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8058 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8059 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8060 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8061 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8062 updateLastModemActivityInfo(info, rat, freq);
8063 matched = true;
8064 }
8065 } else {
8066 updateLastModemActivityInfo(info, rat);
8067 matched = true;
8068 }
8069 }
8070 }
8071
8072 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008073 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008074 new ActivityStatsTechSpecificInfo(
8075 rat,
8076 freq,
8077 info.getTransmitTimeMillis(rat, freq),
8078 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008079 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008080 }
8081 }
8082 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8083 mLastModemActivitySpecificInfo =
8084 new ActivityStatsTechSpecificInfo[merged.size()];
8085 merged.toArray(mLastModemActivitySpecificInfo);
8086
8087 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8088 mLastModemActivityInfo.setSleepTimeMillis(
8089 info.getSleepTimeMillis()
8090 + mLastModemActivityInfo.getSleepTimeMillis());
8091 mLastModemActivityInfo.setIdleTimeMillis(
8092 info.getIdleTimeMillis()
8093 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008094
8095 mLastModemActivityInfo =
8096 new ModemActivityInfo(
8097 mLastModemActivityInfo.getTimestampMillis(),
8098 mLastModemActivityInfo.getSleepTimeMillis(),
8099 mLastModemActivityInfo.getIdleTimeMillis(),
8100 mLastModemActivitySpecificInfo);
8101 }
8102
8103 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8104 ActivityStatsTechSpecificInfo[] info) {
8105 int infoSize = info.length;
8106 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8107 for (int i = 0; i < infoSize; i++) {
8108 ret[i] = new ActivityStatsTechSpecificInfo(
8109 info[i].getRat(), info[i].getFrequencyRange(),
8110 info[i].getTransmitTimeMillis(),
8111 (int) info[i].getReceiveTimeMillis());
8112 }
8113 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008114 }
8115
Jack Yu85bd38a2015-11-09 11:34:32 -08008116 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008117 * Returns the service state information on specified subscription.
8118 */
8119 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008120 public ServiceState getServiceStateForSubscriber(int subId,
8121 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8122 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008124 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008125 return null;
8126 }
8127
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008128 boolean hasFinePermission = false;
8129 boolean hasCoarsePermission = false;
8130 if (!renounceFineLocationAccess) {
8131 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8132 LocationAccessPolicy.checkLocationPermission(mApp,
8133 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8134 .setCallingPackage(callingPackage)
8135 .setCallingFeatureId(callingFeatureId)
8136 .setCallingPid(Binder.getCallingPid())
8137 .setCallingUid(Binder.getCallingUid())
8138 .setMethod("getServiceStateForSubscriber")
8139 .setLogAsInfo(true)
8140 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8141 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8142 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8143 .build());
8144 hasFinePermission =
8145 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8146 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008147
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008148 if (!renounceCoarseLocationAccess) {
8149 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8150 LocationAccessPolicy.checkLocationPermission(mApp,
8151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8152 .setCallingPackage(callingPackage)
8153 .setCallingFeatureId(callingFeatureId)
8154 .setCallingPid(Binder.getCallingPid())
8155 .setCallingUid(Binder.getCallingUid())
8156 .setMethod("getServiceStateForSubscriber")
8157 .setLogAsInfo(true)
8158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8159 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8160 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8161 .build());
8162 hasCoarsePermission =
8163 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8164 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008165
Jack Yu479f40e2020-10-27 21:29:25 -07008166 final Phone phone = getPhone(subId);
8167 if (phone == null) {
8168 return null;
8169 }
8170
Jordan Liu0f2bc442020-11-18 16:47:37 -08008171 final long identity = Binder.clearCallingIdentity();
8172
Jack Yu479f40e2020-10-27 21:29:25 -07008173 boolean isCallingPackageDataService = phone.getDataServicePackages()
8174 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008176 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008177 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8178 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8179 .getSubscriptionInfoInternal(subId);
8180 if (subInfo == null || !subInfo.isActive()) {
8181 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8182 + "subId=" + subId);
8183 return null;
8184 }
8185 } else {
8186 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8187 callingFeatureId)) {
8188 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8189 + "subId=" + subId);
8190 return null;
8191 }
Jordan Liuc437b192020-08-17 10:59:12 -07008192 }
8193
Hall Liuf19c44f2018-11-27 14:38:17 -08008194 ServiceState ss = phone.getServiceState();
8195
8196 // Scrub out the location info in ServiceState depending on what level of access
8197 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008198 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008199 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8200 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008204 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008205
8206 /**
8207 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8208 *
8209 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8210 * voicemail ringtone.
8211 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8212 * PhoneAccount.
8213 */
8214 @Override
8215 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 final long identity = Binder.clearCallingIdentity();
8217 try {
8218 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8219 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008220 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8224 } finally {
8225 Binder.restoreCallingIdentity(identity);
8226 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008227 }
8228
8229 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008230 * Sets the per-account voicemail ringtone.
8231 *
8232 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8233 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8234 *
8235 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8236 * voicemail ringtone.
8237 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8238 * PhoneAccount.
8239 */
8240 @Override
8241 public void setVoicemailRingtoneUri(String callingPackage,
8242 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008243 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008244 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008245 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8246 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8248 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8249 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251
8252 final long identity = Binder.clearCallingIdentity();
8253 try {
8254 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8255 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008256 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 }
8258 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008261 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008262 }
8263
8264 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008265 * Returns whether vibration is set for voicemail notification in Phone settings.
8266 *
8267 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8268 * voicemail vibration setting.
8269 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8270 */
8271 @Override
8272 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 final long identity = Binder.clearCallingIdentity();
8274 try {
8275 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8276 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008277 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008284 }
8285
Youhan Wange64578a2016-05-02 15:32:42 -07008286 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008287 * Sets the per-account voicemail vibration.
8288 *
8289 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8290 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8291 *
8292 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8293 * voicemail vibration setting.
8294 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8295 * specific PhoneAccount.
8296 */
8297 @Override
8298 public void setVoicemailVibrationEnabled(String callingPackage,
8299 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008300 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008301 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008302 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8303 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8305 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8306 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008307 }
8308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8312 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008313 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 }
8315 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8316 } finally {
8317 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008318 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008319 }
8320
8321 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008322 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8323 *
8324 * @throws SecurityException if the caller does not have the required permission
8325 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008326 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008327 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008328 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008329 }
8330
8331 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008332 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8333 * permission.
8334 *
8335 * @throws SecurityException if the caller does not have the required permission
8336 */
8337 private void enforceSendSmsPermission() {
8338 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8339 }
8340
8341 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008342 * Make sure either called from same process as self (phone) or IPC caller has interact across
8343 * users permission.
8344 *
8345 * @throws SecurityException if the caller does not have the required permission
8346 */
8347 private void enforceInteractAcrossUsersPermission(String message) {
8348 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8349 }
8350
8351 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008352 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008353 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008354 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008355 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008356 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357 final long identity = Binder.clearCallingIdentity();
8358 try {
8359 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008360 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361 if (componentName == null) {
8362 throw new SecurityException(
8363 "Caller not current active visual voicemail package[null]");
8364 }
8365 String vvmPackage = componentName.getPackageName();
8366 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008367 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 }
8369 } finally {
8370 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008371 }
8372 }
8373
8374 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008375 * Return the application ID for the app type.
8376 *
8377 * @param subId the subscription ID that this request applies to.
8378 * @param appType the uicc app type.
8379 * @return Application ID for specificied app type, or null if no uicc.
8380 */
8381 @Override
8382 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008383 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008384 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385
8386 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008387 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 if (phone == null) {
8389 return null;
8390 }
8391 String aid = null;
8392 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008393 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 .getApplicationByType(appType).getAid();
8395 } catch (Exception e) {
8396 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8397 }
8398 return aid;
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008401 }
Youhan Wange64578a2016-05-02 15:32:42 -07008402 }
8403
Youhan Wang4001d252016-05-11 10:29:41 -07008404 /**
8405 * Return the Electronic Serial Number.
8406 *
8407 * @param subId the subscription ID that this request applies to.
8408 * @return ESN or null if error.
8409 */
8410 @Override
8411 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008412 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008413 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414
8415 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008416 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008417 if (phone == null) {
8418 return null;
8419 }
8420 String esn = null;
8421 try {
8422 esn = phone.getEsn();
8423 } catch (Exception e) {
8424 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8425 }
8426 return esn;
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008429 }
Youhan Wang4001d252016-05-11 10:29:41 -07008430 }
8431
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008432 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008433 * Return the Preferred Roaming List Version.
8434 *
8435 * @param subId the subscription ID that this request applies to.
8436 * @return PRLVersion or null if error.
8437 */
8438 @Override
8439 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008440 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008441 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442
8443 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008444 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445 if (phone == null) {
8446 return null;
8447 }
8448 String cdmaPrlVersion = null;
8449 try {
8450 cdmaPrlVersion = phone.getCdmaPrlVersion();
8451 } catch (Exception e) {
8452 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8453 }
8454 return cdmaPrlVersion;
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008457 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008458 }
8459
8460 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008461 * Get snapshot of Telephony histograms
8462 * @return List of Telephony histograms
8463 * @hide
8464 */
8465 @Override
8466 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8468 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469
8470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 return RIL.getTelephonyRILTimingHistograms();
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008476 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008477
8478 /**
8479 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008480 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8481 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008482 * Require system privileges. In the future we may add this to carrier APIs.
8483 *
Michele Berionne482f8202018-11-27 18:57:59 -08008484 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008485 */
8486 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008487 @TelephonyManager.SetCarrierRestrictionResult
8488 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008489 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008491
Michele Berionne482f8202018-11-27 18:57:59 -08008492 if (carrierRestrictionRules == null) {
8493 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008494 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008496 final long identity = Binder.clearCallingIdentity();
8497 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008498 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008499 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008500 } finally {
8501 Binder.restoreCallingIdentity(identity);
8502 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008503 }
8504
8505 /**
8506 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008507 * Get the allowed carrier list and the excluded carrier list, including the priority between
8508 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008509 * Require system privileges. In the future we may add this to carrier APIs.
8510 *
Michele Berionne482f8202018-11-27 18:57:59 -08008511 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008512 */
8513 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008514 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008515 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008516 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517
8518 final long identity = Binder.clearCallingIdentity();
8519 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008520 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8521 if (response instanceof CarrierRestrictionRules) {
8522 return (CarrierRestrictionRules) response;
8523 }
8524 // Response is an Exception of some kind,
8525 // which is signalled to the user as a NULL retval
8526 return null;
8527 } catch (Exception e) {
8528 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8529 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008533 }
8534
fionaxu59545b42016-05-25 15:53:37 -07008535 /**
fionaxu59545b42016-05-25 15:53:37 -07008536 * Action set from carrier signalling broadcast receivers to enable/disable radio
8537 * @param subId the subscription ID that this action applies to.
8538 * @param enabled control enable or disable radio.
8539 * {@hide}
8540 */
8541 @Override
8542 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8543 enforceModifyPermission();
8544 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545
8546 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008547 if (phone == null) {
8548 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8549 return;
8550 }
8551 try {
8552 phone.carrierActionSetRadioEnabled(enabled);
8553 } catch (Exception e) {
8554 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555 } finally {
8556 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008557 }
8558 }
8559
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008560 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008561 * Enable or disable Voice over NR (VoNR)
8562 * @param subId the subscription ID that this action applies to.
8563 * @param enabled enable or disable VoNR.
8564 * @return operation result.
8565 */
8566 @Override
8567 public int setVoNrEnabled(int subId, boolean enabled) {
8568 enforceModifyPermission();
8569 final Phone phone = getPhone(subId);
8570
8571 final long identity = Binder.clearCallingIdentity();
8572 if (phone == null) {
8573 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8574 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8575 }
8576
8577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8578 try {
8579 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8580 workSource);
8581 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008582
8583 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8584 if (DBG) {
8585 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8586 }
8587 SubscriptionManager.setSubscriptionProperty(
8588 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8589 (enabled ? "1" : "0"));
8590 }
8591
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008592 return result;
8593 } finally {
8594 Binder.restoreCallingIdentity(identity);
8595 }
8596 }
8597
8598 /**
8599 * Is voice over NR enabled
8600 * @return true if VoNR is enabled else false
8601 */
8602 @Override
8603 public boolean isVoNrEnabled(int subId) {
8604 enforceReadPrivilegedPermission("isVoNrEnabled");
8605 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8606 final long identity = Binder.clearCallingIdentity();
8607 try {
8608 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8609 null, subId, workSource);
8610 if (DBG) log("isVoNrEnabled: " + isEnabled);
8611 return isEnabled;
8612 } finally {
8613 Binder.restoreCallingIdentity(identity);
8614 }
8615 }
8616
8617 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008618 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8619 * network status based on which carrier apps could apply actions accordingly,
8620 * enable/disable default url handler for example.
8621 *
8622 * @param subId the subscription ID that this action applies to.
8623 * @param report control start/stop reporting the default network status.
8624 * {@hide}
8625 */
8626 @Override
8627 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8628 enforceModifyPermission();
8629 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630
8631 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008632 if (phone == null) {
8633 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8634 return;
8635 }
8636 try {
8637 phone.carrierActionReportDefaultNetworkStatus(report);
8638 } catch (Exception e) {
8639 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008640 } finally {
8641 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008642 }
8643 }
8644
8645 /**
fionaxud9622282017-07-17 17:51:30 -07008646 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8647 * @param subId the subscription ID that this action applies to.
8648 * {@hide}
8649 */
8650 @Override
8651 public void carrierActionResetAll(int subId) {
8652 enforceModifyPermission();
8653 final Phone phone = getPhone(subId);
8654 if (phone == null) {
8655 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8656 return;
8657 }
8658 try {
8659 phone.carrierActionResetAll();
8660 } catch (Exception e) {
8661 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8662 }
8663 }
8664
8665 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008666 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8667 * bug report is being generated.
8668 */
8669 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008670 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008671 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8672 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008673 writer.println("Permission Denial: can't dump Phone from pid="
8674 + Binder.getCallingPid()
8675 + ", uid=" + Binder.getCallingUid()
8676 + "without permission "
8677 + android.Manifest.permission.DUMP);
8678 return;
8679 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008680 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008681 }
Jack Yueb89b242016-06-22 13:27:47 -07008682
Brad Ebingerdac2f002018-04-03 15:17:52 -07008683 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008684 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8685 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8686 @NonNull String[] args) {
8687 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8688 this, in.getFileDescriptor(), out.getFileDescriptor(),
8689 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008690 }
8691
Jack Yueb89b242016-06-22 13:27:47 -07008692 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008693 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008694 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008695 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008696 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008697 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008698 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008699 */
8700 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008701 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008702 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008703 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8704 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8705 try {
8706 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008707 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008708 } catch (SecurityException se) {
8709 enforceModifyPermission();
8710 }
8711 } else {
8712 enforceModifyPermission();
8713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008714
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
8717 Phone phone = getPhone(subId);
8718 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008719 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8720 phone.carrierActionSetMeteredApnsEnabled(enabled);
8721 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008722 phone.getDataSettingsManager().setDataEnabled(
8723 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008725 }
8726 } finally {
8727 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008728 }
8729 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008730
8731 /**
8732 * Get Client request stats
8733 * @return List of Client Request Stats
8734 * @hide
8735 */
8736 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008737 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8738 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008740 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008741 return null;
8742 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008743 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008745 final long identity = Binder.clearCallingIdentity();
8746 try {
8747 if (phone != null) {
8748 return phone.getClientRequestStats();
8749 }
8750
8751 return null;
8752 } finally {
8753 Binder.restoreCallingIdentity(identity);
8754 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008755 }
8756
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008757 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008758 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008759 if (uid == Process.ROOT_UID && packageName == null) {
8760 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8761 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8762 // exception. ROOT_UID seems not to have a valid package name returned by
8763 // PackageManager, so just fake it here to avoid issues when running telephony shell
8764 // commands that plumb through the RIL as root, like so:
8765 // $ adb root
8766 // $ adb shell cmd phone ...
8767 packageName = "root";
8768 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008769 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008770 }
Jack Yueb4124c2017-02-16 15:32:43 -08008771
8772 /**
Grace Chen70990072017-03-24 17:21:30 -07008773 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008774 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008775 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008776 * @param state State of SIM (power down, power up, pass through)
8777 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8778 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8779 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008780 *
8781 **/
8782 @Override
Grace Chen70990072017-03-24 17:21:30 -07008783 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008784 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008785 Phone phone = PhoneFactory.getPhone(slotIndex);
8786
vagdeviaf9a5b92018-08-15 16:01:53 -07008787 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008789 final long identity = Binder.clearCallingIdentity();
8790 try {
8791 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008792 phone.setSimPowerState(state, null, workSource);
8793 }
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
8796 }
8797 }
8798
8799 /**
8800 * Set SIM card power state.
8801 *
8802 * @param slotIndex SIM slot id.
8803 * @param state State of SIM (power down, power up, pass through)
8804 * @param callback callback to trigger after success or failure
8805 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8806 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8807 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8808 *
8809 **/
8810 @Override
8811 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8812 IIntegerConsumer callback) {
8813 enforceModifyPermission();
8814 Phone phone = PhoneFactory.getPhone(slotIndex);
8815
8816 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8817
8818 final long identity = Binder.clearCallingIdentity();
8819 try {
8820 if (phone != null) {
8821 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8822 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008823 }
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008826 }
8827 }
Shuo Qiandd210312017-04-12 22:11:33 +00008828
Tyler Gunn65d45c22017-06-05 11:22:26 -07008829 private boolean isUssdApiAllowed(int subId) {
8830 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008831 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008832 if (configManager == null) {
8833 return false;
8834 }
8835 PersistableBundle pb = configManager.getConfigForSubId(subId);
8836 if (pb == null) {
8837 return false;
8838 }
8839 return pb.getBoolean(
8840 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8841 }
8842
Shuo Qiandd210312017-04-12 22:11:33 +00008843 /**
8844 * Check if phone is in emergency callback mode
8845 * @return true if phone is in emergency callback mode
8846 * @param subId sub id
8847 */
goneil9c5f4872017-12-05 14:07:56 -08008848 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008849 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008850 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008851 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008852
8853 final long identity = Binder.clearCallingIdentity();
8854 try {
8855 if (phone != null) {
8856 return phone.isInEcm();
8857 } else {
8858 return false;
8859 }
8860 } finally {
8861 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008862 }
8863 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008864
8865 /**
8866 * Get the current signal strength information for the given subscription.
8867 * Because this information is not updated when the device is in a low power state
8868 * it should not be relied-upon to be current.
8869 * @param subId Subscription index
8870 * @return the most recent cached signal strength info from the modem
8871 */
8872 @Override
8873 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008874 final long identity = Binder.clearCallingIdentity();
8875 try {
8876 Phone p = getPhone(subId);
8877 if (p == null) {
8878 return null;
8879 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 return p.getSignalStrength();
8882 } finally {
8883 Binder.restoreCallingIdentity(identity);
8884 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008885 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008886
Pengquan Meng77b7f132018-08-22 14:49:57 -07008887 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008888 * Get the current modem radio state for the given slot.
8889 * @param slotIndex slot index.
8890 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008891 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008892 * @return the current radio power state from the modem
8893 */
8894 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008895 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008896 Phone phone = PhoneFactory.getPhone(slotIndex);
8897 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8899 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008900 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8901 }
8902
8903 final long identity = Binder.clearCallingIdentity();
8904 try {
8905 return phone.getRadioPowerState();
8906 } finally {
8907 Binder.restoreCallingIdentity(identity);
8908 }
8909 }
8910 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8911 }
8912
8913 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008914 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8915 *
8916 * <p>Requires one of the following permissions:
8917 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008918 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008919 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8920 * privileges.
8921 *
8922 * @param subId subscription id
8923 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8924 * {@code false}.
8925 */
8926 @Override
8927 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008928 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008929 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008930 try {
8931 mApp.enforceCallingOrSelfPermission(
8932 android.Manifest.permission.ACCESS_NETWORK_STATE,
8933 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008934 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008935 mApp.enforceCallingOrSelfPermission(
8936 permission.READ_BASIC_PHONE_STATE, functionName);
8937 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008938 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008939 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008940 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008941 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008942
Pengquan Menga1bb6272018-09-06 09:59:22 -07008943 boolean isEnabled = false;
8944 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008945 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008946 Phone phone = getPhone(subId);
8947 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008948 } finally {
8949 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008950 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008951 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008952 }
8953
8954
8955 /**
8956 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8957 *
8958 * <p> Requires permission:
8959 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8960 * privileges.
8961 *
8962 * @param subId subscription id
8963 * @param isEnabled {@code true} means enable, {@code false} means disable.
8964 */
8965 @Override
8966 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8968 mApp, subId, "setDataRoamingEnabled");
8969
Pengquan Menga1bb6272018-09-06 09:59:22 -07008970 final long identity = Binder.clearCallingIdentity();
8971 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008972 Phone phone = getPhone(subId);
8973 if (phone != null) {
8974 phone.setDataRoamingEnabled(isEnabled);
8975 }
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008978 }
8979 }
8980
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008981 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008982 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008983 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008984 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008985 mApp, subId, "isManualNetworkSelectionAllowed");
8986
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008987 boolean isAllowed = true;
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008990 Phone phone = getPhone(subId);
8991 if (phone != null) {
8992 isAllowed = phone.isCspPlmnEnabled();
8993 }
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 return isAllowed;
8998 }
8999
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009000 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9001 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009002 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009003 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009004 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009005 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9006 if (phone == null) {
9007 return false;
9008 }
9009 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9010 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9011 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009012 }
9013
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009014 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009015 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009016 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009017 mApp.getSystemService(AppOpsManager.class)
9018 .checkPackage(Binder.getCallingUid(), callingPackage);
9019
Jordan Liu1e142fc2019-04-22 15:10:43 -07009020 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009021 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009022 try {
9023 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009024 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009025 } catch (SecurityException e) {
9026 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9027 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009028 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009029 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009030 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009031 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009032 }
sandeepjsb6c87872021-09-27 15:34:44 +00009033 // checking compatibility, if calling app's target SDK is T and beyond.
9034 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9035 Binder.getCallingUid())) {
9036 isIccIdAccessRestricted = true;
9037 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009038 final long identity = Binder.clearCallingIdentity();
9039 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009040 UiccController uiccController = UiccController.getInstance();
9041 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009042 if (hasReadPermission) {
9043 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009044 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009045
9046 // Remove private info if the caller doesn't have access
9047 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9048 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009049 //setting the value after compatibility check
9050 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009051 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9052 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009053 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009054 if (card == null) {
9055 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009056 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009057 continue;
9058 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009059 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9060 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009061 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009062 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009063 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009064 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9065 for (UiccPortInfo portInfo : portInfos) {
9066 UiccPort port = uiccController.getUiccPortForSlot(
9067 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9068 if (port == null) {
9069 // assume no access if port is null
9070 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9071 continue;
9072 }
9073 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9074 uiccPortInfos.add(portInfo);
9075 } else {
9076 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9077 }
9078 }
9079 filteredInfos.add(new UiccCardInfo(
9080 cardInfo.isEuicc(),
9081 cardInfo.getCardId(),
9082 null,
9083 cardInfo.getPhysicalSlotIndex(),
9084 cardInfo.isRemovable(),
9085 cardInfo.isMultipleEnabledProfilesSupported(),
9086 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009087 }
9088 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
9093
sandeepjsb6c87872021-09-27 15:34:44 +00009094 /**
9095 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9096 * generally private and require carrier privileges to view.
9097 *
9098 * @hide
9099 */
9100 @NonNull
9101 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9102 List<UiccPortInfo> portinfo = new ArrayList<>();
9103 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9104 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9105 }
9106 return new UiccCardInfo(
9107 cardInfo.isEuicc(),
9108 cardInfo.getCardId(),
9109 null,
9110 cardInfo.getPhysicalSlotIndex(),
9111 cardInfo.isRemovable(),
9112 cardInfo.isMultipleEnabledProfilesSupported(),
9113 portinfo
9114 );
9115 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009116
sandeepjsb6c87872021-09-27 15:34:44 +00009117 /**
9118 * @hide
9119 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9120 * These values are generally private and require carrier privileges to view.
9121 */
9122 @NonNull
9123 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9124 return new UiccPortInfo(
9125 UiccPortInfo.ICCID_REDACTED,
9126 portInfo.getPortIndex(),
9127 portInfo.getLogicalSlotIndex(),
9128 portInfo.isActive()
9129 );
9130 }
9131 @Override
9132 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009133 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009134 mApp.getSystemService(AppOpsManager.class)
9135 .checkPackage(Binder.getCallingUid(), callingPackage);
9136
sandeepjsb6c87872021-09-27 15:34:44 +00009137 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009138
Aman Guptaf3c90b32022-03-17 04:54:16 +00009139 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9140 // we are reading iccId which is PII data.
9141 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009142
9143 // checking compatibility, if calling app's target SDK is T and beyond.
9144 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9145 Binder.getCallingUid())) {
9146 isLogicalSlotAccessRestricted = true;
9147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009151 if (slots == null || slots.length == 0) {
9152 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153 return null;
9154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009155 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9156 for (int i = 0; i < slots.length; i++) {
9157 UiccSlot slot = slots[i];
9158 if (slot == null) {
9159 continue;
9160 }
9161
Jordan Liu7be7e652019-05-06 18:55:02 +00009162 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009163 UiccCard card = slot.getUiccCard();
9164 if (card != null) {
9165 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009166 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009167 cardId = slot.getEid();
9168 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009169 // If cardId is null, use iccId of default port as cardId.
9170 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009172 }
9173
Jordan Liu857451f2019-05-09 16:35:35 -07009174 if (cardId != null) {
9175 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9176 // if cardId is an EID, it's all digits so this is fine
9177 cardId = IccUtils.stripTrailingFs(cardId);
9178 }
9179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009180 int cardState = 0;
9181 switch (slot.getCardState()) {
9182 case CARDSTATE_ABSENT:
9183 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9184 break;
9185 case CARDSTATE_PRESENT:
9186 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9187 break;
9188 case CARDSTATE_ERROR:
9189 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9190 break;
9191 case CARDSTATE_RESTRICTED:
9192 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9193 break;
9194 default:
9195 break;
9196
9197 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009198 List<UiccPortInfo> portInfos = new ArrayList<>();
9199 int[] portIndexes = slot.getPortList();
9200 for (int portIdx : portIndexes) {
9201 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009202 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009203 portInfos.add(new UiccPortInfo(iccId, portIdx,
9204 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009206 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009207 slot.isEuicc(),
9208 cardId,
9209 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009210 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009211 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009212 //setting the value after compatibility check
9213 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009214 }
9215 return infos;
9216 } finally {
9217 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009218 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009219 }
9220
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009221 /* Returns null if doesn't have read permission or carrier privilege access. */
9222 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9223 boolean hasReadPermission) {
9224 String iccId = slot.getIccId(portIndex);
9225 if (hasReadPermission) { // if has read permission
9226 return iccId;
9227 } else {
9228 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9229 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9230 // if no read permission, checking carrier privilege access
9231 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9232 return iccId;
9233 }
9234 }
9235 }
9236 // No read permission or carrier privilege access.
9237 return UiccPortInfo.ICCID_REDACTED;
9238 }
9239
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009240 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009241 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009242 public boolean switchSlots(int[] physicalSlots) {
9243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009247 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9248 for (int i = 0; i < physicalSlots.length; i++) {
9249 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9250 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9251 physicalSlots[i], i));
9252 }
9253 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009257 }
Jack Yu4c988042018-02-27 15:30:01 -08009258
9259 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009260 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9261 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9262 enforceModifyPermission();
9263
9264 final long identity = Binder.clearCallingIdentity();
9265 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009266 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
9272 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009273 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 return UiccController.getInstance().getCardIdForDefaultEuicc();
9277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
9281
Pengquan Meng85728fb2018-03-12 16:31:21 -07009282 /**
goneil47ffb6e2018-04-06 15:40:58 -07009283 * A test API to reload the UICC profile.
9284 *
9285 * <p>Requires that the calling app has permission
9286 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9287 * @hide
9288 */
9289 @Override
9290 public void refreshUiccProfile(int subId) {
9291 enforceModifyPermission();
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 Phone phone = getPhone(subId);
9296 if (phone == null) {
9297 return;
9298 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009299 UiccPort uiccPort = phone.getUiccPort();
9300 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009301 return;
9302 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009303 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009304 if (uiccProfile == null) {
9305 return;
9306 }
9307 uiccProfile.refresh();
9308 } finally {
9309 Binder.restoreCallingIdentity(identity);
9310 }
9311 }
9312
9313 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009314 * Returns false if the mobile data is disabled by default, otherwise return true.
9315 */
9316 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009317 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009318 }
9319
9320 /**
9321 * Returns true if the data roaming is enabled by default, i.e the system property
9322 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9323 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9324 */
9325 private boolean getDefaultDataRoamingEnabled(int subId) {
9326 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009327 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009328 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009329 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9330 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9331 return isDataRoamingEnabled;
9332 }
9333
9334 /**
9335 * Returns the default network type for the given {@code subId}, if the default network type is
9336 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9337 */
9338 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009339 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009340 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009341 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9342 return list.get(phoneId);
9343 }
9344 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009345 }
fionaxua13278b2018-03-21 00:08:13 -07009346
9347 @Override
9348 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009349 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009350 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009351
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 final Phone phone = getPhone(subId);
9355 if (phone == null) {
9356 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9357 return;
9358 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009359 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9360 if (cpt != null) {
9361 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9362 }
9363 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009364 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9365 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009366 if (carrierPrivilegeRules == null) {
9367 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9368 } else {
9369 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009371 } finally {
9372 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009373 }
fionaxua13278b2018-03-21 00:08:13 -07009374 }
9375
9376 @Override
9377 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009378 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009379
9380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 final Phone phone = getPhone(subId);
9383 if (phone == null) {
9384 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9385 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9386 }
9387 return phone.getCarrierIdListVersion();
9388 } finally {
9389 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009390 }
fionaxua13278b2018-03-21 00:08:13 -07009391 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009392
9393 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009394 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9395 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009397 mApp, subId, callingPackage, callingFeatureId,
9398 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009399 return -1;
9400 }
9401
9402 final long identity = Binder.clearCallingIdentity();
9403 try {
9404 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009409
9410 @Override
9411 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009412 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009413 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009414 mApp, subId, "getCdmaRoamingMode");
9415
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9419 } finally {
9420 Binder.restoreCallingIdentity(identity);
9421 }
9422 }
9423
9424 @Override
9425 public boolean setCdmaRoamingMode(int subId, int mode) {
9426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9427 mApp, subId, "setCdmaRoamingMode");
9428
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
9431 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
9437 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009438 public int getCdmaSubscriptionMode(int subId) {
9439 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009440 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009441 mApp, subId, "getCdmaSubscriptionMode");
9442
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
9445 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
9449 }
9450
9451 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009452 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9454 mApp, subId, "setCdmaSubscriptionMode");
9455
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
9458 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9459 } finally {
9460 Binder.restoreCallingIdentity(identity);
9461 }
9462 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009463
sqianc5eccab2018-10-19 18:46:41 -07009464 @Override
sqian8c685422019-02-22 15:55:18 -08009465 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009466 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009468 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9469 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009470 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9471 }
9472 final long identity = Binder.clearCallingIdentity();
9473 try {
sqian854d44b2018-12-12 16:48:18 -08009474 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9475 for (Phone phone: PhoneFactory.getPhones()) {
9476 if (phone.getEmergencyNumberTracker() != null
9477 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9478 emergencyNumberListInternal.put(
9479 phone.getSubId(),
9480 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9481 }
sqian11b7a0e2018-12-05 18:48:28 -08009482 }
sqian854d44b2018-12-12 16:48:18 -08009483 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009484 } finally {
9485 Binder.restoreCallingIdentity(identity);
9486 }
sqianc5eccab2018-10-19 18:46:41 -07009487 }
9488
9489 @Override
sqian8c685422019-02-22 15:55:18 -08009490 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009491 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009492 if (!exactMatch) {
9493 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009494 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009495 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009496 }
9497 final long identity = Binder.clearCallingIdentity();
9498 try {
sqian854d44b2018-12-12 16:48:18 -08009499 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009500 //Note: we ignore passed in param exactMatch. We can remove it once
9501 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009502 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009503 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009504 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009505 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009506 }
sqian11b7a0e2018-12-05 18:48:28 -08009507 }
9508 return false;
9509 } finally {
9510 Binder.restoreCallingIdentity(identity);
9511 }
9512 }
9513
sqianf4ca7ed2019-01-15 18:32:07 -08009514 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009515 * Start emergency callback mode for GsmCdmaPhone for testing.
9516 */
9517 @Override
9518 public void startEmergencyCallbackMode() {
9519 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9520 "startEmergencyCallbackMode");
9521 enforceModifyPermission();
9522 final long identity = Binder.clearCallingIdentity();
9523 try {
9524 for (Phone phone : PhoneFactory.getPhones()) {
9525 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9526 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9527 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9528 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9529 gsmCdmaPhone.obtainMessage(
9530 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9531 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9532 }
9533 }
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537 }
9538
9539 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009540 * Update emergency number list for test mode.
9541 */
9542 @Override
9543 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9544 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9545 "updateEmergencyNumberListTestMode");
9546
9547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 for (Phone phone: PhoneFactory.getPhones()) {
9550 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9551 if (tracker != null) {
9552 tracker.executeEmergencyNumberTestModeCommand(action, num);
9553 }
9554 }
9555 } finally {
9556 Binder.restoreCallingIdentity(identity);
9557 }
9558 }
9559
9560 /**
9561 * Get the full emergency number list for test mode.
9562 */
9563 @Override
9564 public List<String> getEmergencyNumberListTestMode() {
9565 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9566 "getEmergencyNumberListTestMode");
9567
9568 final long identity = Binder.clearCallingIdentity();
9569 try {
9570 Set<String> emergencyNumbers = new HashSet<>();
9571 for (Phone phone: PhoneFactory.getPhones()) {
9572 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9573 if (tracker != null) {
9574 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9575 emergencyNumbers.add(num.getNumber());
9576 }
9577 }
9578 }
9579 return new ArrayList<>(emergencyNumbers);
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
9584
chen xud6b45bd2018-10-30 22:27:10 -07009585 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009586 public int getEmergencyNumberDbVersion(int subId) {
9587 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9588
9589 final long identity = Binder.clearCallingIdentity();
9590 try {
9591 final Phone phone = getPhone(subId);
9592 if (phone == null) {
9593 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9594 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9595 }
9596 return phone.getEmergencyNumberDbVersion();
9597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
9600 }
9601
9602 @Override
9603 public void notifyOtaEmergencyNumberDbInstalled() {
9604 enforceModifyPermission();
9605
9606 final long identity = Binder.clearCallingIdentity();
9607 try {
9608 for (Phone phone: PhoneFactory.getPhones()) {
9609 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9610 if (tracker != null) {
9611 tracker.updateOtaEmergencyNumberDatabase();
9612 }
9613 }
9614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
9619 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009620 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009621 enforceActiveEmergencySessionPermission();
9622
9623 final long identity = Binder.clearCallingIdentity();
9624 try {
9625 for (Phone phone: PhoneFactory.getPhones()) {
9626 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9627 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009628 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9629 }
9630 }
9631 } finally {
9632 Binder.restoreCallingIdentity(identity);
9633 }
9634 }
9635
9636 @Override
9637 public void resetOtaEmergencyNumberDbFilePath() {
9638 enforceActiveEmergencySessionPermission();
9639
9640 final long identity = Binder.clearCallingIdentity();
9641 try {
9642 for (Phone phone: PhoneFactory.getPhones()) {
9643 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9644 if (tracker != null) {
9645 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009646 }
9647 }
9648 } finally {
9649 Binder.restoreCallingIdentity(identity);
9650 }
9651 }
9652
9653 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009654 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9655 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9656 Phone phone = getPhone(subId);
9657 if (phone == null) {
9658 return null;
9659 }
9660 final long identity = Binder.clearCallingIdentity();
9661 try {
9662 UiccProfile profile = UiccController.getInstance()
9663 .getUiccProfileForPhone(phone.getPhoneId());
9664 if (profile != null) {
9665 return profile.getCertsFromCarrierPrivilegeAccessRules();
9666 }
9667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 return null;
9671 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009672
9673 /**
9674 * Enable or disable a modem stack.
9675 */
9676 @Override
9677 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9678 enforceModifyPermission();
9679
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
9682 Phone phone = PhoneFactory.getPhone(slotIndex);
9683 if (phone == null) {
9684 return false;
9685 } else {
9686 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9687 }
9688 } finally {
9689 Binder.restoreCallingIdentity(identity);
9690 }
9691 }
Michelecea4cf22018-12-21 15:00:11 -08009692
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009693 /**
9694 * Whether a modem stack is enabled or not.
9695 */
9696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009697 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9698 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009699 Phone phone = PhoneFactory.getPhone(slotIndex);
9700 if (phone == null) return false;
9701
9702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009703 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9704 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009705 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9706 }
9707
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009710 try {
9711 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9712 } catch (NoSuchElementException ex) {
9713 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9714 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
9719
Michelecea4cf22018-12-21 15:00:11 -08009720 @Override
Michele0ea7d782019-03-19 14:58:42 -07009721 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009722 enforceModifyPermission();
9723
9724 final long identity = Binder.clearCallingIdentity();
9725 try {
9726 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009727 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009728 .commit();
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 @Override
Michele0ea7d782019-03-19 14:58:42 -07009735 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009736 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009737 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009738 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9739 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009740 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009741 }
Michelecea4cf22018-12-21 15:00:11 -08009742
9743 final long identity = Binder.clearCallingIdentity();
9744 try {
Michele0ea7d782019-03-19 14:58:42 -07009745 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009746 } finally {
9747 Binder.restoreCallingIdentity(identity);
9748 }
9749 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009750
Michele0ea7d782019-03-19 14:58:42 -07009751 @TelephonyManager.IsMultiSimSupportedResult
9752 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009753 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9754 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9755 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009756 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9757 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009758 }
9759 // Check if the hardware supports multisim functionality. If usage of multisim is not
9760 // supported by the modem, indicate that it is restricted.
9761 PhoneCapability staticCapability =
9762 mPhoneConfigurationManager.getStaticPhoneCapability();
9763 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009764 loge("isMultiSimSupportedInternal: no static configuration available");
9765 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009766 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009767 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009768 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9769 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009770 }
9771 // Check if support of multiple SIMs is restricted by carrier
9772 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009773 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009774 }
9775
Michele0ea7d782019-03-19 14:58:42 -07009776 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009777 }
9778
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009779 /**
9780 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009781 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9782 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9783 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009784 * @param numOfSims number of active sims we want to switch to
9785 */
9786 @Override
9787 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009788 if (numOfSims == 1) {
9789 enforceModifyPermission();
9790 } else {
9791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9792 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9793 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009794 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009795
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009796 try {
Michele30b57b22019-03-01 12:01:14 -08009797 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009798 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009799 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9800 return;
9801 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009802 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9803 } finally {
9804 Binder.restoreCallingIdentity(identity);
9805 }
9806 }
9807
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009808 @Override
9809 public boolean isApplicationOnUicc(int subId, int appType) {
9810 enforceReadPrivilegedPermission("isApplicationOnUicc");
9811 Phone phone = getPhone(subId);
9812 if (phone == null) {
9813 return false;
9814 }
9815 final long identity = Binder.clearCallingIdentity();
9816 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009817 UiccPort uiccPort = phone.getUiccPort();
9818 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009819 return false;
9820 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009821 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009822 if (uiccProfile == null) {
9823 return false;
9824 }
9825 if (TelephonyManager.APPTYPE_SIM <= appType
9826 && appType <= TelephonyManager.APPTYPE_ISIM) {
9827 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9828 }
9829 return false;
9830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
9834
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009835 /**
chen xub4baa772019-04-03 10:23:41 -07009836 * Get whether making changes to modem configurations will trigger reboot.
9837 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009838 */
9839 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009840 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9841 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009843 mApp, subId, callingPackage, callingFeatureId,
9844 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009845 return false;
9846 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009847 final long identity = Binder.clearCallingIdentity();
9848 try {
9849 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9850 } finally {
9851 Binder.restoreCallingIdentity(identity);
9852 }
9853 }
9854
Nathan Harold29f5f052019-02-15 13:41:57 -08009855 private void updateModemStateMetrics() {
9856 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9857 // TODO: check the state for each modem if the api is ready.
9858 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9859 }
9860
Pengquan Meng3889a572019-01-23 11:16:29 -08009861 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009862 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009863 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009864 // Verify that the callingPackage belongs to the calling UID
9865 mApp.getSystemService(AppOpsManager.class)
9866 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009867 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009868 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009869 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009870 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9871 if (slotInfos != null) {
9872 for (int i = 0; i < slotInfos.length; i++) {
9873 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9874 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9875 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9876 portInfo.getLogicalSlotIndex()));
9877 }
9878 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009879 }
9880 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009881 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009886
9887 /**
9888 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009889 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009890 */
jimsunf9ec1622022-09-13 21:18:43 +08009891 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009892 @Override
9893 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009894 return getHalVersion(HAL_SERVICE_RADIO);
9895 }
9896
9897 /**
9898 * Get the HAL Version of a specific service
9899 */
9900 @Override
9901 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009902 Phone phone = getDefaultPhone();
9903 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009904 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009905 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9906 return hv.major * 100 + hv.minor;
9907 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009908
9909 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009910 * Get the current calling package name.
9911 * @return the current calling package name
9912 */
9913 @Override
9914 public String getCurrentPackageName() {
9915 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9916 }
9917
9918 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009919 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9920 * corresponding network requests on a subId.
9921 *
9922 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009923 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009924 * 2) APN is un-metered for this subscription, or
9925 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009926 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009927 *
9928 * @return whether data is allowed for a apn type.
9929 *
9930 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009931 */
9932 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009933 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009934 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9935 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009936
9937 // Now that all security checks passes, perform the operation as ourselves.
9938 final long identity = Binder.clearCallingIdentity();
9939 try {
9940 Phone phone = getPhone(subId);
9941 if (phone == null) return false;
9942
Jack Yu27422a52022-03-21 10:38:05 -07009943 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009944 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009945 isMetered = phone.getDataNetworkController().getDataConfigManager()
9946 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9947 phone.getServiceState().getDataRoaming());
9948 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009949 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
9955 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009956 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009957 enforceReadPrivilegedPermission("isApnMetered");
9958
9959 // Now that all security checks passes, perform the operation as ourselves.
9960 final long identity = Binder.clearCallingIdentity();
9961 try {
9962 Phone phone = getPhone(subId);
9963 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009964 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9965 DataUtils.apnTypeToNetworkCapability(apnType),
9966 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009967 } finally {
9968 Binder.restoreCallingIdentity(identity);
9969 }
9970 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009971
9972 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009973 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9974 int subscriptionId, IBooleanConsumer resultCallback) {
9975 enforceModifyPermission();
9976 long token = Binder.clearCallingIdentity();
9977 try {
9978 Phone phone = getPhone(subscriptionId);
9979 if (phone == null) {
9980 try {
9981 if (resultCallback != null) {
9982 resultCallback.accept(false);
9983 }
9984 } catch (RemoteException e) {
9985 // ignore
9986 }
9987 return;
9988 }
9989 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9990 Pair.create(specifiers, (x) -> {
9991 try {
9992 if (resultCallback != null) {
9993 resultCallback.accept(x);
9994 }
9995 } catch (RemoteException e) {
9996 // ignore
9997 }
9998 });
9999 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10000 } finally {
10001 Binder.restoreCallingIdentity(token);
10002 }
10003 }
10004
10005 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010006 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10007 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010008 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010009 mApp, subId, "getSystemSelectionChannels");
10010 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10011 final long identity = Binder.clearCallingIdentity();
10012 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010013 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10014 if (result instanceof IllegalStateException) {
10015 throw (IllegalStateException) result;
10016 }
10017 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010018 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10019 return specifiers;
10020 } finally {
10021 Binder.restoreCallingIdentity(identity);
10022 }
10023 }
10024
10025 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010026 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010027 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010028 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010029 }
10030
10031 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010032 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10033 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010034 if (callingPackage == null) {
10035 callingPackage = getCurrentPackageName();
10036 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010037 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10038 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010039 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10040 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010041 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10042 }
10043 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10044 Intent intent = new Intent();
10045 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10046 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10047 // Bring up choose default SMS subscription dialog right now
10048 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10049 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10050 mApp.startActivity(intent);
10051 }
chen xud5ca2d52019-05-28 15:20:57 -070010052
10053 @Override
10054 public String getMmsUAProfUrl(int subId) {
10055 //TODO investigate if this API should require proper permission check in R b/133791609
10056 final long identity = Binder.clearCallingIdentity();
10057 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010058 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10059 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10060 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10061 return carrierUAProfUrl;
10062 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010063 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10064 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
10069
10070 @Override
10071 public String getMmsUserAgent(int subId) {
10072 //TODO investigate if this API should require proper permission check in R b/133791609
10073 final long identity = Binder.clearCallingIdentity();
10074 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010075 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10076 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10077 if (!TextUtils.isEmpty(carrierUserAgent)) {
10078 return carrierUserAgent;
10079 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010080 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10081 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010082 } finally {
10083 Binder.restoreCallingIdentity(identity);
10084 }
10085 }
Jack Yub07d4972019-05-28 16:12:25 -070010086
10087 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010088 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10089 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010090
Jack Yub07d4972019-05-28 16:12:25 -070010091 final long identity = Binder.clearCallingIdentity();
10092 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010093 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010094 if (phone == null) return false;
10095
Ling Maf188d502022-09-16 15:22:36 -070010096 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010097 } finally {
10098 Binder.restoreCallingIdentity(identity);
10099 }
10100 }
10101
10102 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010103 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010104 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010105 enforceModifyPermission();
10106
changbettyd5c246e2019-12-24 15:40:37 +080010107 final long identity = Binder.clearCallingIdentity();
10108 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010109 Phone phone = getPhone(subscriptionId);
10110 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010111
Ling Maf188d502022-09-16 15:22:36 -070010112 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010113 } finally {
10114 Binder.restoreCallingIdentity(identity);
10115 }
10116 }
10117
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010118 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010119 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010120 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10121 * otherwise.
10122 */
10123 @Override
10124 public void setCepEnabled(boolean isCepEnabled) {
10125 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10126
10127 final long identity = Binder.clearCallingIdentity();
10128 try {
10129 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10130 for (Phone phone : PhoneFactory.getPhones()) {
10131 Phone defaultPhone = phone.getImsPhone();
10132 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10133 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10134 ImsPhoneCallTracker imsPhoneCallTracker =
10135 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10136 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10137 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10138 + imsPhone.getMsisdn());
10139 }
10140 }
10141 } finally {
10142 Binder.restoreCallingIdentity(identity);
10143 }
10144 }
allenwtsu46dcc572020-01-08 18:24:03 +080010145
10146 /**
10147 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10148 *
10149 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10150 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10151 * before being read.
10152 */
10153 @Override
10154 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10155 isCompressed) {
10156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10157 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010158 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10159 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10160 }
10161 if (!isImsAvailableOnDevice()) {
10162 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10163 "IMS not available on device.");
10164 }
10165
10166 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010167 try {
Hui Wang761a6682020-10-31 05:12:53 +000010168 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10169 } finally {
10170 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010171 }
10172 }
zoey chene02881a2019-12-30 16:11:23 +080010173
10174 @Override
10175 public boolean isIccLockEnabled(int subId) {
10176 enforceReadPrivilegedPermission("isIccLockEnabled");
10177
10178 // Now that all security checks passes, perform the operation as ourselves.
10179 final long identity = Binder.clearCallingIdentity();
10180 try {
10181 Phone phone = getPhone(subId);
10182 if (phone != null && phone.getIccCard() != null) {
10183 return phone.getIccCard().getIccLockEnabled();
10184 } else {
10185 return false;
10186 }
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
10191
10192 /**
10193 * Set the ICC pin lock enabled or disabled.
10194 *
10195 * @return an integer representing the status of IccLock enabled or disabled in the following
10196 * three cases:
10197 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10198 * successfully.
10199 * - Positive number and zero for remaining password attempts.
10200 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10201 *
10202 */
10203 @Override
10204 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10205 enforceModifyPermission();
10206
10207 Phone phone = getPhone(subId);
10208 if (phone == null) {
10209 return 0;
10210 }
10211 // Now that all security checks passes, perform the operation as ourselves.
10212 final long identity = Binder.clearCallingIdentity();
10213 try {
10214 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10215 new Pair<Boolean, String>(enabled, password), phone, null);
10216 return attemptsRemaining;
10217
10218 } catch (Exception e) {
10219 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10220 } finally {
10221 Binder.restoreCallingIdentity(identity);
10222 }
10223 return 0;
10224 }
10225
10226 /**
10227 * Change the ICC password used in ICC pin lock.
10228 *
10229 * @return an integer representing the status of IccLock changed in the following three cases:
10230 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10231 * - Positive number and zero for remaining password attempts.
10232 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10233 *
10234 */
10235 @Override
10236 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10237 enforceModifyPermission();
10238
10239 Phone phone = getPhone(subId);
10240 if (phone == null) {
10241 return 0;
10242 }
10243 // Now that all security checks passes, perform the operation as ourselves.
10244 final long identity = Binder.clearCallingIdentity();
10245 try {
10246 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10247 new Pair<String, String>(oldPassword, newPassword), phone, null);
10248 return attemptsRemaining;
10249
10250 } catch (Exception e) {
10251 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10252 } finally {
10253 Binder.restoreCallingIdentity(identity);
10254 }
10255 return 0;
10256 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010257
10258 /**
10259 * Request for receiving user activity notification
10260 */
10261 @Override
10262 public void requestUserActivityNotification() {
10263 if (!mNotifyUserActivity.get()
10264 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10265 mNotifyUserActivity.set(true);
10266 }
10267 }
10268
10269 /**
10270 * Called when userActivity is signalled in the power manager.
10271 * This is safe to call from any thread, with any window manager locks held or not.
10272 */
10273 @Override
10274 public void userActivity() {
10275 // ***************************************
10276 // * Inherited from PhoneWindowManager *
10277 // ***************************************
10278 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10279 // WITH ITS LOCKS HELD.
10280 //
10281 // This code must be VERY careful about the locks
10282 // it acquires.
10283 // In fact, the current code acquires way too many,
10284 // and probably has lurking deadlocks.
10285
10286 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10287 throw new SecurityException("Only the OS may call notifyUserActivity()");
10288 }
10289
10290 if (mNotifyUserActivity.getAndSet(false)) {
10291 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10292 USER_ACTIVITY_NOTIFICATION_DELAY);
10293 }
10294 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010295
10296 @Override
10297 public boolean canConnectTo5GInDsdsMode() {
10298 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10299 }
Jack Yud10cdd42020-09-28 20:28:01 -070010300
10301 @Override
10302 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10303 String callingFeatureId) {
10304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10305 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10306 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10307 }
10308
10309 Phone phone = getPhone(subId);
10310 if (phone == null) {
10311 throw new RuntimeException("phone is not available");
10312 }
10313 // Now that all security checks passes, perform the operation as ourselves.
10314 final long identity = Binder.clearCallingIdentity();
10315 try {
10316 return phone.getEquivalentHomePlmns();
10317 } finally {
10318 Binder.restoreCallingIdentity(identity);
10319 }
10320 }
Daniel Bright59e67312020-11-13 11:49:37 -080010321
10322 @Override
10323 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010324 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10325 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010326 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010327 if (radioInterfaceCapabilities == null) {
10328 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010329 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010330 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010331 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010332
Hui Wang641e81c2020-10-12 12:14:23 -070010333 @Override
10334 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10335 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010336 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10337 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10338 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10339 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10340 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010341 if (DBG) {
10342 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10343 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10344 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10345 }
10346
10347 if (!SubscriptionManager.isValidSubscriptionId(subId)
10348 || appType < TelephonyManager.APPTYPE_UNKNOWN
10349 || appType > TelephonyManager.APPTYPE_ISIM
10350 || nafUrl == null || securityProtocol == null || callback == null) {
10351 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10352 if (callback != null) {
10353 try {
10354 callback.onAuthenticationFailure(
10355 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10356 } catch (RemoteException exception) {
10357 log("Fail to notify onAuthenticationFailure due to " + exception);
10358 }
10359 return;
10360 }
10361 }
10362
10363 final long token = Binder.clearCallingIdentity();
10364 try {
10365 getGbaManager(subId).bootstrapAuthenticationRequest(
10366 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10367 forceBootStrapping, callback));
10368 } finally {
10369 Binder.restoreCallingIdentity(token);
10370 }
10371 }
10372
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010373 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010374 * Attempts to set the radio power state for all phones for thermal reason.
10375 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010376 * requested radio power state will actually be set. See {@link
10377 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10378 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010379 * @param enable {@code true} if trying to turn radio on.
10380 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10381 * false}.
10382 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010383 private boolean setRadioPowerForThermal(boolean enable) {
10384 boolean isPhoneAvailable = false;
10385 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10386 Phone phone = PhoneFactory.getPhone(i);
10387 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010388 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010389 isPhoneAvailable = true;
10390 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010391 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010392
10393 // return true if successfully informed the phone object about the thermal radio power
10394 // request.
10395 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010396 }
10397
10398 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010399 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010400 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10401 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10402 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10403 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10404 throw new IllegalArgumentException("modem does not support data throttling");
10405 }
10406
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010407 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10408 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010409 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010410 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10411 }
10412
Sarah Chinecc78c42022-03-31 21:16:48 -070010413 setDataEnabledForReason(
10414 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010415
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010416 if (isDataThrottlingSupported) {
10417 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010418 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010419 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10420 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10421 } else if (thermalMitigationResult
10422 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010423 log("Modem likely does not support data throttling on secondary carrier. Data " +
10424 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10425 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010426 }
10427 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010428 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010429
10430 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010431 }
10432
Jack Nudelman644b91a2021-03-12 14:09:48 -080010433 private static List<String> getThermalMitigationAllowlist(Context context) {
10434 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10435 for (String pckg : context.getResources()
10436 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10437 sThermalMitigationAllowlistedPackages.add(pckg);
10438 }
10439 }
10440
10441 return sThermalMitigationAllowlistedPackages;
10442 }
10443
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010444 private boolean isAnyPhoneInEmergencyState() {
10445 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10446 if (tm.isInEmergencyCall()) {
10447 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10448 return true;
10449 }
10450 for (Phone phone : PhoneFactory.getPhones()) {
10451 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10452 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10453 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10454 + phone.isInEcm());
10455 return true;
10456 }
10457 }
10458
10459 return false;
10460 }
10461
Jack Nudelman644b91a2021-03-12 14:09:48 -080010462 /**
10463 * Used by shell commands to add an authorized package name for thermal mitigation.
10464 * @param packageName name of package to be allowlisted
10465 * @param context
10466 */
10467 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10468 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10469 sThermalMitigationAllowlistedPackages.add(packageName);
10470 }
10471
10472 /**
10473 * Used by shell commands to remove an authorized package name for thermal mitigation.
10474 * @param packageName name of package to remove from allowlist
10475 * @param context
10476 */
10477 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10478 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10479 sThermalMitigationAllowlistedPackages.remove(packageName);
10480 }
10481
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010482 /**
10483 * Thermal mitigation request to control functionalities at modem.
10484 *
10485 * @param subId the id of the subscription.
10486 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010487 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010488 *
10489 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10490 */
10491 @Override
10492 @ThermalMitigationResult
10493 public int sendThermalMitigationRequest(
10494 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010495 ThermalMitigationRequest thermalMitigationRequest,
10496 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010497 enforceModifyPermission();
10498
Jack Nudelman644b91a2021-03-12 14:09:48 -080010499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10500 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10501 .contains(callingPackage)) {
10502 throw new SecurityException("Calling package must be configured in the device config. "
10503 + "calling package: " + callingPackage);
10504 }
10505
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10507 final long identity = Binder.clearCallingIdentity();
10508
10509 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10510 try {
10511 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10512 switch (thermalMitigationAction) {
10513 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10514 thermalMitigationResult =
10515 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010516 thermalMitigationRequest.getDataThrottlingRequest(),
10517 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010518 break;
10519 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10520 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10521 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10522 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10523 }
10524
10525 // Ensure that radio is on. If not able to power on due to phone being
10526 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010527 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010528 thermalMitigationResult =
10529 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10530 break;
10531 }
10532
10533 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010534 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010535 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10536 break;
10537 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10538 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10539 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10540 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10541 }
10542
10543 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10544 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010545 Phone phone = getPhone(subId);
10546 if (phone == null) {
10547 thermalMitigationResult =
10548 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10549 break;
10550 }
10551
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010552 TelephonyConnectionService service =
10553 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010554 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010555 Log.e(LOG_TAG, "An emergency call is pending");
10556 thermalMitigationResult =
10557 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10558 break;
10559 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010560 thermalMitigationResult =
10561 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10562 break;
10563 }
10564 } else {
10565 thermalMitigationResult =
10566 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10567 break;
10568 }
10569
10570 // Turn radio off. If not able to power off due to phone being unavailable,
10571 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010572 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010573 thermalMitigationResult =
10574 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10575 break;
10576 }
10577 thermalMitigationResult =
10578 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10579 break;
10580 default:
10581 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10582 + "not exist. Requested action: " + thermalMitigationAction);
10583 }
10584 } catch (IllegalArgumentException e) {
10585 throw e;
10586 } catch (Exception e) {
10587 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10588 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10589 } finally {
10590 Binder.restoreCallingIdentity(identity);
10591 }
10592
10593 if (DBG) {
10594 log("thermalMitigationRequest returning with thermalMitigationResult: "
10595 + thermalMitigationResult);
10596 }
10597
10598 return thermalMitigationResult;
10599 }
Hui Wang641e81c2020-10-12 12:14:23 -070010600
10601 /**
10602 * Set the GbaService Package Name that Telephony will bind to.
10603 *
10604 * @param subId The sim that the GbaService is associated with.
10605 * @param packageName The name of the package to be replaced with.
10606 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10607 */
10608 @Override
10609 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10610 enforceModifyPermission();
10611
10612 final long identity = Binder.clearCallingIdentity();
10613 try {
10614 return getGbaManager(subId).overrideServicePackage(packageName);
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
10619
10620 /**
10621 * Return the package name of the currently bound GbaService.
10622 *
10623 * @param subId The sim that the GbaService is associated with.
10624 * @return the package name of the GbaService configuration, null if GBA is not supported.
10625 */
10626 @Override
10627 public String getBoundGbaService(int subId) {
10628 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10629
10630 final long identity = Binder.clearCallingIdentity();
10631 try {
10632 return getGbaManager(subId).getServicePackage();
10633 } finally {
10634 Binder.restoreCallingIdentity(identity);
10635 }
10636 }
10637
10638 /**
10639 * Set the release time for telephony to unbind GbaService.
10640 *
10641 * @param subId The sim that the GbaService is associated with.
10642 * @param interval The release time to unbind GbaService by millisecond.
10643 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10644 */
10645 @Override
10646 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10647 enforceModifyPermission();
10648
10649 final long identity = Binder.clearCallingIdentity();
10650 try {
10651 return getGbaManager(subId).overrideReleaseTime(interval);
10652 } finally {
10653 Binder.restoreCallingIdentity(identity);
10654 }
10655 }
10656
10657 /**
10658 * Return the release time for telephony to unbind GbaService.
10659 *
10660 * @param subId The sim that the GbaService is associated with.
10661 * @return The release time to unbind GbaService by millisecond.
10662 */
10663 @Override
10664 public int getGbaReleaseTime(int subId) {
10665 enforceReadPrivilegedPermission("getGbaReleaseTime");
10666
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
10669 return getGbaManager(subId).getReleaseTime();
10670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
10674
10675 private GbaManager getGbaManager(int subId) {
10676 GbaManager instance = GbaManager.getInstance(subId);
10677 if (instance == null) {
10678 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10679 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10680 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10681 }
10682 return instance;
10683 }
Hui Wang761a6682020-10-31 05:12:53 +000010684
10685 /**
10686 * indicate whether the device and the carrier can support
10687 * RCS VoLTE single registration.
10688 */
10689 @Override
10690 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010691 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10692 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10693 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10694 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010695
10696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10697 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10698 }
10699
10700 final long identity = Binder.clearCallingIdentity();
10701 try {
10702 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10703 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010704 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10705 if (isCapable != null) {
10706 return isCapable;
10707 }
Hui Wang761a6682020-10-31 05:12:53 +000010708 }
Hui Wang67af90e2021-06-04 16:57:15 -070010709 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10710 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010711 } finally {
10712 Binder.restoreCallingIdentity(identity);
10713 }
10714 }
10715
10716 /**
10717 * Register RCS provisioning callback.
10718 */
10719 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010720 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010721 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010722 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010723 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010724 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10725 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010726
10727 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10728 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10729 }
10730 if (!isImsAvailableOnDevice()) {
10731 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10732 "IMS not available on device.");
10733 }
10734
10735 final long identity = Binder.clearCallingIdentity();
10736 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010737 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010738 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010739 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10740 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010741 }
Hui Wang761a6682020-10-31 05:12:53 +000010742 } finally {
10743 Binder.restoreCallingIdentity(identity);
10744 }
10745 }
10746
10747 /**
10748 * Unregister RCS provisioning callback.
10749 */
10750 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010751 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010752 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010753 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010754 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010755 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10756 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010757
10758 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10759 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10760 }
10761 if (!isImsAvailableOnDevice()) {
10762 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10763 "IMS not available on device.");
10764 }
10765
10766 final long identity = Binder.clearCallingIdentity();
10767 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010768 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010769 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
10775 /**
10776 * trigger RCS reconfiguration.
10777 */
10778 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010779 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10780 "triggerRcsReconfiguration",
10781 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010782
10783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10785 }
10786 if (!isImsAvailableOnDevice()) {
10787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10788 "IMS not available on device.");
10789 }
10790
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
10798
10799 /**
10800 * Provide the client configuration parameters of the RCS application.
10801 */
10802 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010803 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10804 "setRcsClientConfiguration",
10805 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010806
10807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10808 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10809 }
10810 if (!isImsAvailableOnDevice()) {
10811 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10812 "IMS not available on device.");
10813 }
10814
10815 final long identity = Binder.clearCallingIdentity();
10816
10817 try {
10818 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10819 if (configBinder == null) {
10820 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010821 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10822 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010823 } else {
10824 configBinder.setRcsClientConfiguration(rcc);
10825 }
joonhunshin3e154242021-09-17 06:33:39 +000010826
10827 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10828 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010829 } catch (RemoteException e) {
10830 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010831 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10832 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
10838 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010839 * Enables or disables the test mode for RCS VoLTE single registration.
10840 */
10841 @Override
10842 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10844 "setRcsSingleRegistrationTestModeEnabled");
10845
10846 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10847 }
10848
10849 /**
10850 * Gets the test mode for RCS VoLTE single registration.
10851 */
10852 @Override
10853 public boolean getRcsSingleRegistrationTestModeEnabled() {
10854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10855 "getRcsSingleRegistrationTestModeEnabled");
10856
10857 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10858 }
10859
10860 /**
Hui Wang761a6682020-10-31 05:12:53 +000010861 * Overrides the config of RCS VoLTE single registration enabled for the device.
10862 */
10863 @Override
10864 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10866 "setDeviceSingleRegistrationEnabledOverride");
10867 enforceModifyPermission();
10868
10869 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10870 : Boolean.parseBoolean(enabledStr);
10871 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010872 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010873 }
10874
10875 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010876 * Sends a device to device communication message. Only usable via shell.
10877 * @param message message to send.
10878 * @param value message value.
10879 */
10880 @Override
10881 public void sendDeviceToDeviceMessage(int message, int value) {
10882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010883 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010884 enforceModifyPermission();
10885
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
10888 TelephonyConnectionService service =
10889 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10890 if (service == null) {
10891 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10892 return;
10893 }
10894 service.sendTestDeviceToDeviceMessage(message, value);
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
Tyler Gunnbabbda02021-02-10 11:05:02 -080010900 /**
10901 * Sets the specified device to device transport active.
10902 * @param transport The transport to set active.
10903 */
10904 @Override
10905 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10907 "setActiveDeviceToDeviceTransport");
10908 enforceModifyPermission();
10909
10910 final long identity = Binder.clearCallingIdentity();
10911 try {
10912 TelephonyConnectionService service =
10913 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10914 if (service == null) {
10915 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10916 return;
10917 }
10918 service.setActiveDeviceToDeviceTransport(transport);
10919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
Tyler Gunn92479152021-01-20 16:30:10 -080010923
Tyler Gunnd4339262021-05-03 14:46:49 -070010924 @Override
10925 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10926 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10927 "setDeviceToDeviceForceEnabled");
10928
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 Arrays.stream(PhoneFactory.getPhones()).forEach(
10932 p -> {
10933 Phone thePhone = p.getImsPhone();
10934 if (thePhone != null && thePhone instanceof ImsPhone) {
10935 ImsPhone imsPhone = (ImsPhone) thePhone;
10936 CallTracker tracker = imsPhone.getCallTracker();
10937 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10938 ImsPhoneCallTracker imsPhoneCallTracker =
10939 (ImsPhoneCallTracker) tracker;
10940 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10941 }
10942 }
10943 }
10944 );
10945 } finally {
10946 Binder.restoreCallingIdentity(identity);
10947 }
10948 }
10949
Tyler Gunn92479152021-01-20 16:30:10 -080010950 /**
Hui Wang761a6682020-10-31 05:12:53 +000010951 * Gets the config of RCS VoLTE single registration enabled for the device.
10952 */
10953 @Override
10954 public boolean getDeviceSingleRegistrationEnabled() {
10955 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10956 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10957 }
10958
10959 /**
10960 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10961 */
10962 @Override
10963 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10965 "setCarrierSingleRegistrationEnabledOverride");
10966 enforceModifyPermission();
10967
10968 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10969 : Boolean.parseBoolean(enabledStr);
10970 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10971 subId, enabled);
10972 }
10973
10974 /**
10975 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10976 */
10977 @Override
10978 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10979 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10980 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10981 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010982
10983 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010984 * Overrides the ims feature validation result
10985 */
10986 @Override
10987 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10989 "setImsFeatureValidationOverride");
10990
10991 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10992 : Boolean.parseBoolean(enabledStr);
10993 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10994 subId, enabled);
10995 }
10996
10997 /**
10998 * Gets the ims feature validation override value
10999 */
11000 @Override
11001 public boolean getImsFeatureValidationOverride(int subId) {
11002 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11003 "getImsFeatureValidationOverride");
11004 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11005 }
11006
11007 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011008 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11009 * their mobile plan.
11010 */
11011 @Override
11012 public String getMobileProvisioningUrl() {
11013 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11014 final long identity = Binder.clearCallingIdentity();
11015 try {
11016 return getDefaultPhone().getMobileProvisioningUrl();
11017 } finally {
11018 Binder.restoreCallingIdentity(identity);
11019 }
11020 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011021
James.cf Linbcdf8b32021-01-14 16:44:13 +080011022 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011023 * Get the EAB contact from the EAB database.
11024 */
11025 @Override
11026 public String getContactFromEab(String contact) {
11027 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11028 enforceModifyPermission();
11029 final long identity = Binder.clearCallingIdentity();
11030 try {
11031 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11032 } finally {
11033 Binder.restoreCallingIdentity(identity);
11034 }
11035 }
11036
11037 /**
Calvin Pana1434322021-07-01 19:27:01 +080011038 * Get the EAB capability from the EAB database.
11039 */
11040 @Override
11041 public String getCapabilityFromEab(String contact) {
11042 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11043 enforceModifyPermission();
11044 final long identity = Binder.clearCallingIdentity();
11045 try {
11046 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11047 } finally {
11048 Binder.restoreCallingIdentity(identity);
11049 }
11050 }
11051
11052 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011053 * Remove the EAB contacts from the EAB database.
11054 */
11055 @Override
11056 public int removeContactFromEab(int subId, String contacts) {
11057 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11058 enforceModifyPermission();
11059 final long identity = Binder.clearCallingIdentity();
11060 try {
11061 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
11066
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011067 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011068 public boolean getDeviceUceEnabled() {
11069 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11070 final long identity = Binder.clearCallingIdentity();
11071 try {
11072 return mApp.getDeviceUceEnabled();
11073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
11077
11078 @Override
11079 public void setDeviceUceEnabled(boolean isEnabled) {
11080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11081 final long identity = Binder.clearCallingIdentity();
11082 try {
11083 mApp.setDeviceUceEnabled(isEnabled);
11084 } finally {
11085 Binder.restoreCallingIdentity(identity);
11086 }
11087 }
11088
Brad Ebinger14d467f2021-02-12 06:18:28 +000011089 /**
11090 * Add new 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 addUceRegistrationOverrideShell(int subId,
11096 List<String> featureTags) {
11097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11098 "addUceRegistrationOverrideShell");
11099 final long identity = Binder.clearCallingIdentity();
11100 try {
11101 return mApp.imsRcsController.addUceRegistrationOverrideShell(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 * Remove existing feature tags to 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 removeUceRegistrationOverrideShell(int subId,
11117 List<String> featureTags) {
11118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11119 "removeUceRegistrationOverrideShell");
11120 final long identity = Binder.clearCallingIdentity();
11121 try {
11122 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11123 new ArraySet<>(featureTags));
11124 } catch (ImsException e) {
11125 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11126 } finally {
11127 Binder.restoreCallingIdentity(identity);
11128 }
11129 }
11130
11131 /**
11132 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11133 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11134 */
11135 // Used for SHELL command only right now.
11136 @Override
11137 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11139 "clearUceRegistrationOverrideShell");
11140 final long identity = Binder.clearCallingIdentity();
11141 try {
11142 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11143 } catch (ImsException e) {
11144 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11145 } finally {
11146 Binder.restoreCallingIdentity(identity);
11147 }
11148 }
11149
11150 /**
11151 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11152 */
11153 // Used for SHELL command only right now.
11154 @Override
11155 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11156 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11157 "getLatestRcsContactUceCapabilityShell");
11158 final long identity = Binder.clearCallingIdentity();
11159 try {
11160 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11161 } catch (ImsException e) {
11162 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11163 } finally {
11164 Binder.restoreCallingIdentity(identity);
11165 }
11166 }
11167
11168 /**
11169 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11170 * device does not have an active PUBLISH.
11171 */
11172 // Used for SHELL command only right now.
11173 @Override
11174 public String getLastUcePidfXmlShell(int subId) {
11175 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11176 final long identity = Binder.clearCallingIdentity();
11177 try {
11178 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11179 } catch (ImsException e) {
11180 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11181 } finally {
11182 Binder.restoreCallingIdentity(identity);
11183 }
11184 }
11185
James.cf Line8713a42021-04-29 16:04:26 +080011186 /**
11187 * Remove UCE requests cannot be sent to the network status.
11188 */
11189 // Used for SHELL command only right now.
11190 @Override
11191 public boolean removeUceRequestDisallowedStatus(int subId) {
11192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11193 final long identity = Binder.clearCallingIdentity();
11194 try {
11195 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11196 } catch (ImsException e) {
11197 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11198 } finally {
11199 Binder.restoreCallingIdentity(identity);
11200 }
11201 }
11202
James.cf Lin18bb9002021-05-25 01:37:38 +080011203 /**
11204 * Remove UCE requests cannot be sent to the network status.
11205 */
11206 // Used for SHELL command only.
11207 @Override
11208 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11210 final long identity = Binder.clearCallingIdentity();
11211 try {
11212 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11213 } catch (ImsException e) {
11214 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11215 } finally {
11216 Binder.restoreCallingIdentity(identity);
11217 }
11218 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011219
James.cf Lin4b784aa2021-01-31 03:25:15 +080011220 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011221 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11222 String callingPackage) {
11223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11224 mApp, subId, "setSignalStrengthUpdateRequest");
11225
11226 final int callingUid = Binder.getCallingUid();
11227 // Verify that tha callingPackage belongs to the calling UID
11228 mApp.getSystemService(AppOpsManager.class)
11229 .checkPackage(callingUid, callingPackage);
11230
Rambo Wang3607f502021-02-01 21:51:40 -080011231 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011232
11233 final long identity = Binder.clearCallingIdentity();
11234 try {
11235 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11236 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11237
11238 if (result instanceof IllegalStateException) {
11239 throw (IllegalStateException) result;
11240 }
11241 } finally {
11242 Binder.restoreCallingIdentity(identity);
11243 }
11244 }
11245
11246 @Override
11247 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11248 String callingPackage) {
11249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11250 mApp, subId, "clearSignalStrengthUpdateRequest");
11251
11252 final int callingUid = Binder.getCallingUid();
11253 // Verify that tha callingPackage belongs to the calling UID
11254 mApp.getSystemService(AppOpsManager.class)
11255 .checkPackage(callingUid, callingPackage);
11256
11257 final long identity = Binder.clearCallingIdentity();
11258 try {
11259 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11260 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11261
11262 if (result instanceof IllegalStateException) {
11263 throw (IllegalStateException) result;
11264 }
11265 } finally {
11266 Binder.restoreCallingIdentity(identity);
11267 }
11268 }
11269
Rambo Wang3607f502021-02-01 21:51:40 -080011270 private static void validateSignalStrengthUpdateRequest(Context context,
11271 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011272 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11273 // phone/system process do not have further restriction on request
11274 return;
11275 }
11276
11277 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011278 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011279 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011280 context.enforceCallingOrSelfPermission(
11281 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11282 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011283 }
11284
11285 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11286 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11287 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11288 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11289 || info.isEnabled()) {
11290 throw new IllegalArgumentException(
11291 "Only system can set hide fields in SignalThresholdInfo");
11292 }
11293
11294 // Thresholds length for each RAN need in range. This has been validated in
11295 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11296 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11297 final int[] thresholds = info.getThresholds();
11298 Objects.requireNonNull(thresholds);
11299 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11300 || thresholds.length
11301 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11302 throw new IllegalArgumentException(
11303 "thresholds length is out of range: " + thresholds.length);
11304 }
11305 }
11306 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011307
11308 /**
11309 * Gets the current phone capability.
11310 *
11311 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11312 * @return the PhoneCapability which describes the data connection capability of modem.
11313 * It's used to evaluate possible phone config change, for example from single
11314 * SIM device to multi-SIM device.
11315 */
11316 @Override
11317 public PhoneCapability getPhoneCapability() {
11318 enforceReadPrivilegedPermission("getPhoneCapability");
11319 final long identity = Binder.clearCallingIdentity();
11320 try {
11321 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11322 } finally {
11323 Binder.restoreCallingIdentity(identity);
11324 }
11325 }
Michele Berionne5e411512020-11-13 02:36:59 +000011326
11327 /**
11328 * Prepare TelephonyManager for an unattended reboot. The reboot is
11329 * required to be done shortly after the API is invoked.
11330 */
11331 @Override
11332 @TelephonyManager.PrepareUnattendedRebootResult
11333 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011335 enforceRebootPermission();
11336
11337 final long identity = Binder.clearCallingIdentity();
11338 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011339 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011340 } finally {
11341 Binder.restoreCallingIdentity(identity);
11342 }
11343 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011344
11345 /**
11346 * Request to get the current slicing configuration including URSP rules and
11347 * NSSAIs (configured, allowed and rejected).
11348 *
11349 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11350 */
11351 @Override
11352 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011353 TelephonyPermissions
11354 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11355 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011356
11357 final long identity = Binder.clearCallingIdentity();
11358 try {
11359 Phone phone = getDefaultPhone();
11360 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11361 } finally {
11362 Binder.restoreCallingIdentity(identity);
11363 }
11364 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011365
11366 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011367 * Check whether the given premium capability is available for purchase from the carrier.
11368 *
11369 * @param capability The premium capability to check.
11370 * @param subId The subId to check the premium capability for.
11371 *
11372 * @return Whether the given premium capability is available to purchase.
11373 */
11374 @Override
11375 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11376 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11377 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11378 log("Premium capability "
11379 + TelephonyManager.convertPremiumCapabilityToString(capability)
11380 + " is not available for purchase due to missing permissions.");
11381 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11382 + "permission READ_BASIC_PHONE_STATE.");
11383 }
11384
11385 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011386 if (phone == null) {
11387 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11388 return false;
11389 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011390 final long identity = Binder.clearCallingIdentity();
11391 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011392 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011393 .isPremiumCapabilityAvailableForPurchase(capability);
11394 } finally {
11395 Binder.restoreCallingIdentity(identity);
11396 }
11397 }
11398
11399 /**
11400 * Purchase the given premium capability from the carrier.
11401 *
11402 * @param capability The premium capability to purchase.
11403 * @param callback The result of the purchase request.
11404 * @param subId The subId to purchase the premium capability for.
11405 */
11406 @Override
11407 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11408 log("purchasePremiumCapability: capability="
11409 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11410 + getCurrentPackageName());
11411
11412 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11413 mApp, "purchasePremiumCapability")) {
11414 log("purchasePremiumCapability "
11415 + TelephonyManager.convertPremiumCapabilityToString(capability)
11416 + " failed due to missing permissions.");
11417 throw new SecurityException("purchasePremiumCapability requires permission "
11418 + "READ_BASIC_PHONE_STATE.");
11419 }
11420
11421 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011422 if (phone == null) {
11423 try {
11424 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11425 callback.accept(result);
11426 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11427 } catch (RemoteException e) {
11428 String logStr = "Purchase premium capability "
11429 + TelephonyManager.convertPremiumCapabilityToString(capability)
11430 + " failed due to RemoteException handling null phone: " + e;
11431 if (DBG) log(logStr);
11432 AnomalyReporter.reportAnomaly(
11433 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11434 }
11435 return;
11436 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011437 String appName;
11438 try {
11439 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11440 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11441 } catch (PackageManager.NameNotFoundException e) {
11442 appName = "An application";
11443 }
11444 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11445 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011446 }
11447
11448 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011449 * Register an IMS connection state callback
11450 */
11451 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011452 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11453 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011454 if (feature == ImsFeature.FEATURE_MMTEL) {
11455 // ImsMmTelManager
11456 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11457 TelephonyPermissions
11458 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11459 mApp, subId, "registerImsStateCallback");
11460 } else if (feature == ImsFeature.FEATURE_RCS) {
11461 // ImsRcsManager or SipDelegateManager
11462 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11463 Binder.getCallingUid(), "registerImsStateCallback",
11464 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11465 Manifest.permission.READ_PRECISE_PHONE_STATE,
11466 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11467 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11468 }
11469
11470 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11471 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11472 "IMS not available on device.");
11473 }
11474
11475 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11476 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11477 }
11478
11479 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11480 if (controller == null) {
11481 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11482 "IMS not available on device.");
11483 }
11484
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011485 if (callingPackage == null) {
11486 callingPackage = getCurrentPackageName();
11487 }
11488
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011489 final long token = Binder.clearCallingIdentity();
11490 try {
11491 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011492 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011493 } catch (ImsException e) {
11494 throw new ServiceSpecificException(e.getCode());
11495 } finally {
11496 Binder.restoreCallingIdentity(token);
11497 }
11498 }
11499
11500 /**
11501 * Unregister an IMS connection state callback
11502 */
11503 @Override
11504 public void unregisterImsStateCallback(IImsStateCallback cb) {
11505 final long token = Binder.clearCallingIdentity();
11506 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11507 if (controller == null) {
11508 return;
11509 }
11510 try {
11511 controller.unregisterImsStateCallback(cb);
11512 } finally {
11513 Binder.restoreCallingIdentity(token);
11514 }
11515 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011516
11517 /**
11518 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11519 *
11520 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11521 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11522 * SecurityException.
11523 * If there is current registered network this value will be same as the registered cell
11524 * identity. If the device goes out of service the previous cell identity is cached and
11525 * will be returned. If the cache age of the Cell identity is more than 24 hours
11526 * it will be cleared and null will be returned.
11527 *
11528 */
11529 @Override
11530 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11531 String callingFeatureId) {
11532 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11533 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11534 LocationAccessPolicy.checkLocationPermission(mApp,
11535 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11536 .setCallingPackage(callingPackage)
11537 .setCallingFeatureId(callingFeatureId)
11538 .setCallingPid(Binder.getCallingPid())
11539 .setCallingUid(Binder.getCallingUid())
11540 .setMethod("getLastKnownCellIdentity")
11541 .setLogAsInfo(true)
11542 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11543 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11544 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11545 .build());
11546
11547 boolean hasFinePermission =
11548 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11549 if (!hasFinePermission
11550 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11551 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011552 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011553 }
11554
11555 final long identity = Binder.clearCallingIdentity();
11556 try {
11557 Phone phone = getPhone(subId);
11558 if (phone == null) return null;
11559 ServiceStateTracker sst = phone.getServiceStateTracker();
11560 if (sst == null) return null;
11561 return sst.getLastKnownCellIdentity();
11562 } finally {
11563 Binder.restoreCallingIdentity(identity);
11564 }
11565 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011566
jimsun3b9ccac2021-10-26 15:01:23 +080011567 /**
11568 * Sets the modem service class Name that Telephony will bind to.
11569 *
11570 * @param serviceName The class name of the modem service.
11571 * @return true if the operation is succeed, otherwise false.
11572 */
11573 public boolean setModemService(String serviceName) {
11574 Log.d(LOG_TAG, "setModemService - " + serviceName);
11575 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11577 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11578 "setModemService");
11579 return mPhoneConfigurationManager.setModemService(serviceName);
11580 }
11581
11582 /**
11583 * Return the class name of the currently bounded modem service.
11584 *
11585 * @return the class name of the modem service.
11586 */
11587 public String getModemService() {
11588 String result;
11589 Log.d(LOG_TAG, "getModemService");
11590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11591 TelephonyPermissions
11592 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11593 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11594 "getModemService");
11595 result = mPhoneConfigurationManager.getModemService();
11596 Log.d(LOG_TAG, "result = " + result);
11597 return result;
11598 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011599
11600 @Override
11601 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11602 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11603 mApp.enforceCallingOrSelfPermission(
11604 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11605 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11606
11607 final long identity = Binder.clearCallingIdentity();
11608 try {
11609 Phone phone = getPhone(subId);
11610 if (phone == null) return;
11611 phone.setVoiceServiceStateOverride(hasService);
11612 } finally {
11613 Binder.restoreCallingIdentity(identity);
11614 }
11615 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011616
11617 /**
11618 * set removable eSIM as default eUICC.
11619 *
11620 * @hide
11621 */
11622 @Override
11623 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11624 enforceModifyPermission();
11625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11626
11627 final long identity = Binder.clearCallingIdentity();
11628 try {
11629 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11630 } finally {
11631 Binder.restoreCallingIdentity(identity);
11632 }
11633 }
11634
11635 /**
11636 * Returns whether the removable eSIM is default eUICC or not.
11637 *
11638 * @hide
11639 */
11640 @Override
11641 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11642 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11644
11645 final long identity = Binder.clearCallingIdentity();
11646 try {
11647 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11648 } finally {
11649 Binder.restoreCallingIdentity(identity);
11650 }
11651 }
11652
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011653 /**
11654 * Get the component name of the default app to direct respond-via-message intent for the
11655 * user associated with this subscription, update the cache if there is no respond-via-message
11656 * application currently configured for this user.
11657 * @return component name of the app and class to direct Respond Via Message intent to, or
11658 * {@code null} if the functionality is not supported.
11659 * @hide
11660 */
11661 @Override
11662 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11663 boolean updateIfNeeded) {
11664 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011665
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011666 Context context = getPhone(subId).getContext();
11667 UserHandle userHandle = null;
11668 final long identity = Binder.clearCallingIdentity();
11669 try {
11670 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11671 } finally {
11672 Binder.restoreCallingIdentity(identity);
11673 }
11674 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11675 updateIfNeeded, userHandle);
11676 }
Jack Yuf5badd92022-12-08 00:50:53 -080011677
11678 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011679 * Set whether the device is able to connect with null ciphering or integrity
11680 * algorithms. This is a global setting and will apply to all active subscriptions
11681 * and all new subscriptions after this.
11682 *
11683 * @param enabled when true, null cipher and integrity algorithms are allowed.
11684 * @hide
11685 */
11686 @Override
11687 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11688 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11689 enforceModifyPermission();
11690 checkForNullCipherAndIntegritySupport();
11691
11692 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11693 // for listening to these preference changes and applying them immediately.
11694 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11695 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11696 editor.apply();
11697
11698 for (Phone phone: PhoneFactory.getPhones()) {
11699 phone.handleNullCipherEnabledChange();
11700 }
11701 }
11702
11703
11704 /**
11705 * Get whether the device is able to connect with null ciphering or integrity
11706 * algorithms. Note that this retrieves the phone-global preference and not
11707 * the state of the radio.
11708 *
11709 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11710 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11711 * version for this feature.
11712 * @hide
11713 */
11714 @Override
11715 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11716 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11717 enforceReadPermission();
11718 checkForNullCipherAndIntegritySupport();
11719 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11720 }
11721
11722 private void checkForNullCipherAndIntegritySupport() {
11723 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11724 throw new UnsupportedOperationException(
11725 "Null cipher and integrity operations require HAL 2.1 or above");
11726 }
11727 }
11728
11729 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011730 * Get the SIM state for the slot index.
11731 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11732 *
11733 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11734 */
11735 @Override
11736 @SimState
11737 public int getSimStateForSlotIndex(int slotIndex) {
11738 IccCardConstants.State simState;
11739 if (slotIndex < 0) {
11740 simState = IccCardConstants.State.UNKNOWN;
11741 } else {
11742 Phone phone = null;
11743 try {
11744 phone = PhoneFactory.getPhone(slotIndex);
11745 } catch (IllegalStateException e) {
11746 // ignore
11747 }
11748 if (phone == null) {
11749 simState = IccCardConstants.State.UNKNOWN;
11750 } else {
11751 IccCard icc = phone.getIccCard();
11752 if (icc == null) {
11753 simState = IccCardConstants.State.UNKNOWN;
11754 } else {
11755 simState = icc.getState();
11756 }
11757 }
11758 }
11759 return simState.ordinal();
11760 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011761
11762 /**
11763 * Get current cell broadcast ranges.
11764 */
11765 @Override
11766 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11767 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11768 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11769 "getCellBroadcastIdRanges");
11770 final long identity = Binder.clearCallingIdentity();
11771 try {
11772 return getPhone(subId).getCellBroadcastIdRanges();
11773 } finally {
11774 Binder.restoreCallingIdentity(identity);
11775 }
11776 }
11777
11778 /**
11779 * Set reception of cell broadcast messages with the list of the given ranges
11780 *
11781 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11782 */
11783 @Override
11784 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11785 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11786 @Nullable IIntegerConsumer callback) {
11787 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11788 "setCellBroadcastIdRanges");
11789 final long identity = Binder.clearCallingIdentity();
11790 try {
11791 Phone phone = getPhoneFromSubId(subId);
11792 if (DBG) {
11793 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11794 }
11795 phone.setCellBroadcastIdRanges(ranges, result -> {
11796 if (callback != null) {
11797 try {
11798 callback.accept(result);
11799 } catch (RemoteException e) {
11800 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
11801 }
11802 }
11803 });
11804 } finally {
11805 Binder.restoreCallingIdentity(identity);
11806 }
11807 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000011808
11809 /**
11810 * Returns whether the device supports the domain selection service.
11811 *
11812 * @return {@code true} if the device supports the domain selection service.
11813 */
11814 @Override
11815 public boolean isDomainSelectionSupported() {
11816 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11817 "isDomainSelectionSupported");
11818
11819 final long identity = Binder.clearCallingIdentity();
11820 try {
11821 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
11822 } finally {
11823 Binder.restoreCallingIdentity(identity);
11824 }
11825 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011826}