blob: 6fc904765b000952337c5af2bf35d261754e0c86 [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
arunvoddud5c6ce02022-12-11 06:03:12 +00003475 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3476 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3477 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3478 callingFeatureId, "getPrimaryImei")) {
3479 throw new SecurityException("Caller does not have permission");
3480 }
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 for (Phone phone : PhoneFactory.getPhones()) {
3484 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3485 return phone.getImei();
3486 }
3487 }
3488 throw new UnsupportedOperationException("Operation not supported");
3489 } finally {
3490 Binder.restoreCallingIdentity(identity);
3491 }
3492 }
3493
3494 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003495 public String getTypeAllocationCodeForSlot(int slotIndex) {
3496 Phone phone = PhoneFactory.getPhone(slotIndex);
3497 String tac = null;
3498 if (phone != null) {
3499 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003500 try {
3501 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3502 } catch (IndexOutOfBoundsException e) {
3503 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3504 return null;
3505 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003506 }
3507 return tac;
3508 }
3509
3510 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003512 try {
3513 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3514 } catch (SecurityException se) {
3515 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3516 throw new SecurityException("Package " + callingPackage + " does not belong to "
3517 + Binder.getCallingUid());
3518 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003519 Phone phone = PhoneFactory.getPhone(slotIndex);
3520 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003521 return null;
3522 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003523
Jeff Davidson913390f2018-02-23 17:11:49 -08003524 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003525 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003527 return null;
3528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 return phone.getMeid();
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
Jack Yu2af8d712017-03-15 17:14:14 -07003536 }
3537
3538 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003539 public String getManufacturerCodeForSlot(int slotIndex) {
3540 Phone phone = PhoneFactory.getPhone(slotIndex);
3541 String manufacturerCode = null;
3542 if (phone != null) {
3543 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003544 try {
3545 manufacturerCode =
3546 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3547 } catch (IndexOutOfBoundsException e) {
3548 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3549 return null;
3550 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003551 }
3552 return manufacturerCode;
3553 }
3554
3555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3557 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003558 Phone phone = PhoneFactory.getPhone(slotIndex);
3559 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 return null;
3561 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003562 int subId = phone.getSubId();
3563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003564 mApp, subId, callingPackage, callingFeatureId,
3565 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003566 return null;
3567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 return phone.getDeviceSvn();
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003575 }
3576
fionaxu43304da2017-11-27 22:51:16 -08003577 @Override
3578 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
fionaxu43304da2017-11-27 22:51:16 -08003586 }
3587
3588 @Override
3589 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 final Phone phone = getPhone(subId);
3593 return phone == null ? null : phone.getCarrierName();
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
fionaxu43304da2017-11-27 22:51:16 -08003597 }
3598
calvinpanffe225e2018-11-01 19:43:06 +08003599 @Override
chen xu0026ca62019-03-06 15:28:50 -08003600 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 final Phone phone = getPhone(subId);
3604 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003605 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003606 } finally {
3607 Binder.restoreCallingIdentity(identity);
3608 }
3609 }
3610
3611 @Override
chen xu0026ca62019-03-06 15:28:50 -08003612 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003613 final long identity = Binder.clearCallingIdentity();
3614 try {
3615 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003616 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003617 } finally {
3618 Binder.restoreCallingIdentity(identity);
3619 }
3620 }
3621
chen xu651eec72018-11-11 19:03:44 -08003622 @Override
chen xu864e11c2018-12-06 22:10:03 -08003623 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3624 if (!isSubscriptionMccMnc) {
3625 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3626 }
chen xu651eec72018-11-11 19:03:44 -08003627 final Phone phone = PhoneFactory.getPhone(slotIndex);
3628 if (phone == null) {
3629 return TelephonyManager.UNKNOWN_CARRIER_ID;
3630 }
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
3637 }
3638
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 //
3640 // Internal helper methods.
3641 //
3642
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003643 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003644 * Make sure the caller is the calling package itself
3645 *
3646 * @throws SecurityException if the caller is not the calling package
3647 */
3648 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3649 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003650 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3651 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003652 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003653 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003654 } catch (PackageManager.NameNotFoundException e) {
3655 // packageUid is -1
3656 }
3657 if (packageUid != callingUid) {
3658 throw new SecurityException(message + ": Package " + callingPackage
3659 + " does not belong to " + callingUid);
3660 }
3661 }
3662
3663 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003664 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3665 *
3666 * @throws SecurityException if the caller does not have the required permission
3667 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003668 @VisibleForTesting
3669 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3671 }
3672
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003673 /**
3674 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3675 *
3676 * @throws SecurityException if the caller does not have the required permission
3677 */
3678 @VisibleForTesting
3679 public void enforceReadPermission() {
3680 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
3681 }
3682
Shuo Qian3b6ee772019-11-13 17:43:31 -08003683 private void enforceActiveEmergencySessionPermission() {
3684 mApp.enforceCallingOrSelfPermission(
3685 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3686 }
3687
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003688 /**
3689 * Make sure the caller has the CALL_PHONE permission.
3690 *
3691 * @throws SecurityException if the caller does not have the required permission
3692 */
3693 private void enforceCallPermission() {
3694 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3695 }
3696
paulhu5a773602019-08-23 19:17:33 +08003697 private void enforceSettingsPermission() {
3698 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003699 }
3700
Michele Berionne5e411512020-11-13 02:36:59 +00003701 private void enforceRebootPermission() {
3702 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3703 }
3704
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003705 private String createTelUrl(String number) {
3706 if (TextUtils.isEmpty(number)) {
3707 return null;
3708 }
3709
Jake Hambye994d462014-02-03 13:10:13 -08003710 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003711 }
3712
Ihab Awadf9e92732013-12-05 18:02:52 -08003713 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003714 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3715 }
3716
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003717 private static void logv(String msg) {
3718 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3719 }
3720
Ihab Awadf9e92732013-12-05 18:02:52 -08003721 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3723 }
3724
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003725 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003726 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003727 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003728 }
3729
Sanket Padawe356d7632015-06-22 14:03:32 -07003730 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003731 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 final Phone phone = PhoneFactory.getPhone(slotIndex);
3735 if (phone == null) {
3736 return PhoneConstants.PHONE_TYPE_NONE;
3737 } else {
3738 return phone.getPhoneType();
3739 }
3740 } finally {
3741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003743 }
3744
3745 /**
3746 * Returns the CDMA ERI icon index to display
3747 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003749 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3750 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3751 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003752 }
3753
Sanket Padawe356d7632015-06-22 14:03:32 -07003754 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003755 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3756 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003758 mApp, subId, callingPackage, callingFeatureId,
3759 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003760 return -1;
3761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 final Phone phone = getPhone(subId);
3766 if (phone != null) {
3767 return phone.getCdmaEriIconIndex();
3768 } else {
3769 return -1;
3770 }
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003774 }
3775
3776 /**
3777 * Returns the CDMA ERI icon mode,
3778 * 0 - ON
3779 * 1 - FLASHING
3780 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003782 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3783 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3784 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003785 }
3786
Sanket Padawe356d7632015-06-22 14:03:32 -07003787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003788 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3789 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003791 mApp, subId, callingPackage, callingFeatureId,
3792 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003793 return -1;
3794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 final Phone phone = getPhone(subId);
3799 if (phone != null) {
3800 return phone.getCdmaEriIconMode();
3801 } else {
3802 return -1;
3803 }
3804 } finally {
3805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003807 }
3808
3809 /**
3810 * Returns the CDMA ERI text,
3811 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003813 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3814 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3815 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003816 }
3817
Sanket Padawe356d7632015-06-22 14:03:32 -07003818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003819 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3820 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003822 mApp, subId, callingPackage, callingFeatureId,
3823 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003824 return null;
3825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826
3827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 if (phone != null) {
3831 return phone.getCdmaEriText();
3832 } else {
3833 return null;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003838 }
3839
3840 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003841 * Returns the CDMA MDN.
3842 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003844 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3846 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847
3848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003851 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852 return phone.getLine1Number();
3853 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003854 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 return null;
3856 }
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003859 }
3860 }
3861
3862 /**
3863 * Returns the CDMA MIN.
3864 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003865 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003866 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3868 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
3870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = getPhone(subId);
3873 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3874 return phone.getCdmaMin();
3875 } else {
3876 return null;
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003880 }
3881 }
3882
Hall Liud892bec2018-11-30 14:51:45 -08003883 @Override
3884 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3885 INumberVerificationCallback callback, String callingPackage) {
3886 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3887 != PERMISSION_GRANTED) {
3888 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3889 }
3890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3891
3892 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3893 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003894 throw new SecurityException("Calling package must be configured in the device config: "
3895 + "calling package: " + callingPackage
3896 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003897 }
3898
3899 if (range == null) {
3900 throw new NullPointerException("Range must be non-null");
3901 }
3902
3903 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003904 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003905
3906 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3907 }
3908
Junda Liuca05d5d2014-08-14 22:36:34 -07003909 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003910 * Returns true if CDMA provisioning needs to run.
3911 */
3912 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003915 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003919 }
3920
3921 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003922 * Sets the voice mail number of a given subId.
3923 */
3924 @Override
3925 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003926 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3927 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3932 new Pair<String, String>(alphaTag, number), new Integer(subId));
3933 return success;
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
3936 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003937 }
3938
Ta-wei Yen87c49842016-05-13 21:19:52 -07003939 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003940 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003942 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3943 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003944 if (!TextUtils.equals(callingPackage, systemDialer)) {
3945 throw new SecurityException("caller must be system dialer");
3946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3951 if (phoneAccountHandle == null) {
3952 return null;
3953 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003954 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 } finally {
3956 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003957 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003958 }
3959
3960 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003961 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3962 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003963 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003965 mApp, subId, callingPackage, callingFeatureId,
3966 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003967 return null;
3968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003970 final long identity = Binder.clearCallingIdentity();
3971 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003973 } finally {
3974 Binder.restoreCallingIdentity(identity);
3975 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003976 }
3977
3978 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003979 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3980 VisualVoicemailSmsFilterSettings settings) {
3981 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982
3983 final long identity = Binder.clearCallingIdentity();
3984 try {
3985 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003990 }
3991
3992 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003993 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3994 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003999 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004003 }
4004
4005 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004006 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4007 String callingPackage, int subId) {
4008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004013 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004017 }
4018
4019 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004020 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022
4023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004026 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004030 }
4031
4032 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004033 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4034 String callingAttributionTag, int subId, String number, int port, String text,
4035 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004037 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004038 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004039 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004040 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4041 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004042 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004043
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004044 /**
fionaxu0152e512016-11-14 13:36:14 -08004045 * Sets the voice activation state of a given subId.
4046 */
4047 @Override
4048 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4050 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 final Phone phone = getPhone(subId);
4055 if (phone != null) {
4056 phone.setVoiceActivationState(activationState);
4057 } else {
4058 loge("setVoiceActivationState fails with invalid subId: " + subId);
4059 }
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004062 }
4063 }
4064
4065 /**
4066 * Sets the data activation state of a given subId.
4067 */
4068 @Override
4069 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4071 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 final Phone phone = getPhone(subId);
4076 if (phone != null) {
4077 phone.setDataActivationState(activationState);
4078 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004079 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 }
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004083 }
4084 }
4085
4086 /**
4087 * Returns the voice activation state of a given subId.
4088 */
4089 @Override
4090 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 enforceReadPrivilegedPermission("getVoiceActivationState");
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.getVoiceActivationState();
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 /**
4107 * Returns the data activation state of a given subId.
4108 */
4109 @Override
4110 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
fionaxu0152e512016-11-14 13:36:14 -08004113 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 if (phone != null) {
4117 return phone.getDataActivationState();
4118 } else {
4119 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4120 }
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004123 }
4124 }
4125
4126 /**
Wink Saville36469e72014-06-11 15:17:00 -07004127 * Returns the unread count of voicemails for a subId
4128 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004130 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4131 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004133 mApp, subId, callingPackage, callingFeatureId,
4134 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004135 return 0;
4136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 final Phone phone = getPhone(subId);
4140 if (phone != null) {
4141 return phone.getVoiceMessageCount();
4142 } else {
4143 return 0;
4144 }
4145 } finally {
4146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004148 }
4149
4150 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004151 * returns true, if the device is in a state where both voice and data
4152 * are supported simultaneously. This can change based on location or network condition.
4153 */
4154 @Override
4155 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156 final long identity = Binder.clearCallingIdentity();
4157 try {
4158 final Phone phone = getPhone(subId);
4159 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004163 }
4164
4165 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004166 * Send the dialer code if called from the current default dialer or the caller has
4167 * carrier privilege.
4168 * @param inputCode The dialer code to send
4169 */
4170 @Override
4171 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004172 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004173 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004174 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4175 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004176 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004177 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004178 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180
4181 final long identity = Binder.clearCallingIdentity();
4182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004183 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
fionaxu235cc5e2017-03-06 22:25:57 -08004187 }
4188
Pengquan Menga1bb6272018-09-06 09:59:22 -07004189 @Override
4190 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004191 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004192 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004193 mApp, subId, "getNetworkSelectionMode");
4194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 if (!isActiveSubscription(subId)) {
4197 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4198 }
4199 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004202 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004203 }
4204
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004206 public boolean isInEmergencySmsMode() {
4207 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 for (Phone phone : PhoneFactory.getPhones()) {
4211 if (phone.isInEmergencySmsMode()) {
4212 return true;
4213 }
4214 }
4215 } finally {
4216 Binder.restoreCallingIdentity(identity);
4217 }
4218 return false;
4219 }
4220
shilu366312e2019-12-17 09:28:10 -08004221 /**
4222 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4223 * @param subId The subscription to use to check the configuration.
4224 * @param c The callback that will be used to send the result.
4225 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004226 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004227 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4228 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004229 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004230 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004231
4232 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4233 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4234 "IMS not available on device.");
4235 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 final long token = Binder.clearCallingIdentity();
4237 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004238 int slotId = getSlotIndexOrException(subId);
4239 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004240
4241 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4242 if (controller != null) {
4243 ImsManager imsManager = controller.getImsManager(subId);
4244 if (imsManager != null) {
4245 imsManager.addRegistrationCallbackForSubscription(c, subId);
4246 } else {
4247 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4248 }
4249 } else {
4250 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4251 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004252 } catch (ImsException e) {
4253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 } finally {
4255 Binder.restoreCallingIdentity(token);
4256 }
4257 }
4258
shilu366312e2019-12-17 09:28:10 -08004259 /**
4260 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4261 * @param subId The subscription to use to check the configuration.
4262 * @param c The callback that will be used to send the result.
4263 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004265 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004266 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004267 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004268 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4269 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4270 }
Meng Wangafbc5852019-09-19 17:37:13 -07004271 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004272
Meng Wangafbc5852019-09-19 17:37:13 -07004273 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004274 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4275 if (controller != null) {
4276 ImsManager imsManager = controller.getImsManager(subId);
4277 if (imsManager != null) {
4278 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4279 } else {
4280 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4281 + "is inactive, ignoring unregister.");
4282 // If the ImsManager is not valid, just return, since the callback
4283 // will already have been removed internally.
4284 }
4285 }
Meng Wangafbc5852019-09-19 17:37:13 -07004286 } finally {
4287 Binder.restoreCallingIdentity(token);
4288 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 }
4290
Brad Ebingera34a6c22019-10-22 17:36:18 -07004291 /**
4292 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4293 */
4294 @Override
4295 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4296 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4297 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4298 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4299 "IMS not available on device.");
4300 }
4301 final long token = Binder.clearCallingIdentity();
4302 try {
4303 Phone phone = getPhone(subId);
4304 if (phone == null) {
4305 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4306 + subId + "'");
4307 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4308 }
4309 phone.getImsRegistrationState(regState -> {
4310 try {
4311 consumer.accept((regState == null)
4312 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4313 } catch (RemoteException e) {
4314 // Ignore if the remote process is no longer available to call back.
4315 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4316 }
4317 });
4318 } finally {
4319 Binder.restoreCallingIdentity(token);
4320 }
4321 }
4322
4323 /**
4324 * Get the transport type for the IMS service registration state.
4325 */
4326 @Override
4327 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004328 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004329 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004330 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4331 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4332 "IMS not available on device.");
4333 }
4334 final long token = Binder.clearCallingIdentity();
4335 try {
4336 Phone phone = getPhone(subId);
4337 if (phone == null) {
4338 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4339 + subId + "'");
4340 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4341 }
4342 phone.getImsRegistrationTech(regTech -> {
4343 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4344 int regTechConverted = (regTech == null)
4345 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4346 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4347 regTechConverted);
4348 try {
4349 consumer.accept(regTechConverted);
4350 } catch (RemoteException e) {
4351 // Ignore if the remote process is no longer available to call back.
4352 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4353 }
4354 });
4355 } finally {
4356 Binder.restoreCallingIdentity(token);
4357 }
4358 }
4359
shilu366312e2019-12-17 09:28:10 -08004360 /**
4361 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4362 * @param subId The subscription to use to check the configuration.
4363 * @param c The callback that will be used to send the result.
4364 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004366 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4367 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004369 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004370 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4371 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4372 "IMS not available on device.");
4373 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long token = Binder.clearCallingIdentity();
4375 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004376 int slotId = getSlotIndexOrException(subId);
4377 verifyImsMmTelConfiguredOrThrow(slotId);
4378 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004379 } catch (ImsException e) {
4380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 } finally {
4382 Binder.restoreCallingIdentity(token);
4383 }
4384 }
4385
shilu366312e2019-12-17 09:28:10 -08004386 /**
4387 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4388 * @param subId The subscription to use to check the configuration.
4389 * @param c The callback that will be used to send the result.
4390 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004392 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004394 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4396 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4397 }
Meng Wangafbc5852019-09-19 17:37:13 -07004398
4399 final long token = Binder.clearCallingIdentity();
4400 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004401 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004402 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004403 } catch (ImsException e) {
4404 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4405 + "is inactive, ignoring unregister.");
4406 // If the subscription is no longer active, just return, since the callback
4407 // will already have been removed internally.
4408 } finally {
4409 Binder.restoreCallingIdentity(token);
4410 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004411 }
4412
4413 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004414 public boolean isCapable(int subId, int capability, int regTech) {
4415 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 final long token = Binder.clearCallingIdentity();
4417 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004418 int slotId = getSlotIndexOrException(subId);
4419 verifyImsMmTelConfiguredOrThrow(slotId);
4420 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4421 } catch (com.android.ims.ImsException e) {
4422 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4423 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004424 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004425 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4426 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 } finally {
4428 Binder.restoreCallingIdentity(token);
4429 }
4430 }
4431
4432 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004433 public boolean isAvailable(int subId, int capability, int regTech) {
4434 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 final long token = Binder.clearCallingIdentity();
4436 try {
4437 Phone phone = getPhone(subId);
4438 if (phone == null) return false;
4439 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004440 } catch (com.android.ims.ImsException e) {
4441 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4442 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 } finally {
4444 Binder.restoreCallingIdentity(token);
4445 }
4446 }
4447
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004448 /**
4449 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4450 * subscription.
4451 * @param subId The subscription to use to check the configuration.
4452 * @param callback The callback that will be used to send the result.
4453 * @param capability The MmTelFeature capability that will be used to send the result.
4454 * @param transportType The transport type of the MmTelFeature capability.
4455 */
4456 @Override
4457 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4458 int transportType) {
4459 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004460 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4461 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4462 "IMS not available on device.");
4463 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004464 final long token = Binder.clearCallingIdentity();
4465 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004466 int slotId = getSlotIndex(subId);
4467 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4468 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4469 + subId + "'");
4470 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4471 }
4472 verifyImsMmTelConfiguredOrThrow(slotId);
4473 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4474 transportType, aBoolean -> {
4475 try {
4476 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4477 } catch (RemoteException e) {
4478 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4479 + "running. Ignore");
4480 }
4481 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004484 } finally {
4485 Binder.restoreCallingIdentity(token);
4486 }
4487 }
4488
shilu366312e2019-12-17 09:28:10 -08004489 /**
4490 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4491 * @param subId The subscription to use to check the configuration.
4492 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 @Override
4494 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004495 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004496 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004497
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 final long token = Binder.clearCallingIdentity();
4499 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004501 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004503 } catch (ImsException e) {
4504 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 } finally {
4506 Binder.restoreCallingIdentity(token);
4507 }
4508 }
4509
4510 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004511 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004513 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004516 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004517 // This setting doesn't require an active ImsService connection, so do not verify. The
4518 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004527 /**
4528 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4529 * @param subId The subscription to use to check the configuration.
4530 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004531 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004532 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004533 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004534 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 final long identity = Binder.clearCallingIdentity();
4536 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004538 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 } catch (ImsException e) {
4541 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 } finally {
4543 Binder.restoreCallingIdentity(identity);
4544 }
4545 }
4546
4547 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004548 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004550 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004551 final long identity = Binder.clearCallingIdentity();
4552 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004553 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004554 // This setting doesn't require an active ImsService connection, so do not verify. The
4555 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004564 /**
4565 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4566 * @param subId The subscription to use to check the configuration.
4567 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004568 @Override
4569 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004570 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004571 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 final long identity = Binder.clearCallingIdentity();
4573 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004574 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004575 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004576 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004577 } catch (ImsException e) {
4578 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
4582 }
4583
4584 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004585 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004587 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004590 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004591 // This setting doesn't require an active ImsService connection, so do not verify. The
4592 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004593 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004594 } catch (ImsException e) {
4595 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
4599 }
4600
shilu366312e2019-12-17 09:28:10 -08004601 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004602 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4603 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4604 * @param subId The subscription to use to check the configuration.
4605 */
4606 @Override
4607 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004609 mApp, subId, "isCrossSimCallingEnabledByUser");
4610 final long identity = Binder.clearCallingIdentity();
4611 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004612 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004613 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004614 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004615 } catch (ImsException e) {
4616 throw new ServiceSpecificException(e.getCode());
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
4619 }
4620 }
4621
4622 /**
4623 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4624 * Requires MODIFY_PHONE_STATE permission.
4625 * @param subId The subscription to use to check the configuration.
4626 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4627 * false otherwise
4628 */
4629 @Override
4630 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4632 "setCrossSimCallingEnabled");
4633 final long identity = Binder.clearCallingIdentity();
4634 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004635 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004636 // This setting doesn't require an active ImsService connection, so do not verify. The
4637 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004638 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004639 } catch (ImsException e) {
4640 throw new ServiceSpecificException(e.getCode());
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
4644 }
4645
4646 /**
shilu366312e2019-12-17 09:28:10 -08004647 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4648 * @param subId The subscription to use to check the configuration.
4649 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004650 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004651
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004653 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004654 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004655 final long identity = Binder.clearCallingIdentity();
4656 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004657 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004658 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004659 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004660 } catch (ImsException e) {
4661 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
4665 }
4666
4667 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004668 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004670 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004671 final long identity = Binder.clearCallingIdentity();
4672 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004673 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004674 // This setting doesn't require an active ImsService connection, so do not verify. The
4675 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004676 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004677 } catch (ImsException e) {
4678 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004679 } finally {
4680 Binder.restoreCallingIdentity(identity);
4681 }
4682 }
4683
4684 @Override
4685 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4687 "setVoWiFiNonPersistent");
4688 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 will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
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
shilu366312e2019-12-17 09:28:10 -08004700 /**
4701 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4702 * @param subId The subscription to use to check the configuration.
4703 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 @Override
4705 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004706 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004707 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 final long identity = Binder.clearCallingIdentity();
4709 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004710 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004711 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004712 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004713 } catch (ImsException e) {
4714 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
4718 }
4719
4720 @Override
4721 public void setVoWiFiModeSetting(int subId, int mode) {
4722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4723 "setVoWiFiModeSetting");
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004726 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004727 // This setting doesn't require an active ImsService connection, so do not verify. The
4728 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004729 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004730 } catch (ImsException e) {
4731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
4735 }
4736
4737 @Override
4738 public int getVoWiFiRoamingModeSetting(int subId) {
4739 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4740 final long identity = Binder.clearCallingIdentity();
4741 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004742 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004743 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004744 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004745 } catch (ImsException e) {
4746 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
4750 }
4751
4752 @Override
4753 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4755 "setVoWiFiRoamingModeSetting");
4756 final long identity = Binder.clearCallingIdentity();
4757 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004758 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004759 // This setting doesn't require an active ImsService connection, so do not verify. The
4760 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004761 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004762 } catch (ImsException e) {
4763 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004764 } finally {
4765 Binder.restoreCallingIdentity(identity);
4766 }
4767 }
4768
4769 @Override
4770 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4772 "setRttCapabilityEnabled");
4773 final long identity = Binder.clearCallingIdentity();
4774 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004775 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004776 // This setting doesn't require an active ImsService connection, so do not verify. The
4777 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004778 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004786 /**
4787 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4788 * @param subId The subscription to use to check the configuration.
4789 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004790 @Override
4791 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004792 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004793 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 final long identity = Binder.clearCallingIdentity();
4795 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004796 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004797 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004798 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004799 } catch (ImsException e) {
4800 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
4804 }
4805
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004806 @Override
4807 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4808 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004809
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004810 final long identity = Binder.clearCallingIdentity();
4811 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004812 if (!isImsAvailableOnDevice()) {
4813 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4814 "IMS not available on device.");
4815 }
4816 int slotId = getSlotIndexOrException(subId);
4817 verifyImsMmTelConfiguredOrThrow(slotId);
4818 ImsManager.getInstance(mApp, slotId)
4819 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004820 } catch (ImsException e) {
4821 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
4825 }
4826
4827 @Override
4828 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4829 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004830
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004831 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004832 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4833 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4834 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004835 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004836 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004837 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004838 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004839 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4840 + "is inactive, ignoring unregister.");
4841 // If the subscription is no longer active, just return, since the callback will already
4842 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004843 } finally {
4844 Binder.restoreCallingIdentity(identity);
4845 }
4846 }
4847
joonhunshincffb7fc2021-11-28 07:32:01 +00004848 @Override
4849 public void registerFeatureProvisioningChangedCallback(int subId,
4850 IFeatureProvisioningCallback callback) {
4851 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4852 mApp, subId, "registerFeatureProvisioningChangedCallback");
4853
4854 final long identity = Binder.clearCallingIdentity();
4855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4856 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4857 }
4858
joonhunshin91bc1952022-04-29 08:47:15 +00004859 try {
4860 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4861 if (controller == null) {
4862 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4863 "Device does not support IMS");
4864 }
4865 controller.addFeatureProvisioningChangedCallback(subId, callback);
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004869 }
4870
4871 @Override
4872 public void unregisterFeatureProvisioningChangedCallback(int subId,
4873 IFeatureProvisioningCallback callback) {
4874 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4875 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4876
4877 final long identity = Binder.clearCallingIdentity();
4878 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4879 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4880 }
4881
joonhunshin91bc1952022-04-29 08:47:15 +00004882 try {
4883 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4884 if (controller == null) {
4885 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4886 return;
4887 }
4888 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004892 }
allenwtsu99c623b2020-01-03 18:24:23 +08004893
4894 private void checkModifyPhoneStatePermission(int subId, String message) {
4895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4896 message);
4897 }
4898
allenwtsu99c623b2020-01-03 18:24:23 +08004899 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004900 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004901 boolean isProvisioned) {
4902 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4903
4904 final long identity = Binder.clearCallingIdentity();
4905 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004906 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4907 if (controller == null) {
4908 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4909 return;
4910 }
4911 controller.setRcsProvisioningStatusForCapability(
4912 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
allenwtsu99c623b2020-01-03 18:24:23 +08004916 }
4917
4918
4919 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004920 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4921 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4922 mApp, subId, "getRcsProvisioningStatusForCapability");
4923
allenwtsu99c623b2020-01-03 18:24:23 +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("getRcsProvisioningStatusForCapability: Device does not support IMS");
4929
4930 // device does not support IMS, this method will return true always.
4931 return true;
4932 }
4933 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
4937 }
4938
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004939 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4941 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004942 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004943
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 final long identity = Binder.clearCallingIdentity();
4945 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004946 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4947 if (controller == null) {
4948 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4949 return;
4950 }
4951 controller.setImsProvisioningStatusForCapability(
4952 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
4956 }
4957
4958 @Override
4959 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004960 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4961 mApp, subId, "getProvisioningStatusForCapability");
4962
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004963 final long identity = Binder.clearCallingIdentity();
4964 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004965 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4966 if (controller == null) {
4967 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968
joonhunshin91bc1952022-04-29 08:47:15 +00004969 // device does not support IMS, this method will return true always.
4970 return true;
4971 }
4972 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
4976 }
4977
4978 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004979 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4980 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4981 mApp, subId, "isProvisioningRequiredForCapability");
4982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004985 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4986 if (controller == null) {
4987 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4988
4989 // device does not support IMS, this method will return false
4990 return false;
4991 }
4992 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004995 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 }
4997
4998 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004999 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5000 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5001 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005002
joonhunshincffb7fc2021-11-28 07:32:01 +00005003 final long identity = Binder.clearCallingIdentity();
5004 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005005 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5006 if (controller == null) {
5007 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5008
5009 // device does not support IMS, this method will return false
5010 return false;
5011 }
5012 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005016 }
5017
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005018 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005019 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005020 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5021 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5022 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005023 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5024 mApp, subId, "getImsProvisioningInt");
5025
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005029 int slotId = getSlotIndex(subId);
5030 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5031 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5032 + subId + "' for key:" + key);
5033 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5034 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005035
joonhunshin91bc1952022-04-29 08:47:15 +00005036 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5037 if (controller == null) {
5038 loge("getImsProvisioningInt: Device does not support IMS");
5039
5040 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5041 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5042 }
5043 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005044 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5045 return retVal;
5046 }
5047
calvinpanb5a34062021-02-08 19:59:36 +08005048 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005049 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005050 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5051 + subId + "' for key:" + key);
5052 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005053 } finally {
5054 Binder.restoreCallingIdentity(identity);
5055 }
5056 }
5057
5058 @Override
5059 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005060 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5061 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5062 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005063 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5064 mApp, subId, "getImsProvisioningString");
5065
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005069 int slotId = getSlotIndex(subId);
5070 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5071 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5072 + subId + "' for key:" + key);
5073 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5074 }
calvinpanb5a34062021-02-08 19:59:36 +08005075 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005076 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5078 + subId + "' for key:" + key);
5079 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
5083 }
5084
5085 @Override
5086 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005087 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5088 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5089 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5091 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005092
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005096 int slotId = getSlotIndex(subId);
5097 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5098 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5099 + subId + "' for key:" + key);
5100 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5101 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005102
joonhunshin91bc1952022-04-29 08:47:15 +00005103 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5104 if (controller == null) {
5105 loge("setImsProvisioningInt: Device does not support IMS");
5106
5107 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5108 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5109 }
5110 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005111 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5112 return retVal;
5113 }
5114
calvinpanb5a34062021-02-08 19:59:36 +08005115 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5116 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005117 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005118 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005119 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005120 } finally {
5121 Binder.restoreCallingIdentity(identity);
5122 }
5123 }
5124
5125 @Override
5126 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005127 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5128 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5129 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5131 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005135 int slotId = getSlotIndex(subId);
5136 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5137 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5138 + subId + "' for key:" + key);
5139 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5140 }
calvinpanb5a34062021-02-08 19:59:36 +08005141 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5142 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005143 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005144 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005145 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
5149 }
5150
Brad Ebinger919631e2021-06-02 17:46:35 -07005151 /**
5152 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5153 * for the given slot ID or no ImsResolver instance has been created.
5154 * @param slotId The slot ID that the IMS service is created for.
5155 * @throws ImsException If there is no ImsService configured for this slot.
5156 */
5157 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5158 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5159 ImsFeature.FEATURE_MMTEL)) {
5160 throw new ImsException("This subscription does not support MMTEL over IMS",
5161 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5162 }
5163 }
5164
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005165 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005166 int slotId = SubscriptionManager.getSlotIndex(subId);
5167 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005168 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5169 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005170 }
5171 return slotId;
5172 }
5173
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005174 private int getSlotIndex(int subId) {
5175 int slotId = SubscriptionManager.getSlotIndex(subId);
5176 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5177 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5178 }
5179 return slotId;
5180 }
5181
Wink Saville36469e72014-06-11 15:17:00 -07005182 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005183 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005184 */
5185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005186 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5187 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005188 try {
5189 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5190 } catch (SecurityException se) {
5191 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5192 throw new SecurityException("Package " + callingPackage + " does not belong to "
5193 + Binder.getCallingUid());
5194 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005195 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005196 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005197 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005198 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005199 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005200 mApp, subId, callingPackage, callingFeatureId,
5201 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005202 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5203 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 final Phone phone = getPhone(subId);
5208 if (phone != null) {
5209 return phone.getServiceState().getDataNetworkType();
5210 } else {
5211 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5212 }
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005216 }
5217
5218 /**
5219 * Returns the data network type
5220 */
5221 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005222 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005223 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005224 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005225 }
5226
5227 /**
5228 * Returns the data network type for a subId
5229 */
5230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005231 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5232 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005233 String functionName = "getDataNetworkTypeForSubscriber";
5234 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5235 mApp, functionName)) {
5236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5237 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5238 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5239 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005240 }
5241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 final long identity = Binder.clearCallingIdentity();
5243 try {
5244 final Phone phone = getPhone(subId);
5245 if (phone != null) {
5246 return phone.getServiceState().getDataNetworkType();
5247 } else {
5248 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5249 }
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005253 }
5254
5255 /**
Wink Saville36469e72014-06-11 15:17:00 -07005256 * Returns the Voice network type for a subId
5257 */
5258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005259 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5260 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005261 String functionName = "getVoiceNetworkTypeForSubscriber";
5262 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5263 mApp, functionName)) {
5264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5265 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5267 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005268 }
5269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 final Phone phone = getPhone(subId);
5273 if (phone != null) {
5274 return phone.getServiceState().getVoiceNetworkType();
5275 } else {
5276 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5277 }
5278 } finally {
5279 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005281 }
5282
5283 /**
5284 * @return true if a ICC card is present
5285 */
5286 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005287 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005288 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005289 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005290 }
5291
5292 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005293 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005294 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005295 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005296 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 final Phone phone = PhoneFactory.getPhone(slotIndex);
5300 if (phone != null) {
5301 return phone.getIccCard().hasIccCard();
5302 } else {
5303 return false;
5304 }
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005308 }
5309
5310 /**
5311 * Return if the current radio is LTE on CDMA. This
5312 * is a tri-state return value as for a period of time
5313 * the mode may be unknown.
5314 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005315 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005316 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005317 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005318 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005319 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005320 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5321 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5322 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005323 }
5324
Sanket Padawe356d7632015-06-22 14:03:32 -07005325 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005326 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5327 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005328 try {
5329 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5330 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005331 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5332 }
5333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 final Phone phone = getPhone(subId);
5337 if (phone == null) {
5338 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5339 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005340 return TelephonyProperties.lte_on_cdma_device()
5341 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 }
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005345 }
Wink Saville36469e72014-06-11 15:17:00 -07005346 }
5347
Wink Saville36469e72014-06-11 15:17:00 -07005348 /**
5349 * {@hide}
5350 * Returns Default subId, 0 in the case of single standby.
5351 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005352 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005353 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005354 }
5355
Shishir Agrawala9f32182016-04-12 12:00:16 -07005356 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005357 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005358 }
5359
Wink Savilleb564aae2014-10-23 10:18:09 -07005360 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005361 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005362 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005363
Pengquan Menge92a50d2018-09-21 15:54:48 -07005364 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005365 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5366 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5367 mApp.getOpPackageName(), mApp.getFeatureId());
5368 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005369 return mSubscriptionController.isActiveSubId(subId);
5370 }
5371
Ihab Awadf2177b72013-11-25 13:33:23 -08005372 /**
5373 * @see android.telephony.TelephonyManager.WifiCallingChoices
5374 */
5375 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005378 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5380 getWhenToMakeWifiCallsDefaultPreference());
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005384 }
5385
5386 /**
5387 * @see android.telephony.TelephonyManager.WifiCallingChoices
5388 */
5389 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005393 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005398 }
5399
Sailesh Nepald1e68152013-12-12 19:08:02 -08005400 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005401 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005402 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005403 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005404
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005405 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5406 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5407 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005408 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005409 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5410 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005411 }
5412 return PhoneFactory.getPhone(phoneId);
5413 }
5414
Shishir Agrawal566b7612013-10-28 14:41:00 -07005415 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005416 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005417 @NonNull IccLogicalChannelRequest request) {
5418 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5419 /*message=*/ "iccOpenLogicalChannel");
5420
5421 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5422 // Verify that the callingPackage in the request belongs to the calling UID
5423 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5424
5425 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005426 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005427
Rambo Wanga1782702021-11-10 20:15:19 -08005428 private Phone getPhoneFromValidIccLogicalChannelRequest(
5429 @NonNull IccLogicalChannelRequest request, String message) {
5430 Phone phone;
5431 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5433 mApp, request.subId, message);
5434 phone = getPhoneFromSubId(request.subId);
5435 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5436 enforceModifyPermission();
5437 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5438 } else {
5439 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005440 }
Rambo Wanga1782702021-11-10 20:15:19 -08005441 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005442 }
5443
5444 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005445 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005448 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005450 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5451 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005452 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5453 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 loge("The calling package is not allowed to access ISD-R.");
5455 throw new SecurityException(
5456 "The calling package is not allowed to access ISD-R.");
5457 }
Derek Tan740e1672017-06-27 14:56:27 -07005458 }
Derek Tan740e1672017-06-27 14:56:27 -07005459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005461 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5462 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 return response;
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005467 }
5468
5469 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005470 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5471 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5472 /*message=*/"iccCloseLogicalChannel");
5473
5474 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5475
5476 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005478
Rambo Wanga1782702021-11-10 20:15:19 -08005479 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5480 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005481 // before this feature is enabled, this API should only return false if
5482 // the operation fails instead of throwing runtime exception for
5483 // backward-compatibility.
5484 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5485 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 final long identity = Binder.clearCallingIdentity();
5487 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005488 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005489 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 }
Chen Xue9d737e2022-01-01 23:41:31 -08005491 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005492 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005493 Boolean success = false;
5494 if (result instanceof RuntimeException) {
5495 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005496 if (shouldThrowExceptionOnFailure) {
5497 throw (RuntimeException) result;
5498 } else {
5499 return false;
5500 }
Chen Xue9d737e2022-01-01 23:41:31 -08005501 } else if (result instanceof Boolean) {
5502 success = (Boolean) result;
5503 } else {
5504 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5505 }
Rambo Wanga1782702021-11-10 20:15:19 -08005506 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 return success;
5508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005510 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005511 }
5512
5513 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005514 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005515 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5517 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005518 if (DBG) {
5519 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5520 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5521 + p3 + " data=" + data);
5522 }
5523 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5524 command, p1, p2, p3, data);
5525 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005526
Jordan Liu4c733742019-02-28 12:03:40 -08005527 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005528 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5529 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005530 enforceModifyPermission();
5531 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005532 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5533 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5534 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005535 }
5536 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005537 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5538 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
5540
5541 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5542 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 final long identity = Binder.clearCallingIdentity();
5544 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005545 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 return "";
5547 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005550 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5551 null /* workSource */);
5552 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 // Append the returned status code to the end of the response payload.
5555 String s = Integer.toHexString(
5556 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5557 if (response.payload != null) {
5558 s = IccUtils.bytesToHexString(response.payload) + s;
5559 }
5560 return s;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005564 }
Jake Hambye994d462014-02-03 13:10:13 -08005565
Evan Charltonc66da362014-05-16 14:06:40 -07005566 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005567 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5568 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5570 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005572 if (DBG) {
5573 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5574 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5575 }
5576 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5577 cla, command, p1, p2, p3, data);
5578 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005579
Jordan Liu4c733742019-02-28 12:03:40 -08005580 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005581 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5582 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005583 enforceModifyPermission();
5584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5585 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005586 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5587 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5588 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005589 }
5590
5591 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005592 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5593 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005594 }
5595
5596 // open APDU basic channel assuming the caller has sufficient permissions
5597 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5598 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 final long identity = Binder.clearCallingIdentity();
5600 try {
5601 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5602 && TextUtils.equals(ISDR_AID, data)) {
5603 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005604 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5605 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 if (bestComponent == null
5607 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5608 loge("The calling package is not allowed to select ISD-R.");
5609 throw new SecurityException(
5610 "The calling package is not allowed to select ISD-R.");
5611 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005612 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005615 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5616 null /* workSource */);
5617 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 // Append the returned status code to the end of the response payload.
5620 String s = Integer.toHexString(
5621 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5622 if (response.payload != null) {
5623 s = IccUtils.bytesToHexString(response.payload) + s;
5624 }
5625 return s;
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005628 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005629 }
5630
5631 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005632 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005633 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 if (DBG) {
5640 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5641 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5642 }
5643
5644 IccIoResult response =
5645 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5646 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5647 subId);
5648
5649 if (DBG) {
5650 log("Exchange SIM_IO [R]" + response);
5651 }
5652
5653 byte[] result = null;
5654 int length = 2;
5655 if (response.payload != null) {
5656 length = 2 + response.payload.length;
5657 result = new byte[length];
5658 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5659 } else {
5660 result = new byte[length];
5661 }
5662
5663 result[length - 1] = (byte) response.sw2;
5664 result[length - 2] = (byte) response.sw1;
5665 return result;
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005668 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005669 }
5670
Nathan Haroldb3014052017-01-25 15:57:32 -08005671 /**
5672 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5673 * on a particular subscription
5674 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005675 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5676 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005678 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005679 return null;
5680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
5684 if (appType != TelephonyManager.APPTYPE_USIM
5685 && appType != TelephonyManager.APPTYPE_SIM) {
5686 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5687 return null;
5688 }
5689 Object response = sendRequest(
5690 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5691 if (response instanceof String[]) {
5692 return (String[]) response;
5693 }
yincheng zhao2737e882019-09-06 17:06:54 -07005694 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005696 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 } finally {
5698 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005699 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005700 }
5701
yincheng zhao2737e882019-09-06 17:06:54 -07005702 /**
5703 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5704 * subscription.
5705 *
5706 * @param subId the id of the subscription.
5707 * @param appType the uicc app type, must be USIM or SIM.
5708 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5709 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005710 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005711 * @return number of fplmns that is successfully written to the SIM.
5712 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005713 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5714 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5716 mApp, subId, "setForbiddenPlmns");
5717
yincheng zhao2737e882019-09-06 17:06:54 -07005718 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5719 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5720 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5721 }
5722 if (fplmns == null) {
5723 throw new IllegalArgumentException("Fplmn List provided is null");
5724 }
5725 for (String fplmn : fplmns) {
5726 if (!CellIdentity.isValidPlmn(fplmn)) {
5727 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5728 }
5729 }
5730 final long identity = Binder.clearCallingIdentity();
5731 try {
5732 Object response = sendRequest(
5733 CMD_SET_FORBIDDEN_PLMNS,
5734 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5735 subId);
5736 return (int) response;
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005742 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005743 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5745 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5750 if (response.payload == null) {
5751 return "";
5752 }
Evan Charltonc66da362014-05-16 14:06:40 -07005753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 // Append the returned status code to the end of the response payload.
5755 String s = Integer.toHexString(
5756 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5757 s = IccUtils.bytesToHexString(response.payload) + s;
5758 return s;
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
Evan Charltonc66da362014-05-16 14:06:40 -07005762 }
5763
Jake Hambye994d462014-02-03 13:10:13 -08005764 /**
5765 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5766 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5767 *
5768 * @param itemID the ID of the item to read
5769 * @return the NV item as a String, or null on error.
5770 */
5771 @Override
5772 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005773 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5775 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776
5777 final long identity = Binder.clearCallingIdentity();
5778 try {
5779 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005780 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5782 return value;
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
Jake Hambye994d462014-02-03 13:10:13 -08005786 }
5787
5788 /**
5789 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5790 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5791 *
5792 * @param itemID the ID of the item to read
5793 * @param itemValue the value to write, as a String
5794 * @return true on success; false on any failure
5795 */
5796 @Override
5797 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005798 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5800 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5805 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005806 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5808 return success;
5809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
Jake Hambye994d462014-02-03 13:10:13 -08005812 }
5813
5814 /**
5815 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5816 * Used for device configuration by some CDMA operators.
5817 *
5818 * @param preferredRoamingList byte array containing the new PRL
5819 * @return true on success; false on any failure
5820 */
5821 @Override
5822 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5824 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825
5826 final long identity = Binder.clearCallingIdentity();
5827 try {
5828 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5829 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5830 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5831 return success;
5832 } finally {
5833 Binder.restoreCallingIdentity(identity);
5834 }
Jake Hambye994d462014-02-03 13:10:13 -08005835 }
5836
5837 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005838 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005839 * Used for device configuration by some CDMA operators.
5840 *
chen xu6dac5ab2018-10-26 17:39:23 -07005841 * @param slotIndex - device slot.
5842 *
Jake Hambye994d462014-02-03 13:10:13 -08005843 * @return true on success; false on any failure
5844 */
5845 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005846 public boolean resetModemConfig(int slotIndex) {
5847 Phone phone = PhoneFactory.getPhone(slotIndex);
5848 if (phone != null) {
5849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5850 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851
chen xu6dac5ab2018-10-26 17:39:23 -07005852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5855 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5856 return success;
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 }
chen xu6dac5ab2018-10-26 17:39:23 -07005861 return false;
5862 }
5863
5864 /**
5865 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5866 *
5867 * @param slotIndex - device slot.
5868 *
5869 * @return true on success; false on any failure
5870 */
5871 @Override
5872 public boolean rebootModem(int slotIndex) {
5873 Phone phone = PhoneFactory.getPhone(slotIndex);
5874 if (phone != null) {
5875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5876 mApp, phone.getSubId(), "rebootModem");
5877
5878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5881 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5882 return success;
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
5886 }
5887 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005888 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005889
Brad Ebinger51f743a2017-01-23 13:50:20 -08005890 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005891 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5892 * {@link #disableIms(int)}.
5893 * @param slotIndex device slot.
5894 */
5895 public void resetIms(int slotIndex) {
5896 enforceModifyPermission();
5897
5898 final long identity = Binder.clearCallingIdentity();
5899 try {
5900 if (mImsResolver == null) {
5901 // may happen if the does not support IMS.
5902 return;
5903 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005904 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
5908 }
5909
5910 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005911 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5912 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005913 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005914 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005919 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005920 // may happen if the device does not support IMS.
5921 return;
5922 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005923 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005927 }
5928
5929 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005930 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5931 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005932 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005933 public void disableIms(int slotId) {
5934 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 Ebinger9c0eb502019-01-23 15:06:19 -08005939 // may happen if the device does not support IMS.
5940 return;
5941 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005946 }
5947
5948 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005949 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5950 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005951 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005952 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005953 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
5957 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005958 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005959 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5960 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005961 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005962 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005966 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005967 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005968 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5969 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005970 @Override
5971 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005972 enforceModifyPermission();
5973
5974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005977 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005978 } finally {
5979 Binder.restoreCallingIdentity(identity);
5980 }
5981 }
5982
5983 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005984 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005985 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005986 */
5987 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989
5990 final long identity = Binder.clearCallingIdentity();
5991 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005992 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005993 // may happen if the device does not support IMS.
5994 return null;
5995 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005996 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006000 }
6001
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006002 /**
6003 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006004 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006005 */
6006 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008
6009 final long identity = Binder.clearCallingIdentity();
6010 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006011 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006012 // may happen if the device does not support IMS.
6013 return null;
6014 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006015 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006019 }
6020
Brad Ebinger884c07b2018-02-15 16:17:40 -08006021 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006022 * Sets the ImsService Package Name that Telephony will bind to.
6023 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006024 * @param slotIndex the slot ID that the ImsService should bind for.
6025 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006026 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006027 * @param featureTypes An integer array of feature types associated with a packageName.
6028 * @param packageName The name of the package that the current configuration will be replaced
6029 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006030 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006031 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006032 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6033 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006036 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 final long identity = Binder.clearCallingIdentity();
6039 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006040 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006041 // may happen if the device does not support IMS.
6042 return false;
6043 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006044 Map<Integer, String> featureConfig = new HashMap<>();
6045 for (int featureType : featureTypes) {
6046 featureConfig.put(featureType, packageName);
6047 }
6048 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6049 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006053 }
6054
6055 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006056 * Clears any carrier ImsService overrides for the slot index specified that were previously
6057 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6058 *
6059 * This should only be used for testing.
6060 *
6061 * @param slotIndex the slot ID that the ImsService should bind for.
6062 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6063 */
6064 @Override
6065 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006066 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6067 "clearCarrierImsServiceOverride");
6068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006069 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006070
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 if (mImsResolver == null) {
6074 // may happen if the device does not support IMS.
6075 return false;
6076 }
6077 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
6080 }
6081 }
6082
6083 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006084 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006085 *
6086 * @param slotId The slot that the ImsService is associated with.
6087 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6088 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006089 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006090 * @return the package name of the ImsService configuration.
6091 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006092 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6093 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006094 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006095 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6096 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 final long identity = Binder.clearCallingIdentity();
6099 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006100 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006101 // may happen if the device does not support IMS.
6102 return "";
6103 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006104 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006105 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6106 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006110 }
6111
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006112 /**
6113 * Get the MmTelFeature state associated with the requested subscription id.
6114 * @param subId The subscription that the MmTelFeature is associated with.
6115 * @param callback A callback with an integer containing the
6116 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6117 */
6118 @Override
6119 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6120 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006121 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6122 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6123 "IMS not available on device.");
6124 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006125 final long token = Binder.clearCallingIdentity();
6126 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006127 int slotId = getSlotIndex(subId);
6128 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6129 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6130 + subId + "'");
6131 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6132 }
6133 verifyImsMmTelConfiguredOrThrow(slotId);
6134 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6135 try {
6136 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6137 } catch (RemoteException e) {
6138 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6139 + "Ignore");
6140 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006141 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006142 } catch (ImsException e) {
6143 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006144 } finally {
6145 Binder.restoreCallingIdentity(token);
6146 }
6147 }
6148
Daniel Brightbb5840b2021-01-12 15:48:18 -08006149 /**
6150 * Sets the ims registration state on all valid {@link Phone}s.
6151 */
6152 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154
6155 final long identity = Binder.clearCallingIdentity();
6156 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006157 // NOTE: Before S, this method only set the default phone.
6158 for (final Phone phone : PhoneFactory.getPhones()) {
6159 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6160 phone.setImsRegistrationState(registered);
6161 }
6162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Wink Saville36469e72014-06-11 15:17:00 -07006166 }
6167
6168 /**
Stuart Scott54788802015-03-30 13:18:01 -07006169 * Set the network selection mode to automatic.
6170 *
6171 */
6172 @Override
6173 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6175 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176
6177 final long identity = Binder.clearCallingIdentity();
6178 try {
shilufc958392020-01-20 11:36:01 -08006179 if (!isActiveSubscription(subId)) {
6180 return;
6181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006183 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6184 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 } finally {
6186 Binder.restoreCallingIdentity(identity);
6187 }
Stuart Scott54788802015-03-30 13:18:01 -07006188 }
6189
Jack Yud10cdd42020-09-28 20:28:01 -07006190 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006191 * Ask the radio to connect to the input network and change selection mode to manual.
6192 *
6193 * @param subId the id of the subscription.
6194 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6195 * the operator to attach to.
6196 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6197 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6198 * normal network selection next time.
6199 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006200 */
6201 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006202 public boolean setNetworkSelectionModeManual(
6203 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6205 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006206
Jack Yu285100e2022-12-02 22:48:35 -08006207 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006208 if (!isActiveSubscription(subId)) {
6209 return false;
6210 }
6211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006213 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006215 if (DBG) {
6216 log("setNetworkSelectionModeManual: subId: " + subId
6217 + " operator: " + operatorInfo);
6218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6220 } finally {
6221 Binder.restoreCallingIdentity(identity);
6222 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006223 }
shilu84f6e8b2019-12-19 13:58:01 -08006224 /**
6225 * Get the manual network selection
6226 *
6227 * @param subId the id of the subscription.
6228 *
6229 * @return the previously saved user selected PLMN
6230 */
6231 @Override
6232 public String getManualNetworkSelectionPlmn(int subId) {
6233 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006234 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006235 mApp, subId, "getManualNetworkSelectionPlmn");
6236
6237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006240 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006241 }
6242
6243 final Phone phone = getPhone(subId);
6244 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006245 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006246 }
6247 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6248 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6249 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252 }
6253 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006254
6255 /**
6256 * Scans for available networks.
6257 */
6258 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006259 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6260 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6262 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006263 LocationAccessPolicy.LocationPermissionResult locationResult =
6264 LocationAccessPolicy.checkLocationPermission(mApp,
6265 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6266 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006267 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006268 .setCallingPid(Binder.getCallingPid())
6269 .setCallingUid(Binder.getCallingUid())
6270 .setMethod("getCellNetworkScanResults")
6271 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006272 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6273 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006274 .build());
6275 switch (locationResult) {
6276 case DENIED_HARD:
6277 throw new SecurityException("Not allowed to access scan results -- location");
6278 case DENIED_SOFT:
6279 return null;
6280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281
Pengquan Menga1bb6272018-09-06 09:59:22 -07006282 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 try {
6284 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006285 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006290 }
6291
6292 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006293 * Get the call forwarding info, given the call forwarding reason.
6294 */
6295 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006296 public void getCallForwarding(int subId, int callForwardingReason,
6297 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006298 enforceReadPrivilegedPermission("getCallForwarding");
6299 long identity = Binder.clearCallingIdentity();
6300 try {
6301 if (DBG) {
6302 log("getCallForwarding: subId " + subId
6303 + " callForwardingReason" + callForwardingReason);
6304 }
Hall Liu27d24262020-09-18 19:04:59 -07006305
6306 Phone phone = getPhone(subId);
6307 if (phone == null) {
6308 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006309 callback.onError(
6310 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006311 } catch (RemoteException e) {
6312 // ignore
6313 }
6314 return;
6315 }
6316
6317 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6318 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6319 @Override
6320 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6321 try {
6322 callback.onCallForwardingInfoAvailable(info);
6323 } catch (RemoteException e) {
6324 // ignore
6325 }
6326 }
6327
6328 @Override
6329 public void onError(int error) {
6330 try {
6331 callback.onError(error);
6332 } catch (RemoteException e) {
6333 // ignore
6334 }
6335 }
6336 });
6337 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
6341 }
6342
6343 /**
6344 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6345 * reason, the number to forward, and the timeout before the forwarding is attempted.
6346 */
6347 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006348 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6349 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006350 enforceModifyPermission();
6351 long identity = Binder.clearCallingIdentity();
6352 try {
6353 if (DBG) {
6354 log("setCallForwarding: subId " + subId
6355 + " callForwardingInfo" + callForwardingInfo);
6356 }
Hall Liu27d24262020-09-18 19:04:59 -07006357
6358 Phone phone = getPhone(subId);
6359 if (phone == null) {
6360 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006361 callback.accept(
6362 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006363 } catch (RemoteException e) {
6364 // ignore
6365 }
6366 return;
6367 }
6368
6369 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6370 FunctionalUtils.ignoreRemoteException(callback::accept));
6371
6372 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006373 } finally {
6374 Binder.restoreCallingIdentity(identity);
6375 }
6376 }
6377
6378 /**
Hall Liu27d24262020-09-18 19:04:59 -07006379 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006380 */
6381 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006382 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006383 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006384 long identity = Binder.clearCallingIdentity();
6385 try {
Hall Liu27d24262020-09-18 19:04:59 -07006386 Phone phone = getPhone(subId);
6387 if (phone == null) {
6388 try {
6389 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6390 } catch (RemoteException e) {
6391 // ignore
6392 }
6393 return;
6394 }
SongFerngWang0e767992021-03-31 22:08:45 +08006395 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6396 PersistableBundle c = configManager.getConfigForSubId(subId);
6397 boolean requireUssd = c.getBoolean(
6398 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006399
Shuo Qian4a594052020-01-23 11:59:30 -08006400 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006401 if (requireUssd) {
6402 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6403 getSubscriptionCarrierId(subId));
6404 String newUssdCommand = "";
6405 try {
6406 newUssdCommand = carrierXmlParser.getFeature(
6407 CarrierXmlParser.FEATURE_CALL_WAITING)
6408 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6409 } catch (NullPointerException e) {
6410 loge("Failed to generate USSD number" + e);
6411 }
6412 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6413 mMainThreadHandler, callback, carrierXmlParser,
6414 CarrierXmlParser.SsEntry.SSAction.QUERY);
6415 final String ussdCommand = newUssdCommand;
6416 Executors.newSingleThreadExecutor().execute(() -> {
6417 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6418 });
6419 } else {
6420 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6421 callback::accept);
6422 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6423 }
Shuo Qian4a594052020-01-23 11:59:30 -08006424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
6427 }
6428
6429 /**
Hall Liu27d24262020-09-18 19:04:59 -07006430 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006431 */
6432 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006433 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006434 enforceModifyPermission();
6435 long identity = Binder.clearCallingIdentity();
6436 try {
Hall Liu27d24262020-09-18 19:04:59 -07006437 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6438
6439 Phone phone = getPhone(subId);
6440 if (phone == null) {
6441 try {
6442 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6443 } catch (RemoteException e) {
6444 // ignore
6445 }
6446 return;
6447 }
6448
SongFerngWang0e767992021-03-31 22:08:45 +08006449 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6450 PersistableBundle c = configManager.getConfigForSubId(subId);
6451 boolean requireUssd = c.getBoolean(
6452 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006453
SongFerngWang0e767992021-03-31 22:08:45 +08006454 if (DBG) log("getCallWaitingStatus: subId " + subId);
6455 if (requireUssd) {
6456 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6457 getSubscriptionCarrierId(subId));
6458 CarrierXmlParser.SsEntry.SSAction ssAction =
6459 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6460 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6461 String newUssdCommand = "";
6462 try {
6463 newUssdCommand = carrierXmlParser.getFeature(
6464 CarrierXmlParser.FEATURE_CALL_WAITING)
6465 .makeCommand(ssAction, null);
6466 } catch (NullPointerException e) {
6467 loge("Failed to generate USSD number" + e);
6468 }
6469 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6470 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6471 final String ussdCommand = newUssdCommand;
6472 Executors.newSingleThreadExecutor().execute(() -> {
6473 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6474 });
6475 } else {
6476 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6477 FunctionalUtils.ignoreRemoteException(callback::accept));
6478
6479 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6480 }
Shuo Qian4a594052020-01-23 11:59:30 -08006481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
6484 }
6485
6486 /**
yinxub1bed742017-04-17 11:45:04 -07006487 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006488 *
yinxub1bed742017-04-17 11:45:04 -07006489 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006490 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6491 * location related information which will be sent if the caller already possess
6492 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006493 * @param request contains the radio access networks with bands/channels to scan
6494 * @param messenger callback messenger for scan results or errors
6495 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006496 * @return the id of the requested scan which can be used to stop the scan.
6497 */
6498 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006499 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6500 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006501 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6503 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006504 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006505 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6506 if (!renounceFineLocationAccess) {
6507 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6508 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6509 .setCallingPackage(callingPackage)
6510 .setCallingFeatureId(callingFeatureId)
6511 .setCallingPid(Binder.getCallingPid())
6512 .setCallingUid(Binder.getCallingUid())
6513 .setMethod("requestNetworkScan")
6514 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6515 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6516 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6517 .build());
6518 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006519 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006520 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6521 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006522 if (e != null) {
6523 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6524 throw e;
6525 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006526 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006527 return TelephonyScanManager.INVALID_SCAN_ID;
6528 }
6529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 }
Hall Liu912dfd32019-04-25 14:02:26 -07006531 int callingUid = Binder.getCallingUid();
6532 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006536 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006537 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
yinxu504e1392017-04-12 16:03:22 -07006541 }
6542
Hall Liub2ac8ef2019-02-28 15:56:23 -08006543 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006544 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006545 boolean hasCarrierPriv;
6546 final long identity = Binder.clearCallingIdentity();
6547 try {
6548 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6549 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
6552 }
Hall Liu558027f2019-05-15 19:14:05 -07006553 boolean hasNetworkScanPermission =
6554 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6555 == PERMISSION_GRANTED;
6556
6557 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6558 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6559 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006560 }
6561
6562 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6563 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006564 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6565 return new SecurityException("Specific channels must not be"
6566 + " scanned without location access.");
6567 }
6568 }
6569 }
6570
Hall Liub2ac8ef2019-02-28 15:56:23 -08006571 return null;
6572 }
6573
yinxu504e1392017-04-12 16:03:22 -07006574 /**
6575 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006576 *
6577 * @param subId id of the subscription
6578 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006579 */
6580 @Override
6581 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6583 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584
Hall Liu912dfd32019-04-25 14:02:26 -07006585 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 final long identity = Binder.clearCallingIdentity();
6587 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006588 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
yinxu504e1392017-04-12 16:03:22 -07006592 }
6593
6594 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006595 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006596 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006597 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006598 */
6599 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006600 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006601 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006602 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006603 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006607 if (DBG) log("getAllowedNetworkTypesBitmask");
6608 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6609 int networkTypesBitmask = (result != null ? result[0] : -1);
6610 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6611 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006615 }
6616
6617 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006618 * Get the allowed network types for certain reason.
6619 *
6620 * @param subId the id of the subscription.
6621 * @param reason the reason the allowed network type change is taking place
6622 * @return the allowed network types.
6623 */
6624 @Override
6625 public long getAllowedNetworkTypesForReason(int subId,
6626 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006627 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006628 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
6635 }
6636
6637 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006638 * Enable/Disable E-UTRA-NR Dual Connectivity
6639 * @param subId subscription id of the sim card
6640 * @param nrDualConnectivityState expected NR dual connectivity state
6641 * This can be passed following states
6642 * <ol>
6643 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6644 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6645 * <li>Disable NR dual connectivity and force secondary cell to be released
6646 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6647 * </ol>
6648 * @return operation result.
6649 */
6650 @Override
6651 public int setNrDualConnectivityState(int subId,
6652 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6654 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006655 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006656 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6657 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6658 }
6659
Sooraj Sasindran37444802020-08-11 10:40:43 -07006660 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6661 final long identity = Binder.clearCallingIdentity();
6662 try {
6663 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6664 nrDualConnectivityState, subId,
6665 workSource);
6666 if (DBG) log("enableNRDualConnectivity result: " + result);
6667 return result;
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
6671 }
6672
6673 /**
6674 * Is E-UTRA-NR Dual Connectivity enabled
6675 * @return true if dual connectivity is enabled else false
6676 */
6677 @Override
6678 public boolean isNrDualConnectivityEnabled(int subId) {
6679 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006680 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006681 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006682 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006683 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6684 return false;
6685 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006686 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6690 null, subId, workSource);
6691 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6692 return isEnabled;
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
6696 }
6697
6698 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006699 * Set the allowed network types of the device and
6700 * provide the reason triggering the allowed network change.
6701 *
6702 * @param subId the id of the subscription.
6703 * @param reason the reason the allowed network type change is taking place
6704 * @param allowedNetworkTypes the allowed network types.
6705 * @return true on success; false on any failure.
6706 */
6707 @Override
6708 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006709 @TelephonyManager.AllowedNetworkTypesReason int reason,
6710 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6712 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006713 // If the caller only has carrier privileges, then they should not be able to override
6714 // any network types which were set for security reasons.
6715 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6716 != PERMISSION_GRANTED
6717 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6718 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6719 throw new SecurityException(
6720 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6721 + " reason "
6722 + reason);
6723 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006724 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006725 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6726 return false;
6727 }
6728 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6729 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006730 return false;
6731 }
6732
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006733 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6734 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6735
6736
6737 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6738 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6739 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006740 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006741
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006742 final long identity = Binder.clearCallingIdentity();
6743 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006744 Boolean success = (Boolean) sendRequest(
6745 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6746 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6747
6748 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6749 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
6753 }
6754
6755 /**
Miaoa84611c2019-03-15 09:21:10 +08006756 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006757 *
Miaoa84611c2019-03-15 09:21:10 +08006758 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006759 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006760 * @hide
6761 */
6762 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006763 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006766 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 try {
Miaoa84611c2019-03-15 09:21:10 +08006768 if (phone != null) {
6769 return phone.hasMatchedTetherApnSetting();
6770 } else {
6771 return false;
6772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 } finally {
6774 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006775 }
Junda Liu475951f2014-11-07 16:45:03 -08006776 }
6777
6778 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006779 * Get the user enabled state of Mobile Data.
6780 *
6781 * TODO: remove and use isUserDataEnabled.
6782 * This can't be removed now because some vendor codes
6783 * calls through ITelephony directly while they should
6784 * use TelephonyManager.
6785 *
6786 * @return true on enabled
6787 */
6788 @Override
6789 public boolean getDataEnabled(int subId) {
6790 return isUserDataEnabled(subId);
6791 }
6792
6793 /**
6794 * Get whether mobile data is enabled per user setting.
6795 *
6796 * There are other factors deciding whether mobile data is actually enabled, but they are
6797 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006798 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6800 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006801 *
6802 * @return {@code true} if data is enabled else {@code false}
6803 */
6804 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006805 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006806 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006807 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006808 try {
6809 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6810 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006811 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006812 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6813 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006814 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006816 mApp, subId, functionName);
6817
Robert Greenwalt646120a2014-05-23 11:54:03 -07006818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
Jack Yu285100e2022-12-02 22:48:35 -08006822 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6824 Phone phone = PhoneFactory.getPhone(phoneId);
6825 if (phone != null) {
6826 boolean retVal = phone.isUserDataEnabled();
6827 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6828 return retVal;
6829 } else {
6830 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6831 return false;
6832 }
6833 } finally {
6834 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006835 }
6836 }
6837
6838 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006839 * Checks if the device is capable of mobile data by considering whether whether the
6840 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6841 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006842 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006843 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006844 */
6845 @Override
6846 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006847 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006848 try {
6849 try {
6850 mApp.enforceCallingOrSelfPermission(
6851 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006852 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006853 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006854 try {
6855 mApp.enforceCallingOrSelfPermission(
6856 android.Manifest.permission.READ_PHONE_STATE,
6857 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006858 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006859 mApp.enforceCallingOrSelfPermission(
6860 permission.READ_BASIC_PHONE_STATE, functionName);
6861 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006862 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006863 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006864 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
Jack Yu285100e2022-12-02 22:48:35 -08006869 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870 Phone phone = PhoneFactory.getPhone(phoneId);
6871 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006872 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006873 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 return retVal;
6875 } else {
6876 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6877 return false;
6878 }
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006881 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006882 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006883
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006884 /**
6885 * Check if data is enabled for a specific reason
6886 * @param subId Subscription index
6887 * @param reason the reason the data enable change is taking place
6888 * @return {@code true} if the overall data is enabled; {@code false} if not.
6889 */
6890 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006891 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006892 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006893 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006894 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006895 try {
6896 mApp.enforceCallingOrSelfPermission(
6897 android.Manifest.permission.ACCESS_NETWORK_STATE,
6898 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006899 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006900 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6901 functionName);
6902 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006903 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006904 try {
6905 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006906 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006907 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006909 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006910 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006911 }
6912
6913
6914 final long identity = Binder.clearCallingIdentity();
6915 try {
Jack Yu285100e2022-12-02 22:48:35 -08006916 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006917 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006918 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006919 + " reason=" + reason);
6920 }
6921 Phone phone = PhoneFactory.getPhone(phoneId);
6922 if (phone != null) {
6923 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006924 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006925 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006926 return retVal;
6927 } else {
6928 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006929 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006930 + subId + " retVal=false");
6931 }
6932 return false;
6933 }
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936 }
6937 }
6938
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006939 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006940 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006941 // No permission needed; this only lets the caller inspect their own status.
6942 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006943 }
Junda Liu29340342014-07-10 15:23:27 -07006944
6945 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006946 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006947 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006948 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6949 }
6950
6951 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6952 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006953 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006954 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006955 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6956 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006957 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6958 if (cpt == null) {
6959 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006960 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6961 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006962 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006963 }
6964
6965 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006966 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006967 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006968 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006969 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006970 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006971 Phone phone = getPhone(subId);
6972 if (phone == null) {
6973 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6974 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6975 }
6976 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6977 if (cpt == null) {
6978 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006979 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6980 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006981 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006982 }
6983
6984 @Override
6985 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006986 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006987 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6988 }
6989
6990 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006991 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006992 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006993 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006994 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006995 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6996 Phone phone = PhoneFactory.getPhone(phoneId);
6997 if (phone == null) {
6998 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006999 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007000 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7001 if (cpt == null) {
7002 continue;
7003 }
7004 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007005 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7006 break;
7007 }
7008 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007009 return result;
Junda Liu29340342014-07-10 15:23:27 -07007010 }
Derek Tan89e89d42014-07-08 17:00:10 -07007011
7012 @Override
Junda Liue64de782015-04-16 17:19:16 -07007013 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007014 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007015 Phone phone = PhoneFactory.getPhone(phoneId);
7016 if (phone == null) {
7017 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007018 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007019 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7020 if (cpt == null) {
7021 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007022 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007023 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007024 }
7025
Amith Yamasani6e118872016-02-19 12:53:51 -08007026 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007027 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007028 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007029 Phone phone = PhoneFactory.getPhone(phoneId);
7030 if (phone == null) {
7031 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007032 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007033 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7034 if (cpt == null) {
7035 return Collections.emptyList();
7036 }
7037 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007038 }
7039
chen xuf7e9fe82019-05-09 19:31:02 -07007040 @Override
7041 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007042 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007043 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007044 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007045 try {
7046 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7047 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7048 }
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007051 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007052 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007053 }
7054
Rambo Wang6812ffb2022-03-15 16:54:17 -07007055 @Override
7056 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7057 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7058
7059 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7060 if (phone == null) {
7061 return null;
7062 }
7063 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7064 if (cpt == null) {
7065 return null;
7066 }
7067 return cpt.getCarrierServicePackageName();
7068 }
7069
Wink Savilleb564aae2014-10-23 10:18:09 -07007070 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007071 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007072 UiccPort port = phone == null ? null : phone.getUiccPort();
7073 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007074 return null;
7075 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007076 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007077 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007078 return null;
7079 }
7080 return iccId;
7081 }
7082
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007083 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007084 public void setCallComposerStatus(int subId, int status) {
7085 enforceModifyPermission();
7086
7087 final long identity = Binder.clearCallingIdentity();
7088 try {
7089 Phone phone = getPhone(subId);
7090 if (phone != null) {
7091 Phone defaultPhone = phone.getImsPhone();
7092 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7093 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7094 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007095 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7096 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007097 }
7098 }
Shuo Qian284ae752020-12-22 19:10:14 -08007099 } catch (ImsException e) {
7100 throw new ServiceSpecificException(e.getCode());
7101 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007102 Binder.restoreCallingIdentity(identity);
7103 }
7104 }
7105
7106 @Override
7107 public int getCallComposerStatus(int subId) {
7108 enforceReadPrivilegedPermission("getCallComposerStatus");
7109
7110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 Phone phone = getPhone(subId);
7113 if (phone != null) {
7114 Phone defaultPhone = phone.getImsPhone();
7115 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7116 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7117 return imsPhone.getCallComposerStatus();
7118 }
7119 }
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
7123 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7124 }
7125
7126 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007127 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7128 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007129 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007130 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 final String iccId = getIccId(subId);
7135 final Phone phone = getPhone(subId);
7136 if (phone == null) {
7137 return false;
7138 }
7139 final String subscriberId = phone.getSubscriberId();
7140
7141 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007142 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 + subscriberId + " to " + number);
7144 }
7145
7146 if (TextUtils.isEmpty(iccId)) {
7147 return false;
7148 }
7149
7150 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7151
7152 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7153 if (alphaTag == null) {
7154 editor.remove(alphaTagPrefKey);
7155 } else {
7156 editor.putString(alphaTagPrefKey, alphaTag);
7157 }
7158
7159 // Record both the line number and IMSI for this ICCID, since we need to
7160 // track all merged IMSIs based on line number
7161 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7162 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7163 if (number == null) {
7164 editor.remove(numberPrefKey);
7165 editor.remove(subscriberPrefKey);
7166 } else {
7167 editor.putString(numberPrefKey, number);
7168 editor.putString(subscriberPrefKey, subscriberId);
7169 }
7170
7171 editor.commit();
7172 return true;
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007175 }
Derek Tan7226c842014-07-02 17:42:23 -07007176 }
7177
7178 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007179 public String getLine1NumberForDisplay(int subId, String callingPackage,
7180 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007181 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007183 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007184 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007185 return null;
7186 }
Derek Tan97ebb422014-09-05 16:55:38 -07007187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 String iccId = getIccId(subId);
7191 if (iccId != null) {
7192 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7193 if (DBG_MERGE) {
7194 log("getLine1NumberForDisplay returning "
7195 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7196 }
7197 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7200 return null;
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007203 }
Derek Tan7226c842014-07-02 17:42:23 -07007204 }
7205
7206 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007207 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7208 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007210 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007211 return null;
7212 }
Derek Tan97ebb422014-09-05 16:55:38 -07007213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 String iccId = getIccId(subId);
7217 if (iccId != null) {
7218 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7219 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7220 }
7221 return null;
7222 } finally {
7223 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007224 }
Derek Tan7226c842014-07-02 17:42:23 -07007225 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007226
7227 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007228 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7229 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007230 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7231 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007233 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007234 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007235 return null;
7236 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007237
Jordan Liub49b04b2019-05-06 14:45:15 -07007238 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7239 // the process, where TelephonyManager was instantiated.
7240 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007241 final long identity = Binder.clearCallingIdentity();
7242 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007243 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 final TelephonyManager tele = TelephonyManager.from(context);
7245 final SubscriptionManager sub = SubscriptionManager.from(context);
7246
7247 // Figure out what subscribers are currently active
7248 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249
Jordan Liub49b04b2019-05-06 14:45:15 -07007250 // Only consider subs which match the current subId
7251 // This logic can be simplified. See b/131189269 for progress.
7252 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007253 activeSubscriberIds.add(tele.getSubscriberId(subId));
7254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255
7256 // First pass, find a number override for an active subscriber
7257 String mergeNumber = null;
7258 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7259 for (String key : prefs.keySet()) {
7260 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7261 final String subscriberId = (String) prefs.get(key);
7262 if (activeSubscriberIds.contains(subscriberId)) {
7263 final String iccId = key.substring(
7264 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7265 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7266 mergeNumber = (String) prefs.get(numberKey);
7267 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007268 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269 + " for active subscriber " + subscriberId);
7270 }
7271 if (!TextUtils.isEmpty(mergeNumber)) {
7272 break;
7273 }
7274 }
7275 }
7276 }
7277
7278 // Shortcut when no active merged subscribers
7279 if (TextUtils.isEmpty(mergeNumber)) {
7280 return null;
7281 }
7282
7283 // Second pass, find all subscribers under that line override
7284 final ArraySet<String> result = new ArraySet<>();
7285 for (String key : prefs.keySet()) {
7286 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7287 final String number = (String) prefs.get(key);
7288 if (mergeNumber.equals(number)) {
7289 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7290 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7291 final String subscriberId = (String) prefs.get(subscriberKey);
7292 if (!TextUtils.isEmpty(subscriberId)) {
7293 result.add(subscriberId);
7294 }
7295 }
7296 }
7297 }
7298
7299 final String[] resultArray = result.toArray(new String[result.size()]);
7300 Arrays.sort(resultArray);
7301 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007302 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7304 }
7305 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007306 } finally {
7307 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007308 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007309 }
7310
7311 @Override
zoey chen38003472019-12-13 17:16:31 +08007312 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7313 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007314
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 final TelephonyManager telephonyManager = mApp.getSystemService(
7318 TelephonyManager.class);
7319 String subscriberId = telephonyManager.getSubscriberId(subId);
7320 if (subscriberId == null) {
7321 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007322 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007323 + subId);
7324 }
7325 return null;
7326 }
7327
Jack Yu285100e2022-12-02 22:48:35 -08007328 ParcelUuid groupUuid;
7329 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7330 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7331 .getSubscriptionInfo(subId);
7332 groupUuid = info.getGroupUuid();
7333 } else {
7334 final SubscriptionInfo info = mSubscriptionController
7335 .getSubscriptionInfo(subId);
7336 groupUuid = info.getGroupUuid();
7337 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007338 // If it doesn't belong to any group, return just subscriberId of itself.
7339 if (groupUuid == null) {
7340 return new String[]{subscriberId};
7341 }
7342
7343 // Get all subscriberIds from the group.
7344 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007345 List<SubscriptionInfo> groupInfos;
7346 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7347 groupInfos = SubscriptionManagerService.getInstance()
7348 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7349 mApp.getAttributionTag());
7350 } else {
7351 groupInfos = mSubscriptionController
7352 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7353 mApp.getAttributionTag());
7354 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007355 for (SubscriptionInfo subInfo : groupInfos) {
7356 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7357 if (subscriberId != null) {
7358 mergedSubscriberIds.add(subscriberId);
7359 }
7360 }
7361
7362 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365
7366 }
7367 }
7368
7369 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007370 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007371 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007372 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373
7374 final long identity = Binder.clearCallingIdentity();
7375 try {
7376 final Phone phone = getPhone(subId);
7377 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007381 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007382
7383 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007384 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007385 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7386 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007387 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7388 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389
7390 final long identity = Binder.clearCallingIdentity();
7391 try {
7392 final Phone phone = getPhone(subId);
7393 if (phone == null) {
7394 return false;
7395 }
7396 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7397 cdmaNonRoamingList);
7398 } finally {
7399 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007400 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007401 }
7402
7403 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007404 @Deprecated
7405 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7406 enforceModifyPermission();
7407
7408 int returnValue = 0;
7409 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007410 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007411 if(result.exception == null) {
7412 if (result.result != null) {
7413 byte[] responseData = (byte[])(result.result);
7414 if(responseData.length > oemResp.length) {
7415 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7416 responseData.length + "bytes. Buffer Size is " +
7417 oemResp.length + "bytes.");
7418 }
7419 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7420 returnValue = responseData.length;
7421 }
7422 } else {
7423 CommandException ex = (CommandException) result.exception;
7424 returnValue = ex.getCommandError().ordinal();
7425 if(returnValue > 0) returnValue *= -1;
7426 }
7427 } catch (RuntimeException e) {
7428 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7429 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7430 if(returnValue > 0) returnValue *= -1;
7431 }
7432
7433 return returnValue;
7434 }
7435
7436 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007437 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007438 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007439 try {
7440 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007441 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007442 mApp, phone.getSubId(), "getRadioAccessFamily");
7443 } catch (SecurityException e) {
7444 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7445 throw e;
7446 }
chen xub97461a2018-10-26 14:17:57 -07007447 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007448 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007449 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 final long identity = Binder.clearCallingIdentity();
7452 try {
chen xub97461a2018-10-26 14:17:57 -07007453 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007454 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007455 mApp, phone.getSubId(), "getRadioAccessFamily");
7456 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
chen xub97461a2018-10-26 14:17:57 -07007460 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007461 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007462
7463 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007464 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007465 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007466 try {
7467 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7468 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007469 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007470 }
7471 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007472 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007473 }
7474 RoleManager rm = mApp.getSystemService(RoleManager.class);
7475 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7476 if (!dialerRoleHolders.contains(callingPackage)) {
7477 throw new SecurityException("App must be the dialer role holder to"
7478 + " upload a call composer pic");
7479 }
7480
7481 Executors.newSingleThreadExecutor().execute(() -> {
7482 ByteArrayOutputStream output = new ByteArrayOutputStream(
7483 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7484 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7485 boolean readUntilEnd = false;
7486 int totalBytesRead = 0;
7487 byte[] buffer = new byte[16 * 1024];
7488 while (true) {
7489 int numRead;
7490 try {
7491 numRead = input.read(buffer);
7492 } catch (IOException e) {
7493 try {
7494 fd.checkError();
7495 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7496 null);
7497 } catch (IOException e1) {
7498 // This means that the other side closed explicitly with an error. If this
7499 // happens, log and ignore.
7500 loge("Remote end of call composer picture pipe closed: " + e1);
7501 }
7502 break;
7503 }
7504 if (numRead == -1) {
7505 readUntilEnd = true;
7506 break;
7507 }
7508 totalBytesRead += numRead;
7509 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7510 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7511 try {
7512 input.close();
7513 } catch (IOException e) {
7514 // ignore
7515 }
7516 break;
7517 }
7518 output.write(buffer, 0, numRead);
7519 }
7520 // Generally, the remote end will close the file descriptors. The only case where we
7521 // close is above, where the picture size is too big.
7522
7523 try {
7524 fd.checkError();
7525 } catch (IOException e) {
7526 loge("Remote end for call composer closed with an error: " + e);
7527 return;
7528 }
7529
Hall Liuaa4211e2021-01-20 15:43:39 -08007530 if (!readUntilEnd) {
7531 loge("Did not finish reading entire image; aborting");
7532 return;
7533 }
Hall Liu82694d52020-12-11 18:22:04 -08007534
Hall Liuaa4211e2021-01-20 15:43:39 -08007535 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7536 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7537 new CallComposerPictureTransfer.Factory() {},
7538 imageData,
7539 (result) -> {
7540 if (result.first != null) {
7541 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7542 Bundle outputResult = new Bundle();
7543 outputResult.putParcelable(
7544 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7545 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7546 outputResult);
7547 } else {
7548 callback.send(result.second, null);
7549 }
7550 }
7551 );
Hall Liu82694d52020-12-11 18:22:04 -08007552 });
7553 }
7554
7555 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007556 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559
7560 final long identity = Binder.clearCallingIdentity();
7561 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 ImsManager.getInstance(defaultPhone.getContext(),
7563 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007567 }
7568
7569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007570 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007571 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7573 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007574 return false;
7575 }
Svet Ganovb320e182015-04-16 12:30:10 -07007576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 // Check the user preference and the system-level IMS setting. Even if the user has
7580 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7581 // In the long run, we may instead need to check if there exists a connection service
7582 // which can support video calling.
7583 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007584 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 return imsManager.isVtEnabledByPlatform()
7586 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7587 && imsManager.isVtEnabledByUser();
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007591 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007592
Andrew Leea1239f22015-03-02 17:44:07 -08007593 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007594 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7595 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007597 mApp, subId, callingPackage, callingFeatureId,
7598 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 return false;
7600 }
7601
7602 final long identity = Binder.clearCallingIdentity();
7603 try {
7604 CarrierConfigManager configManager =
7605 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007606 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
7610 }
Andrew Leea1239f22015-03-02 17:44:07 -08007611 }
7612
7613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007614 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007616 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 return false;
7618 }
7619
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 CarrierConfigManager configManager =
7623 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
Andrew Leea1239f22015-03-02 17:44:07 -08007629 }
7630
Andrew Lee9431b832015-03-09 18:46:45 -07007631 @Override
7632 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007633 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007634 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007635 }
7636
7637 @Override
7638 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 final long identity = Binder.clearCallingIdentity();
7640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007641 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
Andrew Lee9431b832015-03-09 18:46:45 -07007645 }
7646
Hall Liuf6668912018-10-31 17:05:23 -07007647 /**
7648 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7649 * support for the feature and device firmware support.
7650 *
7651 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7652 */
7653 @Override
7654 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007656 final Phone phone = getPhone(subscriptionId);
7657 if (phone == null) {
7658 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7659 return false;
7660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007662 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7664 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007665 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 return isCarrierSupported && isDeviceSupported;
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
Hall Liu98187582018-01-22 19:15:32 -08007670 }
7671
Hall Liuf6668912018-10-31 17:05:23 -07007672 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007673 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7674 * RTT setting, will return true if the device and carrier both support RTT.
7675 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007676 */
7677 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 final long identity = Binder.clearCallingIdentity();
7679 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007680 boolean isRttSupported = isRttSupported(subscriptionId);
7681 boolean isUserRttSettingOn = Settings.Secure.getInt(
7682 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7683 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7684 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7685 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007689 }
7690
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007691 @Deprecated
7692 @Override
7693 public String getDeviceId(String callingPackage) {
7694 return getDeviceIdWithFeature(callingPackage, null);
7695 }
7696
Sanket Padawe7310cc72015-01-14 09:53:20 -08007697 /**
7698 * Returns the unique device ID of phone, for example, the IMEI for
7699 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7700 *
7701 * <p>Requires Permission:
7702 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7703 */
7704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007705 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007706 try {
7707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7708 } catch (SecurityException se) {
7709 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7710 throw new SecurityException("Package " + callingPackage + " does not belong to "
7711 + Binder.getCallingUid());
7712 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007713 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007714 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007715 return null;
7716 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007717 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007718 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007719 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007720 return null;
7721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 return phone.getDeviceId();
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007729 }
7730
Ping Sunc67b7c22016-03-02 19:16:45 +08007731 /**
7732 * {@hide}
7733 * Returns the IMS Registration Status on a particular subid
7734 *
7735 * @param subId
7736 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007737 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007738 Phone phone = getPhone(subId);
7739 if (phone != null) {
7740 return phone.isImsRegistered();
7741 } else {
7742 return false;
7743 }
7744 }
7745
Santos Cordon7a1885b2015-02-03 11:15:19 -08007746 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007747 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007748 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007750 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007751 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7752 }
7753 final long identity = Binder.clearCallingIdentity();
7754 try {
7755 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
7759 }
7760
7761 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007762 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007763 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007764 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007765 mApp,
7766 subscriptionId,
7767 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 Phone phone = getPhone(subscriptionId);
7771 if (phone == null) {
7772 return null;
7773 }
7774 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
7778 }
7779
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007780 /**
7781 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007782 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007783 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 final long identity = Binder.clearCallingIdentity();
7785 try {
7786 Phone phone = getPhone(subId);
7787 if (phone != null) {
7788 return phone.isWifiCallingEnabled();
7789 } else {
7790 return false;
7791 }
7792 } finally {
7793 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007794 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007795 }
7796
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007797 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007798 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007799 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007800 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 final long identity = Binder.clearCallingIdentity();
7802 try {
7803 Phone phone = getPhone(subId);
7804 if (phone != null) {
7805 return phone.isVideoEnabled();
7806 } else {
7807 return false;
7808 }
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007811 }
7812 }
7813
7814 /**
7815 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7816 * defined in {@link ImsRegistrationImplBase}.
7817 */
7818 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 final long identity = Binder.clearCallingIdentity();
7820 try {
7821 Phone phone = getPhone(subId);
7822 if (phone != null) {
7823 return phone.getImsRegistrationTech();
7824 } else {
7825 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7826 }
7827 } finally {
7828 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007829 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007830 }
7831
Stuart Scott8eef64f2015-04-08 15:13:54 -07007832 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007833 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007834 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007835 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7836 return;
7837 }
Kai Shif70f46f2021-03-03 13:59:46 -08007838 Phone defaultPhone = getDefaultPhone();
7839 if (defaultPhone != null) {
7840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7841 mApp, getDefaultPhone().getSubId(), "factoryReset");
7842 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007843 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007844
Svet Ganovcc087f82015-05-12 20:35:54 -07007845 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007846 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7847 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007848 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007849 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007850 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007851 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007852 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007853 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007854 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007855 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007856 // There has been issues when Sms raw table somehow stores orphan
7857 // fragments. They lead to garbled message when new fragments come
7858 // in and combined with those stale ones. In case this happens again,
7859 // user can reset all network settings which will clean up this table.
7860 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007861 // Clean up IMS settings as well here.
7862 int slotId = getSlotIndex(subId);
7863 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7864 ImsManager.getInstance(mApp, slotId).factoryReset();
7865 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007866
Kai Shif70f46f2021-03-03 13:59:46 -08007867 if (defaultPhone == null) {
7868 return;
7869 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007870 // Erase modem config if erase modem on network setting is enabled.
7871 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7872 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7873 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007874 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007875 }
Kai Shif70f46f2021-03-03 13:59:46 -08007876
7877 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007878 } finally {
7879 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007880 }
7881 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007882
SongFerngWangfd89b102021-05-27 22:44:54 +08007883 @VisibleForTesting
7884 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7885 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7886 return;
7887 }
7888 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7889 RILConstants.PREFERRED_NETWORK_MODE);
7890 SubscriptionManager.setSubscriptionProperty(subId,
7891 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7892 "user=" + defaultNetworkType);
7893 phone.loadAllowedNetworksFromSubscriptionDatabase();
7894 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7895 defaultNetworkType, null);
7896 }
7897
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007898 private void cleanUpSmsRawTable(Context context) {
7899 ContentResolver resolver = context.getContentResolver();
7900 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7901 resolver.delete(uri, null, null);
7902 }
7903
Narayan Kamath1c496c22015-04-16 14:40:19 +01007904 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007905 public String getSimLocaleForSubscriber(int subId) {
7906 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7907 final Phone phone = getPhone(subId);
7908 if (phone == null) {
7909 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007910 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 final long identity = Binder.clearCallingIdentity();
7913 try {
Jack Yu285100e2022-12-02 22:48:35 -08007914 SubscriptionInfo info;
7915 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7916 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7917 phone.getContext().getOpPackageName(),
7918 phone.getContext().getAttributionTag());
7919 if (info == null) {
7920 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7921 return null;
7922 }
7923 } else {
7924 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7925 phone.getContext().getOpPackageName(),
7926 phone.getContext().getAttributionTag());
7927 if (info == null) {
7928 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7929 return null;
7930 }
chen xu6291c472019-02-04 12:55:53 -08007931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 // Try and fetch the locale from the carrier properties or from the SIM language
7933 // preferences (EF-PL and EF-LI)...
7934 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007936 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7937 if (localeFromDefaultSim != null) {
7938 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7939 if (DBG) log("Using locale from subId: " + subId + " locale: "
7940 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007941 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007942 } else {
7943 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 }
7945 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947 // The SIM language preferences only store a language (e.g. fr = French), not an
7948 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7949 // the SIM and carrier preferences does not include a country we add the country
7950 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007951 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007953 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007954 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 }
7956
7957 if (DBG) log("No locale found - returning null");
7958 return null;
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
7961 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007962 }
7963
tom hsu0b59d292022-09-29 23:49:21 +08007964 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007965 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007966 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007967 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007968 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007969 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7970 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007971 Locale.forLanguageTag(localeTag).getCountry())) {
7972 return localeTag;
7973 }
7974 }
7975 return inputLocale.toLanguageTag();
7976 }
7977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 /**
7979 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7980 */
7981 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007982 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7983 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7984 mApp.getOpPackageName(), mApp.getAttributionTag());
7985 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007986 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007987 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007988 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007989
Gary Jian3aa9a762022-01-24 16:41:19 +08007990 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7991 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007992
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007993 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007994 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7995 * representing the state of the modem.
7996 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007997 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7998 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007999 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008000 */
8001 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008002 public void requestModemActivityInfo(ResultReceiver result) {
8003 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008004 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005
8006 final long identity = Binder.clearCallingIdentity();
8007 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008008 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 } finally {
8010 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008011 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008012 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008013
Siddharth Rayb8114062018-06-17 15:02:38 -07008014 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
8015 // less than total activity duration.
8016 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8017 if (info == null) {
8018 return false;
8019 }
8020 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008021 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
8022 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8023
Siddharth Rayb8114062018-06-17 15:02:38 -07008024 return (info.isValid()
8025 && (info.getSleepTimeMillis() <= activityDurationMs)
8026 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07008027 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07008028 && (totalTxTimeMs <= activityDurationMs));
8029 }
8030
Gary Jian3aa9a762022-01-24 16:41:19 +08008031 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8032 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8033 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8034 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8035
8036 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8037 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8038 }
8039
8040 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8041 mLastModemActivityInfo.setReceiveTimeMillis(
8042 rat,
8043 freq,
8044 info.getReceiveTimeMillis(rat, freq)
8045 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8046 }
8047
8048 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8049 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8050 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8051 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8052
8053 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8054 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8055 }
8056 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8057 mLastModemActivityInfo.setReceiveTimeMillis(
8058 rat,
8059 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8060 }
8061
8062 /**
8063 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8064 * @param info recent ModemActivityInfo
8065 */
8066 private void mergeModemActivityInfo(ModemActivityInfo info) {
8067 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008068 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008069 boolean matched;
8070 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8071 matched = false;
8072 int rat = info.getSpecificInfoRat(i);
8073 int freq = info.getSpecificInfoFrequencyRange(i);
8074 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8075 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8076 //if it already exists
8077 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8078 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8079 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8080 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8081 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8082 updateLastModemActivityInfo(info, rat, freq);
8083 matched = true;
8084 }
8085 } else {
8086 updateLastModemActivityInfo(info, rat);
8087 matched = true;
8088 }
8089 }
8090 }
8091
8092 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008093 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008094 new ActivityStatsTechSpecificInfo(
8095 rat,
8096 freq,
8097 info.getTransmitTimeMillis(rat, freq),
8098 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008099 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008100 }
8101 }
8102 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8103 mLastModemActivitySpecificInfo =
8104 new ActivityStatsTechSpecificInfo[merged.size()];
8105 merged.toArray(mLastModemActivitySpecificInfo);
8106
8107 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8108 mLastModemActivityInfo.setSleepTimeMillis(
8109 info.getSleepTimeMillis()
8110 + mLastModemActivityInfo.getSleepTimeMillis());
8111 mLastModemActivityInfo.setIdleTimeMillis(
8112 info.getIdleTimeMillis()
8113 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008114
8115 mLastModemActivityInfo =
8116 new ModemActivityInfo(
8117 mLastModemActivityInfo.getTimestampMillis(),
8118 mLastModemActivityInfo.getSleepTimeMillis(),
8119 mLastModemActivityInfo.getIdleTimeMillis(),
8120 mLastModemActivitySpecificInfo);
8121 }
8122
8123 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8124 ActivityStatsTechSpecificInfo[] info) {
8125 int infoSize = info.length;
8126 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8127 for (int i = 0; i < infoSize; i++) {
8128 ret[i] = new ActivityStatsTechSpecificInfo(
8129 info[i].getRat(), info[i].getFrequencyRange(),
8130 info[i].getTransmitTimeMillis(),
8131 (int) info[i].getReceiveTimeMillis());
8132 }
8133 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008134 }
8135
Jack Yu85bd38a2015-11-09 11:34:32 -08008136 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008137 * Returns the service state information on specified subscription.
8138 */
8139 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008140 public ServiceState getServiceStateForSubscriber(int subId,
8141 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8142 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008144 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008145 return null;
8146 }
8147
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008148 boolean hasFinePermission = false;
8149 boolean hasCoarsePermission = false;
8150 if (!renounceFineLocationAccess) {
8151 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8152 LocationAccessPolicy.checkLocationPermission(mApp,
8153 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8154 .setCallingPackage(callingPackage)
8155 .setCallingFeatureId(callingFeatureId)
8156 .setCallingPid(Binder.getCallingPid())
8157 .setCallingUid(Binder.getCallingUid())
8158 .setMethod("getServiceStateForSubscriber")
8159 .setLogAsInfo(true)
8160 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8161 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8162 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8163 .build());
8164 hasFinePermission =
8165 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8166 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008167
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008168 if (!renounceCoarseLocationAccess) {
8169 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8170 LocationAccessPolicy.checkLocationPermission(mApp,
8171 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8172 .setCallingPackage(callingPackage)
8173 .setCallingFeatureId(callingFeatureId)
8174 .setCallingPid(Binder.getCallingPid())
8175 .setCallingUid(Binder.getCallingUid())
8176 .setMethod("getServiceStateForSubscriber")
8177 .setLogAsInfo(true)
8178 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8179 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8180 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8181 .build());
8182 hasCoarsePermission =
8183 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8184 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008185
Jack Yu479f40e2020-10-27 21:29:25 -07008186 final Phone phone = getPhone(subId);
8187 if (phone == null) {
8188 return null;
8189 }
8190
Jordan Liu0f2bc442020-11-18 16:47:37 -08008191 final long identity = Binder.clearCallingIdentity();
8192
Jack Yu479f40e2020-10-27 21:29:25 -07008193 boolean isCallingPackageDataService = phone.getDataServicePackages()
8194 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008196 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008197 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8198 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8199 .getSubscriptionInfoInternal(subId);
8200 if (subInfo == null || !subInfo.isActive()) {
8201 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8202 + "subId=" + subId);
8203 return null;
8204 }
8205 } else {
8206 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8207 callingFeatureId)) {
8208 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8209 + "subId=" + subId);
8210 return null;
8211 }
Jordan Liuc437b192020-08-17 10:59:12 -07008212 }
8213
Hall Liuf19c44f2018-11-27 14:38:17 -08008214 ServiceState ss = phone.getServiceState();
8215
8216 // Scrub out the location info in ServiceState depending on what level of access
8217 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008218 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008219 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8220 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008224 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008225
8226 /**
8227 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8228 *
8229 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8230 * voicemail ringtone.
8231 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8232 * PhoneAccount.
8233 */
8234 @Override
8235 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 final long identity = Binder.clearCallingIdentity();
8237 try {
8238 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8239 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008240 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8244 } finally {
8245 Binder.restoreCallingIdentity(identity);
8246 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008247 }
8248
8249 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008250 * Sets the per-account voicemail ringtone.
8251 *
8252 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8253 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8254 *
8255 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8256 * voicemail ringtone.
8257 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8258 * PhoneAccount.
8259 */
8260 @Override
8261 public void setVoicemailRingtoneUri(String callingPackage,
8262 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008263 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008264 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008265 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8266 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8268 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8269 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271
8272 final long identity = Binder.clearCallingIdentity();
8273 try {
8274 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8275 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008276 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 }
8278 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008281 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008282 }
8283
8284 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008285 * Returns whether vibration is set for voicemail notification in Phone settings.
8286 *
8287 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8288 * voicemail vibration setting.
8289 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8290 */
8291 @Override
8292 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8296 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008297 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008304 }
8305
Youhan Wange64578a2016-05-02 15:32:42 -07008306 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008307 * Sets the per-account voicemail vibration.
8308 *
8309 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8310 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8311 *
8312 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8313 * voicemail vibration setting.
8314 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8315 * specific PhoneAccount.
8316 */
8317 @Override
8318 public void setVoicemailVibrationEnabled(String callingPackage,
8319 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008320 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008322 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8323 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8325 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8326 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008327 }
8328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8332 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008333 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 }
8335 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008338 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008339 }
8340
8341 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008342 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8343 *
8344 * @throws SecurityException if the caller does not have the required permission
8345 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008346 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008347 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008348 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008349 }
8350
8351 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008352 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8353 * permission.
8354 *
8355 * @throws SecurityException if the caller does not have the required permission
8356 */
8357 private void enforceSendSmsPermission() {
8358 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8359 }
8360
8361 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008362 * Make sure either called from same process as self (phone) or IPC caller has interact across
8363 * users permission.
8364 *
8365 * @throws SecurityException if the caller does not have the required permission
8366 */
8367 private void enforceInteractAcrossUsersPermission(String message) {
8368 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8369 }
8370
8371 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008372 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008373 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008374 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008375 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008376 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 final long identity = Binder.clearCallingIdentity();
8378 try {
8379 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008380 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 if (componentName == null) {
8382 throw new SecurityException(
8383 "Caller not current active visual voicemail package[null]");
8384 }
8385 String vvmPackage = componentName.getPackageName();
8386 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008387 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 }
8389 } finally {
8390 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008391 }
8392 }
8393
8394 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008395 * Return the application ID for the app type.
8396 *
8397 * @param subId the subscription ID that this request applies to.
8398 * @param appType the uicc app type.
8399 * @return Application ID for specificied app type, or null if no uicc.
8400 */
8401 @Override
8402 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008403 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008404 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405
8406 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008407 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408 if (phone == null) {
8409 return null;
8410 }
8411 String aid = null;
8412 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008413 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414 .getApplicationByType(appType).getAid();
8415 } catch (Exception e) {
8416 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8417 }
8418 return aid;
8419 } finally {
8420 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008421 }
Youhan Wange64578a2016-05-02 15:32:42 -07008422 }
8423
Youhan Wang4001d252016-05-11 10:29:41 -07008424 /**
8425 * Return the Electronic Serial Number.
8426 *
8427 * @param subId the subscription ID that this request applies to.
8428 * @return ESN or null if error.
8429 */
8430 @Override
8431 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008432 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008433 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434
8435 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008436 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 if (phone == null) {
8438 return null;
8439 }
8440 String esn = null;
8441 try {
8442 esn = phone.getEsn();
8443 } catch (Exception e) {
8444 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8445 }
8446 return esn;
8447 } finally {
8448 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008449 }
Youhan Wang4001d252016-05-11 10:29:41 -07008450 }
8451
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008452 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008453 * Return the Preferred Roaming List Version.
8454 *
8455 * @param subId the subscription ID that this request applies to.
8456 * @return PRLVersion or null if error.
8457 */
8458 @Override
8459 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008460 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008461 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462
8463 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008464 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465 if (phone == null) {
8466 return null;
8467 }
8468 String cdmaPrlVersion = null;
8469 try {
8470 cdmaPrlVersion = phone.getCdmaPrlVersion();
8471 } catch (Exception e) {
8472 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8473 }
8474 return cdmaPrlVersion;
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008477 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008478 }
8479
8480 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008481 * Get snapshot of Telephony histograms
8482 * @return List of Telephony histograms
8483 * @hide
8484 */
8485 @Override
8486 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8488 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 return RIL.getTelephonyRILTimingHistograms();
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008496 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008497
8498 /**
8499 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008500 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8501 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008502 * Require system privileges. In the future we may add this to carrier APIs.
8503 *
Michele Berionne482f8202018-11-27 18:57:59 -08008504 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008505 */
8506 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008507 @TelephonyManager.SetCarrierRestrictionResult
8508 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008509 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008511
Michele Berionne482f8202018-11-27 18:57:59 -08008512 if (carrierRestrictionRules == null) {
8513 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008514 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 final long identity = Binder.clearCallingIdentity();
8517 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008518 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008519 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008523 }
8524
8525 /**
8526 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008527 * Get the allowed carrier list and the excluded carrier list, including the priority between
8528 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008529 * Require system privileges. In the future we may add this to carrier APIs.
8530 *
Michele Berionne482f8202018-11-27 18:57:59 -08008531 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008532 */
8533 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008534 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008535 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008536 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008540 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8541 if (response instanceof CarrierRestrictionRules) {
8542 return (CarrierRestrictionRules) response;
8543 }
8544 // Response is an Exception of some kind,
8545 // which is signalled to the user as a NULL retval
8546 return null;
8547 } catch (Exception e) {
8548 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8549 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550 } finally {
8551 Binder.restoreCallingIdentity(identity);
8552 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008553 }
8554
fionaxu59545b42016-05-25 15:53:37 -07008555 /**
fionaxu59545b42016-05-25 15:53:37 -07008556 * Action set from carrier signalling broadcast receivers to enable/disable radio
8557 * @param subId the subscription ID that this action applies to.
8558 * @param enabled control enable or disable radio.
8559 * {@hide}
8560 */
8561 @Override
8562 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8563 enforceModifyPermission();
8564 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008565
8566 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008567 if (phone == null) {
8568 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8569 return;
8570 }
8571 try {
8572 phone.carrierActionSetRadioEnabled(enabled);
8573 } catch (Exception e) {
8574 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575 } finally {
8576 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008577 }
8578 }
8579
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008580 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008581 * Enable or disable Voice over NR (VoNR)
8582 * @param subId the subscription ID that this action applies to.
8583 * @param enabled enable or disable VoNR.
8584 * @return operation result.
8585 */
8586 @Override
8587 public int setVoNrEnabled(int subId, boolean enabled) {
8588 enforceModifyPermission();
8589 final Phone phone = getPhone(subId);
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 if (phone == null) {
8593 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8594 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8595 }
8596
8597 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8598 try {
8599 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8600 workSource);
8601 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008602
8603 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8604 if (DBG) {
8605 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8606 }
8607 SubscriptionManager.setSubscriptionProperty(
8608 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8609 (enabled ? "1" : "0"));
8610 }
8611
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008612 return result;
8613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
8616 }
8617
8618 /**
8619 * Is voice over NR enabled
8620 * @return true if VoNR is enabled else false
8621 */
8622 @Override
8623 public boolean isVoNrEnabled(int subId) {
8624 enforceReadPrivilegedPermission("isVoNrEnabled");
8625 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8629 null, subId, workSource);
8630 if (DBG) log("isVoNrEnabled: " + isEnabled);
8631 return isEnabled;
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636
8637 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008638 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8639 * network status based on which carrier apps could apply actions accordingly,
8640 * enable/disable default url handler for example.
8641 *
8642 * @param subId the subscription ID that this action applies to.
8643 * @param report control start/stop reporting the default network status.
8644 * {@hide}
8645 */
8646 @Override
8647 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8648 enforceModifyPermission();
8649 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008650
8651 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008652 if (phone == null) {
8653 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8654 return;
8655 }
8656 try {
8657 phone.carrierActionReportDefaultNetworkStatus(report);
8658 } catch (Exception e) {
8659 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008660 } finally {
8661 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008662 }
8663 }
8664
8665 /**
fionaxud9622282017-07-17 17:51:30 -07008666 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8667 * @param subId the subscription ID that this action applies to.
8668 * {@hide}
8669 */
8670 @Override
8671 public void carrierActionResetAll(int subId) {
8672 enforceModifyPermission();
8673 final Phone phone = getPhone(subId);
8674 if (phone == null) {
8675 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8676 return;
8677 }
8678 try {
8679 phone.carrierActionResetAll();
8680 } catch (Exception e) {
8681 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8682 }
8683 }
8684
8685 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008686 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8687 * bug report is being generated.
8688 */
8689 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008690 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008691 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8692 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008693 writer.println("Permission Denial: can't dump Phone from pid="
8694 + Binder.getCallingPid()
8695 + ", uid=" + Binder.getCallingUid()
8696 + "without permission "
8697 + android.Manifest.permission.DUMP);
8698 return;
8699 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008700 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008701 }
Jack Yueb89b242016-06-22 13:27:47 -07008702
Brad Ebingerdac2f002018-04-03 15:17:52 -07008703 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008704 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8705 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8706 @NonNull String[] args) {
8707 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8708 this, in.getFileDescriptor(), out.getFileDescriptor(),
8709 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008710 }
8711
Jack Yueb89b242016-06-22 13:27:47 -07008712 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008713 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008714 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008715 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008716 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008717 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008718 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008719 */
8720 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008721 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008722 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008723 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8724 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8725 try {
8726 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008727 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008728 } catch (SecurityException se) {
8729 enforceModifyPermission();
8730 }
8731 } else {
8732 enforceModifyPermission();
8733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008734
8735 final long identity = Binder.clearCallingIdentity();
8736 try {
8737 Phone phone = getPhone(subId);
8738 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008739 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8740 phone.carrierActionSetMeteredApnsEnabled(enabled);
8741 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008742 phone.getDataSettingsManager().setDataEnabled(
8743 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008745 }
8746 } finally {
8747 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008748 }
8749 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008750
8751 /**
8752 * Get Client request stats
8753 * @return List of Client Request Stats
8754 * @hide
8755 */
8756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008757 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8758 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008760 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008761 return null;
8762 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008763 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008765 final long identity = Binder.clearCallingIdentity();
8766 try {
8767 if (phone != null) {
8768 return phone.getClientRequestStats();
8769 }
8770
8771 return null;
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008775 }
8776
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008777 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008778 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008779 if (uid == Process.ROOT_UID && packageName == null) {
8780 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8781 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8782 // exception. ROOT_UID seems not to have a valid package name returned by
8783 // PackageManager, so just fake it here to avoid issues when running telephony shell
8784 // commands that plumb through the RIL as root, like so:
8785 // $ adb root
8786 // $ adb shell cmd phone ...
8787 packageName = "root";
8788 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008789 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008790 }
Jack Yueb4124c2017-02-16 15:32:43 -08008791
8792 /**
Grace Chen70990072017-03-24 17:21:30 -07008793 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008794 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008795 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008796 * @param state State of SIM (power down, power up, pass through)
8797 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8798 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8799 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008800 *
8801 **/
8802 @Override
Grace Chen70990072017-03-24 17:21:30 -07008803 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008804 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008805 Phone phone = PhoneFactory.getPhone(slotIndex);
8806
vagdeviaf9a5b92018-08-15 16:01:53 -07008807 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008809 final long identity = Binder.clearCallingIdentity();
8810 try {
8811 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008812 phone.setSimPowerState(state, null, workSource);
8813 }
8814 } finally {
8815 Binder.restoreCallingIdentity(identity);
8816 }
8817 }
8818
8819 /**
8820 * Set SIM card power state.
8821 *
8822 * @param slotIndex SIM slot id.
8823 * @param state State of SIM (power down, power up, pass through)
8824 * @param callback callback to trigger after success or failure
8825 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8826 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8827 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8828 *
8829 **/
8830 @Override
8831 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8832 IIntegerConsumer callback) {
8833 enforceModifyPermission();
8834 Phone phone = PhoneFactory.getPhone(slotIndex);
8835
8836 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8837
8838 final long identity = Binder.clearCallingIdentity();
8839 try {
8840 if (phone != null) {
8841 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8842 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008843 }
8844 } finally {
8845 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008846 }
8847 }
Shuo Qiandd210312017-04-12 22:11:33 +00008848
Tyler Gunn65d45c22017-06-05 11:22:26 -07008849 private boolean isUssdApiAllowed(int subId) {
8850 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008851 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008852 if (configManager == null) {
8853 return false;
8854 }
8855 PersistableBundle pb = configManager.getConfigForSubId(subId);
8856 if (pb == null) {
8857 return false;
8858 }
8859 return pb.getBoolean(
8860 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8861 }
8862
Shuo Qiandd210312017-04-12 22:11:33 +00008863 /**
8864 * Check if phone is in emergency callback mode
8865 * @return true if phone is in emergency callback mode
8866 * @param subId sub id
8867 */
goneil9c5f4872017-12-05 14:07:56 -08008868 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008869 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008870 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008871 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008872
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 if (phone != null) {
8876 return phone.isInEcm();
8877 } else {
8878 return false;
8879 }
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008882 }
8883 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008884
8885 /**
8886 * Get the current signal strength information for the given subscription.
8887 * Because this information is not updated when the device is in a low power state
8888 * it should not be relied-upon to be current.
8889 * @param subId Subscription index
8890 * @return the most recent cached signal strength info from the modem
8891 */
8892 @Override
8893 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008894 final long identity = Binder.clearCallingIdentity();
8895 try {
8896 Phone p = getPhone(subId);
8897 if (p == null) {
8898 return null;
8899 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008901 return p.getSignalStrength();
8902 } finally {
8903 Binder.restoreCallingIdentity(identity);
8904 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008905 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008906
Pengquan Meng77b7f132018-08-22 14:49:57 -07008907 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008908 * Get the current modem radio state for the given slot.
8909 * @param slotIndex slot index.
8910 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008911 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008912 * @return the current radio power state from the modem
8913 */
8914 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008915 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008916 Phone phone = PhoneFactory.getPhone(slotIndex);
8917 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8919 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008920 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8921 }
8922
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 return phone.getRadioPowerState();
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
8928 }
8929 }
8930 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8931 }
8932
8933 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008934 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8935 *
8936 * <p>Requires one of the following permissions:
8937 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008938 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008939 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8940 * privileges.
8941 *
8942 * @param subId subscription id
8943 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8944 * {@code false}.
8945 */
8946 @Override
8947 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008948 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008949 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008950 try {
8951 mApp.enforceCallingOrSelfPermission(
8952 android.Manifest.permission.ACCESS_NETWORK_STATE,
8953 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008954 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008955 mApp.enforceCallingOrSelfPermission(
8956 permission.READ_BASIC_PHONE_STATE, functionName);
8957 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008958 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008959 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008960 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008961 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008962
Pengquan Menga1bb6272018-09-06 09:59:22 -07008963 boolean isEnabled = false;
8964 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008965 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008966 Phone phone = getPhone(subId);
8967 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008968 } finally {
8969 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008970 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008971 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008972 }
8973
8974
8975 /**
8976 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8977 *
8978 * <p> Requires permission:
8979 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8980 * privileges.
8981 *
8982 * @param subId subscription id
8983 * @param isEnabled {@code true} means enable, {@code false} means disable.
8984 */
8985 @Override
8986 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8988 mApp, subId, "setDataRoamingEnabled");
8989
Pengquan Menga1bb6272018-09-06 09:59:22 -07008990 final long identity = Binder.clearCallingIdentity();
8991 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008992 Phone phone = getPhone(subId);
8993 if (phone != null) {
8994 phone.setDataRoamingEnabled(isEnabled);
8995 }
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008998 }
8999 }
9000
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009001 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009002 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009003 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009004 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009005 mApp, subId, "isManualNetworkSelectionAllowed");
9006
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009007 boolean isAllowed = true;
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009010 Phone phone = getPhone(subId);
9011 if (phone != null) {
9012 isAllowed = phone.isCspPlmnEnabled();
9013 }
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 return isAllowed;
9018 }
9019
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009020 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9021 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009022 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009023 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009024 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009025 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9026 if (phone == null) {
9027 return false;
9028 }
9029 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9030 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9031 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009032 }
9033
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009034 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009035 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009036 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009037 mApp.getSystemService(AppOpsManager.class)
9038 .checkPackage(Binder.getCallingUid(), callingPackage);
9039
Jordan Liu1e142fc2019-04-22 15:10:43 -07009040 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009041 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009042 try {
9043 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009044 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009045 } catch (SecurityException e) {
9046 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9047 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009048 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009049 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009050 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009051 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009052 }
sandeepjsb6c87872021-09-27 15:34:44 +00009053 // checking compatibility, if calling app's target SDK is T and beyond.
9054 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9055 Binder.getCallingUid())) {
9056 isIccIdAccessRestricted = true;
9057 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009058 final long identity = Binder.clearCallingIdentity();
9059 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009060 UiccController uiccController = UiccController.getInstance();
9061 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009062 if (hasReadPermission) {
9063 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009064 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009065
9066 // Remove private info if the caller doesn't have access
9067 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9068 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009069 //setting the value after compatibility check
9070 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009071 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9072 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009073 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009074 if (card == null) {
9075 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009076 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009077 continue;
9078 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009079 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9080 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009081 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009082 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009083 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009084 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9085 for (UiccPortInfo portInfo : portInfos) {
9086 UiccPort port = uiccController.getUiccPortForSlot(
9087 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9088 if (port == null) {
9089 // assume no access if port is null
9090 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9091 continue;
9092 }
9093 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9094 uiccPortInfos.add(portInfo);
9095 } else {
9096 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9097 }
9098 }
9099 filteredInfos.add(new UiccCardInfo(
9100 cardInfo.isEuicc(),
9101 cardInfo.getCardId(),
9102 null,
9103 cardInfo.getPhysicalSlotIndex(),
9104 cardInfo.isRemovable(),
9105 cardInfo.isMultipleEnabledProfilesSupported(),
9106 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009107 }
9108 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009109 } finally {
9110 Binder.restoreCallingIdentity(identity);
9111 }
9112 }
9113
sandeepjsb6c87872021-09-27 15:34:44 +00009114 /**
9115 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9116 * generally private and require carrier privileges to view.
9117 *
9118 * @hide
9119 */
9120 @NonNull
9121 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9122 List<UiccPortInfo> portinfo = new ArrayList<>();
9123 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9124 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9125 }
9126 return new UiccCardInfo(
9127 cardInfo.isEuicc(),
9128 cardInfo.getCardId(),
9129 null,
9130 cardInfo.getPhysicalSlotIndex(),
9131 cardInfo.isRemovable(),
9132 cardInfo.isMultipleEnabledProfilesSupported(),
9133 portinfo
9134 );
9135 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009136
sandeepjsb6c87872021-09-27 15:34:44 +00009137 /**
9138 * @hide
9139 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9140 * These values are generally private and require carrier privileges to view.
9141 */
9142 @NonNull
9143 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9144 return new UiccPortInfo(
9145 UiccPortInfo.ICCID_REDACTED,
9146 portInfo.getPortIndex(),
9147 portInfo.getLogicalSlotIndex(),
9148 portInfo.isActive()
9149 );
9150 }
9151 @Override
9152 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009153 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009154 mApp.getSystemService(AppOpsManager.class)
9155 .checkPackage(Binder.getCallingUid(), callingPackage);
9156
sandeepjsb6c87872021-09-27 15:34:44 +00009157 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009158
Aman Guptaf3c90b32022-03-17 04:54:16 +00009159 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9160 // we are reading iccId which is PII data.
9161 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009162
9163 // checking compatibility, if calling app's target SDK is T and beyond.
9164 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9165 Binder.getCallingUid())) {
9166 isLogicalSlotAccessRestricted = true;
9167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009171 if (slots == null || slots.length == 0) {
9172 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009173 return null;
9174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009175 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9176 for (int i = 0; i < slots.length; i++) {
9177 UiccSlot slot = slots[i];
9178 if (slot == null) {
9179 continue;
9180 }
9181
Jordan Liu7be7e652019-05-06 18:55:02 +00009182 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009183 UiccCard card = slot.getUiccCard();
9184 if (card != null) {
9185 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009186 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009187 cardId = slot.getEid();
9188 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009189 // If cardId is null, use iccId of default port as cardId.
9190 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192 }
9193
Jordan Liu857451f2019-05-09 16:35:35 -07009194 if (cardId != null) {
9195 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9196 // if cardId is an EID, it's all digits so this is fine
9197 cardId = IccUtils.stripTrailingFs(cardId);
9198 }
9199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009200 int cardState = 0;
9201 switch (slot.getCardState()) {
9202 case CARDSTATE_ABSENT:
9203 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9204 break;
9205 case CARDSTATE_PRESENT:
9206 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9207 break;
9208 case CARDSTATE_ERROR:
9209 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9210 break;
9211 case CARDSTATE_RESTRICTED:
9212 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9213 break;
9214 default:
9215 break;
9216
9217 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009218 List<UiccPortInfo> portInfos = new ArrayList<>();
9219 int[] portIndexes = slot.getPortList();
9220 for (int portIdx : portIndexes) {
9221 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009222 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009223 portInfos.add(new UiccPortInfo(iccId, portIdx,
9224 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009226 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009227 slot.isEuicc(),
9228 cardId,
9229 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009230 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009231 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009232 //setting the value after compatibility check
9233 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009234 }
9235 return infos;
9236 } finally {
9237 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009238 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009239 }
9240
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009241 /* Returns null if doesn't have read permission or carrier privilege access. */
9242 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9243 boolean hasReadPermission) {
9244 String iccId = slot.getIccId(portIndex);
9245 if (hasReadPermission) { // if has read permission
9246 return iccId;
9247 } else {
9248 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9249 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9250 // if no read permission, checking carrier privilege access
9251 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9252 return iccId;
9253 }
9254 }
9255 }
9256 // No read permission or carrier privilege access.
9257 return UiccPortInfo.ICCID_REDACTED;
9258 }
9259
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009260 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009261 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009262 public boolean switchSlots(int[] physicalSlots) {
9263 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009264
9265 final long identity = Binder.clearCallingIdentity();
9266 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009267 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9268 for (int i = 0; i < physicalSlots.length; i++) {
9269 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9270 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9271 physicalSlots[i], i));
9272 }
9273 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009277 }
Jack Yu4c988042018-02-27 15:30:01 -08009278
9279 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009280 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9281 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9282 enforceModifyPermission();
9283
9284 final long identity = Binder.clearCallingIdentity();
9285 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009286 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009287 } finally {
9288 Binder.restoreCallingIdentity(identity);
9289 }
9290 }
9291
9292 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009293 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 return UiccController.getInstance().getCardIdForDefaultEuicc();
9297 } finally {
9298 Binder.restoreCallingIdentity(identity);
9299 }
9300 }
9301
Pengquan Meng85728fb2018-03-12 16:31:21 -07009302 /**
goneil47ffb6e2018-04-06 15:40:58 -07009303 * A test API to reload the UICC profile.
9304 *
9305 * <p>Requires that the calling app has permission
9306 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9307 * @hide
9308 */
9309 @Override
9310 public void refreshUiccProfile(int subId) {
9311 enforceModifyPermission();
9312
9313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 Phone phone = getPhone(subId);
9316 if (phone == null) {
9317 return;
9318 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009319 UiccPort uiccPort = phone.getUiccPort();
9320 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009321 return;
9322 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009323 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009324 if (uiccProfile == null) {
9325 return;
9326 }
9327 uiccProfile.refresh();
9328 } finally {
9329 Binder.restoreCallingIdentity(identity);
9330 }
9331 }
9332
9333 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009334 * Returns false if the mobile data is disabled by default, otherwise return true.
9335 */
9336 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009337 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009338 }
9339
9340 /**
9341 * Returns true if the data roaming is enabled by default, i.e the system property
9342 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9343 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9344 */
9345 private boolean getDefaultDataRoamingEnabled(int subId) {
9346 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009347 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009348 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009349 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9350 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9351 return isDataRoamingEnabled;
9352 }
9353
9354 /**
9355 * Returns the default network type for the given {@code subId}, if the default network type is
9356 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9357 */
9358 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009359 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009360 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009361 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9362 return list.get(phoneId);
9363 }
9364 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009365 }
fionaxua13278b2018-03-21 00:08:13 -07009366
9367 @Override
9368 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009369 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009370 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009371
9372 final long identity = Binder.clearCallingIdentity();
9373 try {
9374 final Phone phone = getPhone(subId);
9375 if (phone == null) {
9376 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9377 return;
9378 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009379 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9380 if (cpt != null) {
9381 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9382 }
9383 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009384 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9385 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009386 if (carrierPrivilegeRules == null) {
9387 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9388 } else {
9389 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009391 } finally {
9392 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009393 }
fionaxua13278b2018-03-21 00:08:13 -07009394 }
9395
9396 @Override
9397 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009398 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009399
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 final Phone phone = getPhone(subId);
9403 if (phone == null) {
9404 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9405 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9406 }
9407 return phone.getCarrierIdListVersion();
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009410 }
fionaxua13278b2018-03-21 00:08:13 -07009411 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009412
9413 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009414 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9415 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009417 mApp, subId, callingPackage, callingFeatureId,
9418 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009419 return -1;
9420 }
9421
9422 final long identity = Binder.clearCallingIdentity();
9423 try {
9424 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009429
9430 @Override
9431 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009432 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009433 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009434 mApp, subId, "getCdmaRoamingMode");
9435
9436 final long identity = Binder.clearCallingIdentity();
9437 try {
9438 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
9443
9444 @Override
9445 public boolean setCdmaRoamingMode(int subId, int mode) {
9446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9447 mApp, subId, "setCdmaRoamingMode");
9448
9449 final long identity = Binder.clearCallingIdentity();
9450 try {
9451 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9452 } finally {
9453 Binder.restoreCallingIdentity(identity);
9454 }
9455 }
9456
9457 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009458 public int getCdmaSubscriptionMode(int subId) {
9459 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009460 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009461 mApp, subId, "getCdmaSubscriptionMode");
9462
9463 final long identity = Binder.clearCallingIdentity();
9464 try {
9465 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
9469 }
9470
9471 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009472 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9474 mApp, subId, "setCdmaSubscriptionMode");
9475
9476 final long identity = Binder.clearCallingIdentity();
9477 try {
9478 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9479 } finally {
9480 Binder.restoreCallingIdentity(identity);
9481 }
9482 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009483
sqianc5eccab2018-10-19 18:46:41 -07009484 @Override
sqian8c685422019-02-22 15:55:18 -08009485 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009486 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009488 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9489 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009490 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9491 }
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
sqian854d44b2018-12-12 16:48:18 -08009494 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9495 for (Phone phone: PhoneFactory.getPhones()) {
9496 if (phone.getEmergencyNumberTracker() != null
9497 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9498 emergencyNumberListInternal.put(
9499 phone.getSubId(),
9500 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9501 }
sqian11b7a0e2018-12-05 18:48:28 -08009502 }
sqian854d44b2018-12-12 16:48:18 -08009503 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009504 } finally {
9505 Binder.restoreCallingIdentity(identity);
9506 }
sqianc5eccab2018-10-19 18:46:41 -07009507 }
9508
9509 @Override
sqian8c685422019-02-22 15:55:18 -08009510 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009511 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009512 if (!exactMatch) {
9513 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009514 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009515 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009516 }
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
sqian854d44b2018-12-12 16:48:18 -08009519 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009520 //Note: we ignore passed in param exactMatch. We can remove it once
9521 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009522 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009523 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009524 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009525 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009526 }
sqian11b7a0e2018-12-05 18:48:28 -08009527 }
9528 return false;
9529 } finally {
9530 Binder.restoreCallingIdentity(identity);
9531 }
9532 }
9533
sqianf4ca7ed2019-01-15 18:32:07 -08009534 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009535 * Start emergency callback mode for GsmCdmaPhone for testing.
9536 */
9537 @Override
9538 public void startEmergencyCallbackMode() {
9539 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9540 "startEmergencyCallbackMode");
9541 enforceModifyPermission();
9542 final long identity = Binder.clearCallingIdentity();
9543 try {
9544 for (Phone phone : PhoneFactory.getPhones()) {
9545 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9546 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9547 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9548 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9549 gsmCdmaPhone.obtainMessage(
9550 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9551 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9552 }
9553 }
9554 } finally {
9555 Binder.restoreCallingIdentity(identity);
9556 }
9557 }
9558
9559 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009560 * Update emergency number list for test mode.
9561 */
9562 @Override
9563 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9565 "updateEmergencyNumberListTestMode");
9566
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 for (Phone phone: PhoneFactory.getPhones()) {
9570 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9571 if (tracker != null) {
9572 tracker.executeEmergencyNumberTestModeCommand(action, num);
9573 }
9574 }
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
9580 /**
9581 * Get the full emergency number list for test mode.
9582 */
9583 @Override
9584 public List<String> getEmergencyNumberListTestMode() {
9585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9586 "getEmergencyNumberListTestMode");
9587
9588 final long identity = Binder.clearCallingIdentity();
9589 try {
9590 Set<String> emergencyNumbers = new HashSet<>();
9591 for (Phone phone: PhoneFactory.getPhones()) {
9592 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9593 if (tracker != null) {
9594 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9595 emergencyNumbers.add(num.getNumber());
9596 }
9597 }
9598 }
9599 return new ArrayList<>(emergencyNumbers);
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
9604
chen xud6b45bd2018-10-30 22:27:10 -07009605 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009606 public int getEmergencyNumberDbVersion(int subId) {
9607 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9608
9609 final long identity = Binder.clearCallingIdentity();
9610 try {
9611 final Phone phone = getPhone(subId);
9612 if (phone == null) {
9613 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9614 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9615 }
9616 return phone.getEmergencyNumberDbVersion();
9617 } finally {
9618 Binder.restoreCallingIdentity(identity);
9619 }
9620 }
9621
9622 @Override
9623 public void notifyOtaEmergencyNumberDbInstalled() {
9624 enforceModifyPermission();
9625
9626 final long identity = Binder.clearCallingIdentity();
9627 try {
9628 for (Phone phone: PhoneFactory.getPhones()) {
9629 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9630 if (tracker != null) {
9631 tracker.updateOtaEmergencyNumberDatabase();
9632 }
9633 }
9634 } finally {
9635 Binder.restoreCallingIdentity(identity);
9636 }
9637 }
9638
9639 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009640 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009641 enforceActiveEmergencySessionPermission();
9642
9643 final long identity = Binder.clearCallingIdentity();
9644 try {
9645 for (Phone phone: PhoneFactory.getPhones()) {
9646 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9647 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009648 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9649 }
9650 }
9651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
9654 }
9655
9656 @Override
9657 public void resetOtaEmergencyNumberDbFilePath() {
9658 enforceActiveEmergencySessionPermission();
9659
9660 final long identity = Binder.clearCallingIdentity();
9661 try {
9662 for (Phone phone: PhoneFactory.getPhones()) {
9663 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9664 if (tracker != null) {
9665 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009666 }
9667 }
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
9672
9673 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009674 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9675 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9676 Phone phone = getPhone(subId);
9677 if (phone == null) {
9678 return null;
9679 }
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
9682 UiccProfile profile = UiccController.getInstance()
9683 .getUiccProfileForPhone(phone.getPhoneId());
9684 if (profile != null) {
9685 return profile.getCertsFromCarrierPrivilegeAccessRules();
9686 }
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 return null;
9691 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009692
9693 /**
9694 * Enable or disable a modem stack.
9695 */
9696 @Override
9697 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9698 enforceModifyPermission();
9699
9700 final long identity = Binder.clearCallingIdentity();
9701 try {
9702 Phone phone = PhoneFactory.getPhone(slotIndex);
9703 if (phone == null) {
9704 return false;
9705 } else {
9706 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9707 }
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
Michelecea4cf22018-12-21 15:00:11 -08009712
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009713 /**
9714 * Whether a modem stack is enabled or not.
9715 */
9716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009717 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9718 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009719 Phone phone = PhoneFactory.getPhone(slotIndex);
9720 if (phone == null) return false;
9721
9722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009723 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9724 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009725 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9726 }
9727
9728 final long identity = Binder.clearCallingIdentity();
9729 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009730 try {
9731 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9732 } catch (NoSuchElementException ex) {
9733 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9734 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738 }
9739
Michelecea4cf22018-12-21 15:00:11 -08009740 @Override
Michele0ea7d782019-03-19 14:58:42 -07009741 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009742 enforceModifyPermission();
9743
9744 final long identity = Binder.clearCallingIdentity();
9745 try {
9746 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009747 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009748 .commit();
9749 } finally {
9750 Binder.restoreCallingIdentity(identity);
9751 }
9752 }
9753
9754 @Override
Michele0ea7d782019-03-19 14:58:42 -07009755 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009756 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009758 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9759 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009760 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009761 }
Michelecea4cf22018-12-21 15:00:11 -08009762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
Michele0ea7d782019-03-19 14:58:42 -07009765 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009770
Michele0ea7d782019-03-19 14:58:42 -07009771 @TelephonyManager.IsMultiSimSupportedResult
9772 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009773 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9774 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9775 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009776 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9777 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009778 }
9779 // Check if the hardware supports multisim functionality. If usage of multisim is not
9780 // supported by the modem, indicate that it is restricted.
9781 PhoneCapability staticCapability =
9782 mPhoneConfigurationManager.getStaticPhoneCapability();
9783 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009784 loge("isMultiSimSupportedInternal: no static configuration available");
9785 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009786 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009787 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009788 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9789 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009790 }
9791 // Check if support of multiple SIMs is restricted by carrier
9792 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009793 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009794 }
9795
Michele0ea7d782019-03-19 14:58:42 -07009796 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009797 }
9798
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009799 /**
9800 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009801 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9802 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9803 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009804 * @param numOfSims number of active sims we want to switch to
9805 */
9806 @Override
9807 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009808 if (numOfSims == 1) {
9809 enforceModifyPermission();
9810 } else {
9811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9812 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9813 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009814 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009815
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009816 try {
Michele30b57b22019-03-01 12:01:14 -08009817 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009818 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009819 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9820 return;
9821 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009822 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9823 } finally {
9824 Binder.restoreCallingIdentity(identity);
9825 }
9826 }
9827
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009828 @Override
9829 public boolean isApplicationOnUicc(int subId, int appType) {
9830 enforceReadPrivilegedPermission("isApplicationOnUicc");
9831 Phone phone = getPhone(subId);
9832 if (phone == null) {
9833 return false;
9834 }
9835 final long identity = Binder.clearCallingIdentity();
9836 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009837 UiccPort uiccPort = phone.getUiccPort();
9838 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009839 return false;
9840 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009841 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009842 if (uiccProfile == null) {
9843 return false;
9844 }
9845 if (TelephonyManager.APPTYPE_SIM <= appType
9846 && appType <= TelephonyManager.APPTYPE_ISIM) {
9847 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9848 }
9849 return false;
9850 } finally {
9851 Binder.restoreCallingIdentity(identity);
9852 }
9853 }
9854
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009855 /**
chen xub4baa772019-04-03 10:23:41 -07009856 * Get whether making changes to modem configurations will trigger reboot.
9857 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009858 */
9859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009860 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9861 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009863 mApp, subId, callingPackage, callingFeatureId,
9864 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009865 return false;
9866 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009867 final long identity = Binder.clearCallingIdentity();
9868 try {
9869 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
9872 }
9873 }
9874
Nathan Harold29f5f052019-02-15 13:41:57 -08009875 private void updateModemStateMetrics() {
9876 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9877 // TODO: check the state for each modem if the api is ready.
9878 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9879 }
9880
Pengquan Meng3889a572019-01-23 11:16:29 -08009881 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009882 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009883 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009884 // Verify that the callingPackage belongs to the calling UID
9885 mApp.getSystemService(AppOpsManager.class)
9886 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009887 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009888 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009889 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009890 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9891 if (slotInfos != null) {
9892 for (int i = 0; i < slotInfos.length; i++) {
9893 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9894 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9895 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9896 portInfo.getLogicalSlotIndex()));
9897 }
9898 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009899 }
9900 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009901 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009902 } finally {
9903 Binder.restoreCallingIdentity(identity);
9904 }
9905 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009906
9907 /**
9908 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009909 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009910 */
jimsunf9ec1622022-09-13 21:18:43 +08009911 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009912 @Override
9913 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009914 return getHalVersion(HAL_SERVICE_RADIO);
9915 }
9916
9917 /**
9918 * Get the HAL Version of a specific service
9919 */
9920 @Override
9921 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009922 Phone phone = getDefaultPhone();
9923 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009924 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009925 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9926 return hv.major * 100 + hv.minor;
9927 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009928
9929 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009930 * Get the current calling package name.
9931 * @return the current calling package name
9932 */
9933 @Override
9934 public String getCurrentPackageName() {
9935 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9936 }
9937
9938 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009939 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9940 * corresponding network requests on a subId.
9941 *
9942 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009943 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009944 * 2) APN is un-metered for this subscription, or
9945 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009946 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009947 *
9948 * @return whether data is allowed for a apn type.
9949 *
9950 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009951 */
9952 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009953 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009954 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9955 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009956
9957 // Now that all security checks passes, perform the operation as ourselves.
9958 final long identity = Binder.clearCallingIdentity();
9959 try {
9960 Phone phone = getPhone(subId);
9961 if (phone == null) return false;
9962
Jack Yu27422a52022-03-21 10:38:05 -07009963 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009964 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009965 isMetered = phone.getDataNetworkController().getDataConfigManager()
9966 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9967 phone.getServiceState().getDataRoaming());
9968 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009969 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009970 } finally {
9971 Binder.restoreCallingIdentity(identity);
9972 }
9973 }
9974
9975 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009976 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009977 enforceReadPrivilegedPermission("isApnMetered");
9978
9979 // Now that all security checks passes, perform the operation as ourselves.
9980 final long identity = Binder.clearCallingIdentity();
9981 try {
9982 Phone phone = getPhone(subId);
9983 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009984 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9985 DataUtils.apnTypeToNetworkCapability(apnType),
9986 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009987 } finally {
9988 Binder.restoreCallingIdentity(identity);
9989 }
9990 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009991
9992 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009993 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9994 int subscriptionId, IBooleanConsumer resultCallback) {
9995 enforceModifyPermission();
9996 long token = Binder.clearCallingIdentity();
9997 try {
9998 Phone phone = getPhone(subscriptionId);
9999 if (phone == null) {
10000 try {
10001 if (resultCallback != null) {
10002 resultCallback.accept(false);
10003 }
10004 } catch (RemoteException e) {
10005 // ignore
10006 }
10007 return;
10008 }
10009 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10010 Pair.create(specifiers, (x) -> {
10011 try {
10012 if (resultCallback != null) {
10013 resultCallback.accept(x);
10014 }
10015 } catch (RemoteException e) {
10016 // ignore
10017 }
10018 });
10019 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10020 } finally {
10021 Binder.restoreCallingIdentity(token);
10022 }
10023 }
10024
10025 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010026 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10027 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010028 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010029 mApp, subId, "getSystemSelectionChannels");
10030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10031 final long identity = Binder.clearCallingIdentity();
10032 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010033 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10034 if (result instanceof IllegalStateException) {
10035 throw (IllegalStateException) result;
10036 }
10037 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010038 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10039 return specifiers;
10040 } finally {
10041 Binder.restoreCallingIdentity(identity);
10042 }
10043 }
10044
10045 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010046 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010047 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010048 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010049 }
10050
10051 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010052 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10053 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010054 if (callingPackage == null) {
10055 callingPackage = getCurrentPackageName();
10056 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010057 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10058 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010059 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10060 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010061 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10062 }
10063 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10064 Intent intent = new Intent();
10065 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10066 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10067 // Bring up choose default SMS subscription dialog right now
10068 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10069 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10070 mApp.startActivity(intent);
10071 }
chen xud5ca2d52019-05-28 15:20:57 -070010072
10073 @Override
10074 public String getMmsUAProfUrl(int subId) {
10075 //TODO investigate if this API should require proper permission check in R b/133791609
10076 final long identity = Binder.clearCallingIdentity();
10077 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010078 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10079 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10080 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10081 return carrierUAProfUrl;
10082 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010083 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10084 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010085 } finally {
10086 Binder.restoreCallingIdentity(identity);
10087 }
10088 }
10089
10090 @Override
10091 public String getMmsUserAgent(int subId) {
10092 //TODO investigate if this API should require proper permission check in R b/133791609
10093 final long identity = Binder.clearCallingIdentity();
10094 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010095 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10096 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10097 if (!TextUtils.isEmpty(carrierUserAgent)) {
10098 return carrierUserAgent;
10099 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010100 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10101 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010102 } finally {
10103 Binder.restoreCallingIdentity(identity);
10104 }
10105 }
Jack Yub07d4972019-05-28 16:12:25 -070010106
10107 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010108 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10109 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010110
Jack Yub07d4972019-05-28 16:12:25 -070010111 final long identity = Binder.clearCallingIdentity();
10112 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010113 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010114 if (phone == null) return false;
10115
Ling Maf188d502022-09-16 15:22:36 -070010116 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010117 } finally {
10118 Binder.restoreCallingIdentity(identity);
10119 }
10120 }
10121
10122 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010123 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010124 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010125 enforceModifyPermission();
10126
changbettyd5c246e2019-12-24 15:40:37 +080010127 final long identity = Binder.clearCallingIdentity();
10128 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010129 Phone phone = getPhone(subscriptionId);
10130 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010131
Ling Maf188d502022-09-16 15:22:36 -070010132 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010133 } finally {
10134 Binder.restoreCallingIdentity(identity);
10135 }
10136 }
10137
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010138 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010139 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010140 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10141 * otherwise.
10142 */
10143 @Override
10144 public void setCepEnabled(boolean isCepEnabled) {
10145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10146
10147 final long identity = Binder.clearCallingIdentity();
10148 try {
10149 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10150 for (Phone phone : PhoneFactory.getPhones()) {
10151 Phone defaultPhone = phone.getImsPhone();
10152 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10153 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10154 ImsPhoneCallTracker imsPhoneCallTracker =
10155 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10156 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10157 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10158 + imsPhone.getMsisdn());
10159 }
10160 }
10161 } finally {
10162 Binder.restoreCallingIdentity(identity);
10163 }
10164 }
allenwtsu46dcc572020-01-08 18:24:03 +080010165
10166 /**
10167 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10168 *
10169 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10170 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10171 * before being read.
10172 */
10173 @Override
10174 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10175 isCompressed) {
10176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10177 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10179 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10180 }
10181 if (!isImsAvailableOnDevice()) {
10182 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10183 "IMS not available on device.");
10184 }
10185
10186 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010187 try {
Hui Wang761a6682020-10-31 05:12:53 +000010188 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10189 } finally {
10190 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010191 }
10192 }
zoey chene02881a2019-12-30 16:11:23 +080010193
10194 @Override
10195 public boolean isIccLockEnabled(int subId) {
10196 enforceReadPrivilegedPermission("isIccLockEnabled");
10197
10198 // Now that all security checks passes, perform the operation as ourselves.
10199 final long identity = Binder.clearCallingIdentity();
10200 try {
10201 Phone phone = getPhone(subId);
10202 if (phone != null && phone.getIccCard() != null) {
10203 return phone.getIccCard().getIccLockEnabled();
10204 } else {
10205 return false;
10206 }
10207 } finally {
10208 Binder.restoreCallingIdentity(identity);
10209 }
10210 }
10211
10212 /**
10213 * Set the ICC pin lock enabled or disabled.
10214 *
10215 * @return an integer representing the status of IccLock enabled or disabled in the following
10216 * three cases:
10217 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10218 * successfully.
10219 * - Positive number and zero for remaining password attempts.
10220 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10221 *
10222 */
10223 @Override
10224 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10225 enforceModifyPermission();
10226
10227 Phone phone = getPhone(subId);
10228 if (phone == null) {
10229 return 0;
10230 }
10231 // Now that all security checks passes, perform the operation as ourselves.
10232 final long identity = Binder.clearCallingIdentity();
10233 try {
10234 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10235 new Pair<Boolean, String>(enabled, password), phone, null);
10236 return attemptsRemaining;
10237
10238 } catch (Exception e) {
10239 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10240 } finally {
10241 Binder.restoreCallingIdentity(identity);
10242 }
10243 return 0;
10244 }
10245
10246 /**
10247 * Change the ICC password used in ICC pin lock.
10248 *
10249 * @return an integer representing the status of IccLock changed in the following three cases:
10250 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10251 * - Positive number and zero for remaining password attempts.
10252 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10253 *
10254 */
10255 @Override
10256 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10257 enforceModifyPermission();
10258
10259 Phone phone = getPhone(subId);
10260 if (phone == null) {
10261 return 0;
10262 }
10263 // Now that all security checks passes, perform the operation as ourselves.
10264 final long identity = Binder.clearCallingIdentity();
10265 try {
10266 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10267 new Pair<String, String>(oldPassword, newPassword), phone, null);
10268 return attemptsRemaining;
10269
10270 } catch (Exception e) {
10271 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10272 } finally {
10273 Binder.restoreCallingIdentity(identity);
10274 }
10275 return 0;
10276 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010277
10278 /**
10279 * Request for receiving user activity notification
10280 */
10281 @Override
10282 public void requestUserActivityNotification() {
10283 if (!mNotifyUserActivity.get()
10284 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10285 mNotifyUserActivity.set(true);
10286 }
10287 }
10288
10289 /**
10290 * Called when userActivity is signalled in the power manager.
10291 * This is safe to call from any thread, with any window manager locks held or not.
10292 */
10293 @Override
10294 public void userActivity() {
10295 // ***************************************
10296 // * Inherited from PhoneWindowManager *
10297 // ***************************************
10298 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10299 // WITH ITS LOCKS HELD.
10300 //
10301 // This code must be VERY careful about the locks
10302 // it acquires.
10303 // In fact, the current code acquires way too many,
10304 // and probably has lurking deadlocks.
10305
10306 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10307 throw new SecurityException("Only the OS may call notifyUserActivity()");
10308 }
10309
10310 if (mNotifyUserActivity.getAndSet(false)) {
10311 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10312 USER_ACTIVITY_NOTIFICATION_DELAY);
10313 }
10314 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010315
10316 @Override
10317 public boolean canConnectTo5GInDsdsMode() {
10318 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10319 }
Jack Yud10cdd42020-09-28 20:28:01 -070010320
10321 @Override
10322 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10323 String callingFeatureId) {
10324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10325 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10326 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10327 }
10328
10329 Phone phone = getPhone(subId);
10330 if (phone == null) {
10331 throw new RuntimeException("phone is not available");
10332 }
10333 // Now that all security checks passes, perform the operation as ourselves.
10334 final long identity = Binder.clearCallingIdentity();
10335 try {
10336 return phone.getEquivalentHomePlmns();
10337 } finally {
10338 Binder.restoreCallingIdentity(identity);
10339 }
10340 }
Daniel Bright59e67312020-11-13 11:49:37 -080010341
10342 @Override
10343 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010344 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10345 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010346 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010347 if (radioInterfaceCapabilities == null) {
10348 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010349 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010350 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010351 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010352
Hui Wang641e81c2020-10-12 12:14:23 -070010353 @Override
10354 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10355 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010356 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10357 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10358 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10359 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10360 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010361 if (DBG) {
10362 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10363 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10364 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10365 }
10366
10367 if (!SubscriptionManager.isValidSubscriptionId(subId)
10368 || appType < TelephonyManager.APPTYPE_UNKNOWN
10369 || appType > TelephonyManager.APPTYPE_ISIM
10370 || nafUrl == null || securityProtocol == null || callback == null) {
10371 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10372 if (callback != null) {
10373 try {
10374 callback.onAuthenticationFailure(
10375 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10376 } catch (RemoteException exception) {
10377 log("Fail to notify onAuthenticationFailure due to " + exception);
10378 }
10379 return;
10380 }
10381 }
10382
10383 final long token = Binder.clearCallingIdentity();
10384 try {
10385 getGbaManager(subId).bootstrapAuthenticationRequest(
10386 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10387 forceBootStrapping, callback));
10388 } finally {
10389 Binder.restoreCallingIdentity(token);
10390 }
10391 }
10392
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010393 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010394 * Attempts to set the radio power state for all phones for thermal reason.
10395 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010396 * requested radio power state will actually be set. See {@link
10397 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10398 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010399 * @param enable {@code true} if trying to turn radio on.
10400 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10401 * false}.
10402 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010403 private boolean setRadioPowerForThermal(boolean enable) {
10404 boolean isPhoneAvailable = false;
10405 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10406 Phone phone = PhoneFactory.getPhone(i);
10407 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010408 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010409 isPhoneAvailable = true;
10410 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010411 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010412
10413 // return true if successfully informed the phone object about the thermal radio power
10414 // request.
10415 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010416 }
10417
10418 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010419 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010420 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10421 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10422 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10423 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10424 throw new IllegalArgumentException("modem does not support data throttling");
10425 }
10426
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010427 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10428 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010429 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010430 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10431 }
10432
Sarah Chinecc78c42022-03-31 21:16:48 -070010433 setDataEnabledForReason(
10434 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010435
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010436 if (isDataThrottlingSupported) {
10437 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010438 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010439 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10440 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10441 } else if (thermalMitigationResult
10442 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010443 log("Modem likely does not support data throttling on secondary carrier. Data " +
10444 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10445 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010446 }
10447 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010448 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010449
10450 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010451 }
10452
Jack Nudelman644b91a2021-03-12 14:09:48 -080010453 private static List<String> getThermalMitigationAllowlist(Context context) {
10454 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10455 for (String pckg : context.getResources()
10456 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10457 sThermalMitigationAllowlistedPackages.add(pckg);
10458 }
10459 }
10460
10461 return sThermalMitigationAllowlistedPackages;
10462 }
10463
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010464 private boolean isAnyPhoneInEmergencyState() {
10465 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10466 if (tm.isInEmergencyCall()) {
10467 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10468 return true;
10469 }
10470 for (Phone phone : PhoneFactory.getPhones()) {
10471 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10472 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10473 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10474 + phone.isInEcm());
10475 return true;
10476 }
10477 }
10478
10479 return false;
10480 }
10481
Jack Nudelman644b91a2021-03-12 14:09:48 -080010482 /**
10483 * Used by shell commands to add an authorized package name for thermal mitigation.
10484 * @param packageName name of package to be allowlisted
10485 * @param context
10486 */
10487 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10488 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10489 sThermalMitigationAllowlistedPackages.add(packageName);
10490 }
10491
10492 /**
10493 * Used by shell commands to remove an authorized package name for thermal mitigation.
10494 * @param packageName name of package to remove from allowlist
10495 * @param context
10496 */
10497 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10498 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10499 sThermalMitigationAllowlistedPackages.remove(packageName);
10500 }
10501
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010502 /**
10503 * Thermal mitigation request to control functionalities at modem.
10504 *
10505 * @param subId the id of the subscription.
10506 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010507 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010508 *
10509 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10510 */
10511 @Override
10512 @ThermalMitigationResult
10513 public int sendThermalMitigationRequest(
10514 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010515 ThermalMitigationRequest thermalMitigationRequest,
10516 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010517 enforceModifyPermission();
10518
Jack Nudelman644b91a2021-03-12 14:09:48 -080010519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10520 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10521 .contains(callingPackage)) {
10522 throw new SecurityException("Calling package must be configured in the device config. "
10523 + "calling package: " + callingPackage);
10524 }
10525
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010526 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10527 final long identity = Binder.clearCallingIdentity();
10528
10529 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10530 try {
10531 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10532 switch (thermalMitigationAction) {
10533 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10534 thermalMitigationResult =
10535 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010536 thermalMitigationRequest.getDataThrottlingRequest(),
10537 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010538 break;
10539 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10540 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10541 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10542 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10543 }
10544
10545 // Ensure that radio is on. If not able to power on due to phone being
10546 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010547 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010548 thermalMitigationResult =
10549 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10550 break;
10551 }
10552
10553 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010554 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010555 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10556 break;
10557 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10558 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10559 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10560 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10561 }
10562
10563 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10564 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010565 Phone phone = getPhone(subId);
10566 if (phone == null) {
10567 thermalMitigationResult =
10568 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10569 break;
10570 }
10571
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010572 TelephonyConnectionService service =
10573 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010574 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010575 Log.e(LOG_TAG, "An emergency call is pending");
10576 thermalMitigationResult =
10577 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10578 break;
10579 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010580 thermalMitigationResult =
10581 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10582 break;
10583 }
10584 } else {
10585 thermalMitigationResult =
10586 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10587 break;
10588 }
10589
10590 // Turn radio off. If not able to power off due to phone being unavailable,
10591 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010592 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010593 thermalMitigationResult =
10594 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10595 break;
10596 }
10597 thermalMitigationResult =
10598 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10599 break;
10600 default:
10601 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10602 + "not exist. Requested action: " + thermalMitigationAction);
10603 }
10604 } catch (IllegalArgumentException e) {
10605 throw e;
10606 } catch (Exception e) {
10607 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10608 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10609 } finally {
10610 Binder.restoreCallingIdentity(identity);
10611 }
10612
10613 if (DBG) {
10614 log("thermalMitigationRequest returning with thermalMitigationResult: "
10615 + thermalMitigationResult);
10616 }
10617
10618 return thermalMitigationResult;
10619 }
Hui Wang641e81c2020-10-12 12:14:23 -070010620
10621 /**
10622 * Set the GbaService Package Name that Telephony will bind to.
10623 *
10624 * @param subId The sim that the GbaService is associated with.
10625 * @param packageName The name of the package to be replaced with.
10626 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10627 */
10628 @Override
10629 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10630 enforceModifyPermission();
10631
10632 final long identity = Binder.clearCallingIdentity();
10633 try {
10634 return getGbaManager(subId).overrideServicePackage(packageName);
10635 } finally {
10636 Binder.restoreCallingIdentity(identity);
10637 }
10638 }
10639
10640 /**
10641 * Return the package name of the currently bound GbaService.
10642 *
10643 * @param subId The sim that the GbaService is associated with.
10644 * @return the package name of the GbaService configuration, null if GBA is not supported.
10645 */
10646 @Override
10647 public String getBoundGbaService(int subId) {
10648 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10649
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
10652 return getGbaManager(subId).getServicePackage();
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
10658 /**
10659 * Set the release time for telephony to unbind GbaService.
10660 *
10661 * @param subId The sim that the GbaService is associated with.
10662 * @param interval The release time to unbind GbaService by millisecond.
10663 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10664 */
10665 @Override
10666 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10667 enforceModifyPermission();
10668
10669 final long identity = Binder.clearCallingIdentity();
10670 try {
10671 return getGbaManager(subId).overrideReleaseTime(interval);
10672 } finally {
10673 Binder.restoreCallingIdentity(identity);
10674 }
10675 }
10676
10677 /**
10678 * Return the release time for telephony to unbind GbaService.
10679 *
10680 * @param subId The sim that the GbaService is associated with.
10681 * @return The release time to unbind GbaService by millisecond.
10682 */
10683 @Override
10684 public int getGbaReleaseTime(int subId) {
10685 enforceReadPrivilegedPermission("getGbaReleaseTime");
10686
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 return getGbaManager(subId).getReleaseTime();
10690 } finally {
10691 Binder.restoreCallingIdentity(identity);
10692 }
10693 }
10694
10695 private GbaManager getGbaManager(int subId) {
10696 GbaManager instance = GbaManager.getInstance(subId);
10697 if (instance == null) {
10698 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10699 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10700 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10701 }
10702 return instance;
10703 }
Hui Wang761a6682020-10-31 05:12:53 +000010704
10705 /**
10706 * indicate whether the device and the carrier can support
10707 * RCS VoLTE single registration.
10708 */
10709 @Override
10710 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010711 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10712 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10713 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10714 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010715
10716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10717 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10718 }
10719
10720 final long identity = Binder.clearCallingIdentity();
10721 try {
10722 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10723 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010724 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10725 if (isCapable != null) {
10726 return isCapable;
10727 }
Hui Wang761a6682020-10-31 05:12:53 +000010728 }
Hui Wang67af90e2021-06-04 16:57:15 -070010729 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10730 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010731 } finally {
10732 Binder.restoreCallingIdentity(identity);
10733 }
10734 }
10735
10736 /**
10737 * Register RCS provisioning callback.
10738 */
10739 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010740 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010741 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010742 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010743 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010744 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10745 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010746
10747 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10748 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10749 }
10750 if (!isImsAvailableOnDevice()) {
10751 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10752 "IMS not available on device.");
10753 }
10754
10755 final long identity = Binder.clearCallingIdentity();
10756 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010757 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010758 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010759 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10760 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010761 }
Hui Wang761a6682020-10-31 05:12:53 +000010762 } finally {
10763 Binder.restoreCallingIdentity(identity);
10764 }
10765 }
10766
10767 /**
10768 * Unregister RCS provisioning callback.
10769 */
10770 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010771 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010772 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010773 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010774 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010775 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10776 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010777
10778 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10779 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10780 }
10781 if (!isImsAvailableOnDevice()) {
10782 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10783 "IMS not available on device.");
10784 }
10785
10786 final long identity = Binder.clearCallingIdentity();
10787 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010788 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010789 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
10794
10795 /**
10796 * trigger RCS reconfiguration.
10797 */
10798 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010799 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10800 "triggerRcsReconfiguration",
10801 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010802
10803 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10804 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10805 }
10806 if (!isImsAvailableOnDevice()) {
10807 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10808 "IMS not available on device.");
10809 }
10810
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
10818
10819 /**
10820 * Provide the client configuration parameters of the RCS application.
10821 */
10822 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010823 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10824 "setRcsClientConfiguration",
10825 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010826
10827 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10828 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10829 }
10830 if (!isImsAvailableOnDevice()) {
10831 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10832 "IMS not available on device.");
10833 }
10834
10835 final long identity = Binder.clearCallingIdentity();
10836
10837 try {
10838 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10839 if (configBinder == null) {
10840 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010841 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10842 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010843 } else {
10844 configBinder.setRcsClientConfiguration(rcc);
10845 }
joonhunshin3e154242021-09-17 06:33:39 +000010846
10847 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10848 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010849 } catch (RemoteException e) {
10850 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010851 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10852 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
10857
10858 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010859 * Enables or disables the test mode for RCS VoLTE single registration.
10860 */
10861 @Override
10862 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10864 "setRcsSingleRegistrationTestModeEnabled");
10865
10866 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10867 }
10868
10869 /**
10870 * Gets the test mode for RCS VoLTE single registration.
10871 */
10872 @Override
10873 public boolean getRcsSingleRegistrationTestModeEnabled() {
10874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10875 "getRcsSingleRegistrationTestModeEnabled");
10876
10877 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10878 }
10879
10880 /**
Hui Wang761a6682020-10-31 05:12:53 +000010881 * Overrides the config of RCS VoLTE single registration enabled for the device.
10882 */
10883 @Override
10884 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10886 "setDeviceSingleRegistrationEnabledOverride");
10887 enforceModifyPermission();
10888
10889 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10890 : Boolean.parseBoolean(enabledStr);
10891 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010892 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010893 }
10894
10895 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010896 * Sends a device to device communication message. Only usable via shell.
10897 * @param message message to send.
10898 * @param value message value.
10899 */
10900 @Override
10901 public void sendDeviceToDeviceMessage(int message, int value) {
10902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010903 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010904 enforceModifyPermission();
10905
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 TelephonyConnectionService service =
10909 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10910 if (service == null) {
10911 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10912 return;
10913 }
10914 service.sendTestDeviceToDeviceMessage(message, value);
10915 } finally {
10916 Binder.restoreCallingIdentity(identity);
10917 }
10918 }
10919
Tyler Gunnbabbda02021-02-10 11:05:02 -080010920 /**
10921 * Sets the specified device to device transport active.
10922 * @param transport The transport to set active.
10923 */
10924 @Override
10925 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10926 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10927 "setActiveDeviceToDeviceTransport");
10928 enforceModifyPermission();
10929
10930 final long identity = Binder.clearCallingIdentity();
10931 try {
10932 TelephonyConnectionService service =
10933 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10934 if (service == null) {
10935 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10936 return;
10937 }
10938 service.setActiveDeviceToDeviceTransport(transport);
10939 } finally {
10940 Binder.restoreCallingIdentity(identity);
10941 }
10942 }
Tyler Gunn92479152021-01-20 16:30:10 -080010943
Tyler Gunnd4339262021-05-03 14:46:49 -070010944 @Override
10945 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10946 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10947 "setDeviceToDeviceForceEnabled");
10948
10949 final long identity = Binder.clearCallingIdentity();
10950 try {
10951 Arrays.stream(PhoneFactory.getPhones()).forEach(
10952 p -> {
10953 Phone thePhone = p.getImsPhone();
10954 if (thePhone != null && thePhone instanceof ImsPhone) {
10955 ImsPhone imsPhone = (ImsPhone) thePhone;
10956 CallTracker tracker = imsPhone.getCallTracker();
10957 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10958 ImsPhoneCallTracker imsPhoneCallTracker =
10959 (ImsPhoneCallTracker) tracker;
10960 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10961 }
10962 }
10963 }
10964 );
10965 } finally {
10966 Binder.restoreCallingIdentity(identity);
10967 }
10968 }
10969
Tyler Gunn92479152021-01-20 16:30:10 -080010970 /**
Hui Wang761a6682020-10-31 05:12:53 +000010971 * Gets the config of RCS VoLTE single registration enabled for the device.
10972 */
10973 @Override
10974 public boolean getDeviceSingleRegistrationEnabled() {
10975 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10976 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10977 }
10978
10979 /**
10980 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10981 */
10982 @Override
10983 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10985 "setCarrierSingleRegistrationEnabledOverride");
10986 enforceModifyPermission();
10987
10988 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10989 : Boolean.parseBoolean(enabledStr);
10990 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10991 subId, enabled);
10992 }
10993
10994 /**
10995 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10996 */
10997 @Override
10998 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10999 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11000 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11001 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011002
11003 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011004 * Overrides the ims feature validation result
11005 */
11006 @Override
11007 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11009 "setImsFeatureValidationOverride");
11010
11011 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11012 : Boolean.parseBoolean(enabledStr);
11013 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11014 subId, enabled);
11015 }
11016
11017 /**
11018 * Gets the ims feature validation override value
11019 */
11020 @Override
11021 public boolean getImsFeatureValidationOverride(int subId) {
11022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11023 "getImsFeatureValidationOverride");
11024 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11025 }
11026
11027 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011028 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11029 * their mobile plan.
11030 */
11031 @Override
11032 public String getMobileProvisioningUrl() {
11033 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11034 final long identity = Binder.clearCallingIdentity();
11035 try {
11036 return getDefaultPhone().getMobileProvisioningUrl();
11037 } finally {
11038 Binder.restoreCallingIdentity(identity);
11039 }
11040 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011041
James.cf Linbcdf8b32021-01-14 16:44:13 +080011042 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011043 * Get the EAB contact from the EAB database.
11044 */
11045 @Override
11046 public String getContactFromEab(String contact) {
11047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11048 enforceModifyPermission();
11049 final long identity = Binder.clearCallingIdentity();
11050 try {
11051 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
11056
11057 /**
Calvin Pana1434322021-07-01 19:27:01 +080011058 * Get the EAB capability from the EAB database.
11059 */
11060 @Override
11061 public String getCapabilityFromEab(String contact) {
11062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11063 enforceModifyPermission();
11064 final long identity = Binder.clearCallingIdentity();
11065 try {
11066 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11067 } finally {
11068 Binder.restoreCallingIdentity(identity);
11069 }
11070 }
11071
11072 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011073 * Remove the EAB contacts from the EAB database.
11074 */
11075 @Override
11076 public int removeContactFromEab(int subId, String contacts) {
11077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11078 enforceModifyPermission();
11079 final long identity = Binder.clearCallingIdentity();
11080 try {
11081 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11082 } finally {
11083 Binder.restoreCallingIdentity(identity);
11084 }
11085 }
11086
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011087 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011088 public boolean getDeviceUceEnabled() {
11089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11090 final long identity = Binder.clearCallingIdentity();
11091 try {
11092 return mApp.getDeviceUceEnabled();
11093 } finally {
11094 Binder.restoreCallingIdentity(identity);
11095 }
11096 }
11097
11098 @Override
11099 public void setDeviceUceEnabled(boolean isEnabled) {
11100 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11101 final long identity = Binder.clearCallingIdentity();
11102 try {
11103 mApp.setDeviceUceEnabled(isEnabled);
11104 } finally {
11105 Binder.restoreCallingIdentity(identity);
11106 }
11107 }
11108
Brad Ebinger14d467f2021-02-12 06:18:28 +000011109 /**
11110 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11111 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11112 */
11113 // Used for SHELL command only right now.
11114 @Override
11115 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11116 List<String> featureTags) {
11117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11118 "addUceRegistrationOverrideShell");
11119 final long identity = Binder.clearCallingIdentity();
11120 try {
11121 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11122 new ArraySet<>(featureTags));
11123 } catch (ImsException e) {
11124 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11125 } finally {
11126 Binder.restoreCallingIdentity(identity);
11127 }
11128 }
11129
11130 /**
11131 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11132 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11133 */
11134 // Used for SHELL command only right now.
11135 @Override
11136 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11137 List<String> featureTags) {
11138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11139 "removeUceRegistrationOverrideShell");
11140 final long identity = Binder.clearCallingIdentity();
11141 try {
11142 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11143 new ArraySet<>(featureTags));
11144 } catch (ImsException e) {
11145 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11146 } finally {
11147 Binder.restoreCallingIdentity(identity);
11148 }
11149 }
11150
11151 /**
11152 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11153 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11154 */
11155 // Used for SHELL command only right now.
11156 @Override
11157 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11159 "clearUceRegistrationOverrideShell");
11160 final long identity = Binder.clearCallingIdentity();
11161 try {
11162 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11163 } catch (ImsException e) {
11164 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11165 } finally {
11166 Binder.restoreCallingIdentity(identity);
11167 }
11168 }
11169
11170 /**
11171 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11172 */
11173 // Used for SHELL command only right now.
11174 @Override
11175 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11176 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11177 "getLatestRcsContactUceCapabilityShell");
11178 final long identity = Binder.clearCallingIdentity();
11179 try {
11180 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11181 } catch (ImsException e) {
11182 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11183 } finally {
11184 Binder.restoreCallingIdentity(identity);
11185 }
11186 }
11187
11188 /**
11189 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11190 * device does not have an active PUBLISH.
11191 */
11192 // Used for SHELL command only right now.
11193 @Override
11194 public String getLastUcePidfXmlShell(int subId) {
11195 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11196 final long identity = Binder.clearCallingIdentity();
11197 try {
11198 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11199 } catch (ImsException e) {
11200 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11201 } finally {
11202 Binder.restoreCallingIdentity(identity);
11203 }
11204 }
11205
James.cf Line8713a42021-04-29 16:04:26 +080011206 /**
11207 * Remove UCE requests cannot be sent to the network status.
11208 */
11209 // Used for SHELL command only right now.
11210 @Override
11211 public boolean removeUceRequestDisallowedStatus(int subId) {
11212 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11213 final long identity = Binder.clearCallingIdentity();
11214 try {
11215 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11216 } catch (ImsException e) {
11217 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11218 } finally {
11219 Binder.restoreCallingIdentity(identity);
11220 }
11221 }
11222
James.cf Lin18bb9002021-05-25 01:37:38 +080011223 /**
11224 * Remove UCE requests cannot be sent to the network status.
11225 */
11226 // Used for SHELL command only.
11227 @Override
11228 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11229 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11230 final long identity = Binder.clearCallingIdentity();
11231 try {
11232 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11233 } catch (ImsException e) {
11234 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11235 } finally {
11236 Binder.restoreCallingIdentity(identity);
11237 }
11238 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011239
James.cf Lin4b784aa2021-01-31 03:25:15 +080011240 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011241 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11242 String callingPackage) {
11243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11244 mApp, subId, "setSignalStrengthUpdateRequest");
11245
11246 final int callingUid = Binder.getCallingUid();
11247 // Verify that tha callingPackage belongs to the calling UID
11248 mApp.getSystemService(AppOpsManager.class)
11249 .checkPackage(callingUid, callingPackage);
11250
Rambo Wang3607f502021-02-01 21:51:40 -080011251 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011252
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11256 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11257
11258 if (result instanceof IllegalStateException) {
11259 throw (IllegalStateException) result;
11260 }
11261 } finally {
11262 Binder.restoreCallingIdentity(identity);
11263 }
11264 }
11265
11266 @Override
11267 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11268 String callingPackage) {
11269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11270 mApp, subId, "clearSignalStrengthUpdateRequest");
11271
11272 final int callingUid = Binder.getCallingUid();
11273 // Verify that tha callingPackage belongs to the calling UID
11274 mApp.getSystemService(AppOpsManager.class)
11275 .checkPackage(callingUid, callingPackage);
11276
11277 final long identity = Binder.clearCallingIdentity();
11278 try {
11279 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11280 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11281
11282 if (result instanceof IllegalStateException) {
11283 throw (IllegalStateException) result;
11284 }
11285 } finally {
11286 Binder.restoreCallingIdentity(identity);
11287 }
11288 }
11289
Rambo Wang3607f502021-02-01 21:51:40 -080011290 private static void validateSignalStrengthUpdateRequest(Context context,
11291 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011292 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11293 // phone/system process do not have further restriction on request
11294 return;
11295 }
11296
11297 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011298 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011299 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011300 context.enforceCallingOrSelfPermission(
11301 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11302 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011303 }
11304
11305 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11306 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11307 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11308 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11309 || info.isEnabled()) {
11310 throw new IllegalArgumentException(
11311 "Only system can set hide fields in SignalThresholdInfo");
11312 }
11313
11314 // Thresholds length for each RAN need in range. This has been validated in
11315 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11316 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11317 final int[] thresholds = info.getThresholds();
11318 Objects.requireNonNull(thresholds);
11319 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11320 || thresholds.length
11321 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11322 throw new IllegalArgumentException(
11323 "thresholds length is out of range: " + thresholds.length);
11324 }
11325 }
11326 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011327
11328 /**
11329 * Gets the current phone capability.
11330 *
11331 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11332 * @return the PhoneCapability which describes the data connection capability of modem.
11333 * It's used to evaluate possible phone config change, for example from single
11334 * SIM device to multi-SIM device.
11335 */
11336 @Override
11337 public PhoneCapability getPhoneCapability() {
11338 enforceReadPrivilegedPermission("getPhoneCapability");
11339 final long identity = Binder.clearCallingIdentity();
11340 try {
11341 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11342 } finally {
11343 Binder.restoreCallingIdentity(identity);
11344 }
11345 }
Michele Berionne5e411512020-11-13 02:36:59 +000011346
11347 /**
11348 * Prepare TelephonyManager for an unattended reboot. The reboot is
11349 * required to be done shortly after the API is invoked.
11350 */
11351 @Override
11352 @TelephonyManager.PrepareUnattendedRebootResult
11353 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011355 enforceRebootPermission();
11356
11357 final long identity = Binder.clearCallingIdentity();
11358 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011359 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011360 } finally {
11361 Binder.restoreCallingIdentity(identity);
11362 }
11363 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011364
11365 /**
11366 * Request to get the current slicing configuration including URSP rules and
11367 * NSSAIs (configured, allowed and rejected).
11368 *
11369 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11370 */
11371 @Override
11372 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011373 TelephonyPermissions
11374 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11375 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011376
11377 final long identity = Binder.clearCallingIdentity();
11378 try {
11379 Phone phone = getDefaultPhone();
11380 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11381 } finally {
11382 Binder.restoreCallingIdentity(identity);
11383 }
11384 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011385
11386 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011387 * Check whether the given premium capability is available for purchase from the carrier.
11388 *
11389 * @param capability The premium capability to check.
11390 * @param subId The subId to check the premium capability for.
11391 *
11392 * @return Whether the given premium capability is available to purchase.
11393 */
11394 @Override
11395 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11396 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11397 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11398 log("Premium capability "
11399 + TelephonyManager.convertPremiumCapabilityToString(capability)
11400 + " is not available for purchase due to missing permissions.");
11401 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11402 + "permission READ_BASIC_PHONE_STATE.");
11403 }
11404
11405 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011406 if (phone == null) {
11407 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11408 return false;
11409 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011410 final long identity = Binder.clearCallingIdentity();
11411 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011412 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011413 .isPremiumCapabilityAvailableForPurchase(capability);
11414 } finally {
11415 Binder.restoreCallingIdentity(identity);
11416 }
11417 }
11418
11419 /**
11420 * Purchase the given premium capability from the carrier.
11421 *
11422 * @param capability The premium capability to purchase.
11423 * @param callback The result of the purchase request.
11424 * @param subId The subId to purchase the premium capability for.
11425 */
11426 @Override
11427 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11428 log("purchasePremiumCapability: capability="
11429 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11430 + getCurrentPackageName());
11431
11432 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11433 mApp, "purchasePremiumCapability")) {
11434 log("purchasePremiumCapability "
11435 + TelephonyManager.convertPremiumCapabilityToString(capability)
11436 + " failed due to missing permissions.");
11437 throw new SecurityException("purchasePremiumCapability requires permission "
11438 + "READ_BASIC_PHONE_STATE.");
11439 }
11440
11441 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011442 if (phone == null) {
11443 try {
11444 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11445 callback.accept(result);
11446 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11447 } catch (RemoteException e) {
11448 String logStr = "Purchase premium capability "
11449 + TelephonyManager.convertPremiumCapabilityToString(capability)
11450 + " failed due to RemoteException handling null phone: " + e;
11451 if (DBG) log(logStr);
11452 AnomalyReporter.reportAnomaly(
11453 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11454 }
11455 return;
11456 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011457 String appName;
11458 try {
11459 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11460 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11461 } catch (PackageManager.NameNotFoundException e) {
11462 appName = "An application";
11463 }
11464 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11465 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011466 }
11467
11468 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011469 * Register an IMS connection state callback
11470 */
11471 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011472 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11473 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011474 if (feature == ImsFeature.FEATURE_MMTEL) {
11475 // ImsMmTelManager
11476 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11477 TelephonyPermissions
11478 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11479 mApp, subId, "registerImsStateCallback");
11480 } else if (feature == ImsFeature.FEATURE_RCS) {
11481 // ImsRcsManager or SipDelegateManager
11482 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11483 Binder.getCallingUid(), "registerImsStateCallback",
11484 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11485 Manifest.permission.READ_PRECISE_PHONE_STATE,
11486 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11487 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11488 }
11489
11490 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11491 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11492 "IMS not available on device.");
11493 }
11494
11495 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11496 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11497 }
11498
11499 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11500 if (controller == null) {
11501 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11502 "IMS not available on device.");
11503 }
11504
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011505 if (callingPackage == null) {
11506 callingPackage = getCurrentPackageName();
11507 }
11508
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011509 final long token = Binder.clearCallingIdentity();
11510 try {
11511 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011512 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011513 } catch (ImsException e) {
11514 throw new ServiceSpecificException(e.getCode());
11515 } finally {
11516 Binder.restoreCallingIdentity(token);
11517 }
11518 }
11519
11520 /**
11521 * Unregister an IMS connection state callback
11522 */
11523 @Override
11524 public void unregisterImsStateCallback(IImsStateCallback cb) {
11525 final long token = Binder.clearCallingIdentity();
11526 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11527 if (controller == null) {
11528 return;
11529 }
11530 try {
11531 controller.unregisterImsStateCallback(cb);
11532 } finally {
11533 Binder.restoreCallingIdentity(token);
11534 }
11535 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011536
11537 /**
11538 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11539 *
11540 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11541 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11542 * SecurityException.
11543 * If there is current registered network this value will be same as the registered cell
11544 * identity. If the device goes out of service the previous cell identity is cached and
11545 * will be returned. If the cache age of the Cell identity is more than 24 hours
11546 * it will be cleared and null will be returned.
11547 *
11548 */
11549 @Override
11550 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11551 String callingFeatureId) {
11552 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11553 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11554 LocationAccessPolicy.checkLocationPermission(mApp,
11555 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11556 .setCallingPackage(callingPackage)
11557 .setCallingFeatureId(callingFeatureId)
11558 .setCallingPid(Binder.getCallingPid())
11559 .setCallingUid(Binder.getCallingUid())
11560 .setMethod("getLastKnownCellIdentity")
11561 .setLogAsInfo(true)
11562 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11563 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11564 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11565 .build());
11566
11567 boolean hasFinePermission =
11568 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11569 if (!hasFinePermission
11570 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11571 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011572 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011573 }
11574
11575 final long identity = Binder.clearCallingIdentity();
11576 try {
11577 Phone phone = getPhone(subId);
11578 if (phone == null) return null;
11579 ServiceStateTracker sst = phone.getServiceStateTracker();
11580 if (sst == null) return null;
11581 return sst.getLastKnownCellIdentity();
11582 } finally {
11583 Binder.restoreCallingIdentity(identity);
11584 }
11585 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011586
jimsun3b9ccac2021-10-26 15:01:23 +080011587 /**
11588 * Sets the modem service class Name that Telephony will bind to.
11589 *
11590 * @param serviceName The class name of the modem service.
11591 * @return true if the operation is succeed, otherwise false.
11592 */
11593 public boolean setModemService(String serviceName) {
11594 Log.d(LOG_TAG, "setModemService - " + serviceName);
11595 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11597 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11598 "setModemService");
11599 return mPhoneConfigurationManager.setModemService(serviceName);
11600 }
11601
11602 /**
11603 * Return the class name of the currently bounded modem service.
11604 *
11605 * @return the class name of the modem service.
11606 */
11607 public String getModemService() {
11608 String result;
11609 Log.d(LOG_TAG, "getModemService");
11610 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11611 TelephonyPermissions
11612 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11613 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11614 "getModemService");
11615 result = mPhoneConfigurationManager.getModemService();
11616 Log.d(LOG_TAG, "result = " + result);
11617 return result;
11618 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011619
11620 @Override
11621 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11622 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11623 mApp.enforceCallingOrSelfPermission(
11624 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11626
11627 final long identity = Binder.clearCallingIdentity();
11628 try {
11629 Phone phone = getPhone(subId);
11630 if (phone == null) return;
11631 phone.setVoiceServiceStateOverride(hasService);
11632 } finally {
11633 Binder.restoreCallingIdentity(identity);
11634 }
11635 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011636
11637 /**
11638 * set removable eSIM as default eUICC.
11639 *
11640 * @hide
11641 */
11642 @Override
11643 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11644 enforceModifyPermission();
11645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11646
11647 final long identity = Binder.clearCallingIdentity();
11648 try {
11649 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11650 } finally {
11651 Binder.restoreCallingIdentity(identity);
11652 }
11653 }
11654
11655 /**
11656 * Returns whether the removable eSIM is default eUICC or not.
11657 *
11658 * @hide
11659 */
11660 @Override
11661 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11662 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11664
11665 final long identity = Binder.clearCallingIdentity();
11666 try {
11667 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11668 } finally {
11669 Binder.restoreCallingIdentity(identity);
11670 }
11671 }
11672
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011673 /**
11674 * Get the component name of the default app to direct respond-via-message intent for the
11675 * user associated with this subscription, update the cache if there is no respond-via-message
11676 * application currently configured for this user.
11677 * @return component name of the app and class to direct Respond Via Message intent to, or
11678 * {@code null} if the functionality is not supported.
11679 * @hide
11680 */
11681 @Override
11682 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11683 boolean updateIfNeeded) {
11684 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011685
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011686 Context context = getPhone(subId).getContext();
11687 UserHandle userHandle = null;
11688 final long identity = Binder.clearCallingIdentity();
11689 try {
11690 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11691 } finally {
11692 Binder.restoreCallingIdentity(identity);
11693 }
11694 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11695 updateIfNeeded, userHandle);
11696 }
Jack Yuf5badd92022-12-08 00:50:53 -080011697
11698 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011699 * Set whether the device is able to connect with null ciphering or integrity
11700 * algorithms. This is a global setting and will apply to all active subscriptions
11701 * and all new subscriptions after this.
11702 *
11703 * @param enabled when true, null cipher and integrity algorithms are allowed.
11704 * @hide
11705 */
11706 @Override
11707 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11708 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11709 enforceModifyPermission();
11710 checkForNullCipherAndIntegritySupport();
11711
11712 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11713 // for listening to these preference changes and applying them immediately.
11714 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11715 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11716 editor.apply();
11717
11718 for (Phone phone: PhoneFactory.getPhones()) {
11719 phone.handleNullCipherEnabledChange();
11720 }
11721 }
11722
11723
11724 /**
11725 * Get whether the device is able to connect with null ciphering or integrity
11726 * algorithms. Note that this retrieves the phone-global preference and not
11727 * the state of the radio.
11728 *
11729 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11730 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11731 * version for this feature.
11732 * @hide
11733 */
11734 @Override
11735 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11736 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11737 enforceReadPermission();
11738 checkForNullCipherAndIntegritySupport();
11739 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11740 }
11741
11742 private void checkForNullCipherAndIntegritySupport() {
11743 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11744 throw new UnsupportedOperationException(
11745 "Null cipher and integrity operations require HAL 2.1 or above");
11746 }
11747 }
11748
11749 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011750 * Get the SIM state for the slot index.
11751 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11752 *
11753 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11754 */
11755 @Override
11756 @SimState
11757 public int getSimStateForSlotIndex(int slotIndex) {
11758 IccCardConstants.State simState;
11759 if (slotIndex < 0) {
11760 simState = IccCardConstants.State.UNKNOWN;
11761 } else {
11762 Phone phone = null;
11763 try {
11764 phone = PhoneFactory.getPhone(slotIndex);
11765 } catch (IllegalStateException e) {
11766 // ignore
11767 }
11768 if (phone == null) {
11769 simState = IccCardConstants.State.UNKNOWN;
11770 } else {
11771 IccCard icc = phone.getIccCard();
11772 if (icc == null) {
11773 simState = IccCardConstants.State.UNKNOWN;
11774 } else {
11775 simState = icc.getState();
11776 }
11777 }
11778 }
11779 return simState.ordinal();
11780 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011781
11782 /**
11783 * Get current cell broadcast ranges.
11784 */
11785 @Override
11786 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11787 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11788 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11789 "getCellBroadcastIdRanges");
11790 final long identity = Binder.clearCallingIdentity();
11791 try {
11792 return getPhone(subId).getCellBroadcastIdRanges();
11793 } finally {
11794 Binder.restoreCallingIdentity(identity);
11795 }
11796 }
11797
11798 /**
11799 * Set reception of cell broadcast messages with the list of the given ranges
11800 *
11801 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11802 */
11803 @Override
11804 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11805 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11806 @Nullable IIntegerConsumer callback) {
11807 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11808 "setCellBroadcastIdRanges");
11809 final long identity = Binder.clearCallingIdentity();
11810 try {
11811 Phone phone = getPhoneFromSubId(subId);
11812 if (DBG) {
11813 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11814 }
11815 phone.setCellBroadcastIdRanges(ranges, result -> {
11816 if (callback != null) {
11817 try {
11818 callback.accept(result);
11819 } catch (RemoteException e) {
11820 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
11821 }
11822 }
11823 });
11824 } finally {
11825 Binder.restoreCallingIdentity(identity);
11826 }
11827 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000011828
11829 /**
11830 * Returns whether the device supports the domain selection service.
11831 *
11832 * @return {@code true} if the device supports the domain selection service.
11833 */
11834 @Override
11835 public boolean isDomainSelectionSupported() {
11836 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11837 "isDomainSelectionSupported");
11838
11839 final long identity = Binder.clearCallingIdentity();
11840 try {
11841 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
11842 } finally {
11843 Binder.restoreCallingIdentity(identity);
11844 }
11845 }
arunvoddud5c6ce02022-12-11 06:03:12 +000011846
11847 /**
11848 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
11849 *
11850 * <p>This method behaves in one of the following ways:
11851 * <ul>
11852 * <li>return true : if the calling package has the appop permission {@link
11853 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
11854 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
11855 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
11856 * Owner device identifier access check, or the calling package has carrier privileges</>
11857 * <li>throw SecurityException: if the caller does not meet any of the requirements.
11858 * </ul>
11859 */
11860 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
11861 String callingPackage, @Nullable String callingFeatureId, String message) {
11862 for (Phone phone : PhoneFactory.getPhones()) {
11863 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
11864 phone.getSubId(), callingPackage, callingFeatureId, message)) {
11865 return true;
11866 }
11867 }
11868 return false;
11869 }
11870}