blob: 7bc563260cce63b4c77284efb825623f13969ccc [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;
Aishwarya Mallampati32336e82023-01-04 23:02:56 +0000397 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();
Aishwarya Mallampati32336e82023-01-04 23:02:56 +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
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002432 /**
2433 * Get the default phone for this device.
2434 */
2435 @VisibleForTesting
2436 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002437 Phone thePhone = getPhone(getDefaultSubscription());
2438 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2439 }
2440
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 private void publish() {
2442 if (DBG) log("publish: " + this);
2443
Peter Wangc035ce42020-01-08 21:00:22 -08002444 TelephonyFrameworkInitializer
2445 .getTelephonyServiceManager()
2446 .getTelephonyServiceRegisterer()
2447 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Stuart Scott584921c2015-01-15 17:10:34 -08002450 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002451 if (request.phone != null) {
2452 return request.phone;
2453 } else {
2454 return getPhoneFromSubId(request.subId);
2455 }
2456 }
2457
2458 private Phone getPhoneFromSubId(int subId) {
2459 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2460 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002461 }
2462
Rambo Wange53e07d2022-05-10 13:01:13 -07002463 @Nullable
2464 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002465 Phone phone = getPhoneFromRequest(request);
2466 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002467 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002468 }
2469
Wink Saville36469e72014-06-11 15:17:00 -07002470 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002471 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002472 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474
Kai Shif70f46f2021-03-03 13:59:46 -08002475 private void sendEraseModemConfig(@NonNull Phone phone) {
2476 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2477 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2478 }
2479
2480 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2481 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2482 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002483 }
2484
Peter Wang44b186e2020-01-13 23:33:09 -08002485 private boolean isImsAvailableOnDevice() {
2486 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2487 if (pm == null) {
2488 // For some reason package manger is not available.. This will fail internally anyway,
2489 // so do not throw error and allow.
2490 return true;
2491 }
2492 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2493 }
2494
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 if (DBG) log("dial: " + number);
2501 // No permission check needed here: This is just a wrapper around the
2502 // ACTION_DIAL intent, which is available to any app since it puts up
2503 // the UI before it does anything.
2504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 String url = createTelUrl(number);
2508 if (url == null) {
2509 return;
2510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 // PENDING: should we just silently fail if phone is offhook or ringing?
2513 PhoneConstants.State state = mCM.getState(subId);
2514 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2515 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2516 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2517 mApp.startActivity(intent);
2518 }
2519 } finally {
2520 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 }
2522 }
2523
2524 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002525 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Wink Savilleb564aae2014-10-23 10:18:09 -07002528 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 if (DBG) log("call: " + number);
2530
2531 // This is just a wrapper around the ACTION_CALL intent, but we still
2532 // need to do a permission check since we're calling startActivity()
2533 // from the context of the phone app.
2534 enforceCallPermission();
2535
Jordan Liu1617b712019-07-10 15:06:26 -07002536 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 != AppOpsManager.MODE_ALLOWED) {
2538 return;
2539 }
2540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 String url = createTelUrl(number);
2544 if (url == null) {
2545 return;
2546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 boolean isValid = false;
2549 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2550 if (slist != null) {
2551 for (SubscriptionInfo subInfoRecord : slist) {
2552 if (subInfoRecord.getSubscriptionId() == subId) {
2553 isValid = true;
2554 break;
2555 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002556 }
Wink Saville08874612014-08-31 19:19:58 -07002557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 if (!isValid) {
2559 return;
2560 }
Wink Saville08874612014-08-31 19:19:58 -07002561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2563 intent.putExtra(SUBSCRIPTION_KEY, subId);
2564 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2565 mApp.startActivity(intent);
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 }
2570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002572 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002573 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2574 }
2575
Wink Savilleb564aae2014-10-23 10:18:09 -07002576 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002577 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002578 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2579 }
2580
Wink Savilleb564aae2014-10-23 10:18:09 -07002581 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002586 Phone phone = getPhone(subId);
2587 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 checkSimPin.start();
2589 return checkSimPin.unlockSim(null, pin);
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
2592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 }
2594
Wink Savilleb564aae2014-10-23 10:18:09 -07002595 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002600 Phone phone = getPhone(subId);
2601 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 checkSimPuk.start();
2603 return checkSimPuk.unlockSim(puk, pin);
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
2606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 }
2608
2609 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002610 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 * a synchronous one.
2612 */
2613 private static class UnlockSim extends Thread {
2614
2615 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002616 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617
2618 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002619 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2620 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621
2622 // For replies from SimCard interface
2623 private Handler mHandler;
2624
2625 // For async handler to identify request type
2626 private static final int SUPPLY_PIN_COMPLETE = 100;
2627
Michele Berionne5e411512020-11-13 02:36:59 +00002628 UnlockSim(int phoneId, IccCard simCard) {
2629 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 mSimCard = simCard;
2631 }
2632
2633 @Override
2634 public void run() {
2635 Looper.prepare();
2636 synchronized (UnlockSim.this) {
2637 mHandler = new Handler() {
2638 @Override
2639 public void handleMessage(Message msg) {
2640 AsyncResult ar = (AsyncResult) msg.obj;
2641 switch (msg.what) {
2642 case SUPPLY_PIN_COMPLETE:
2643 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2644 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002645 mRetryCount = msg.arg1;
2646 if (ar.exception != null) {
2647 if (ar.exception instanceof CommandException &&
2648 ((CommandException)(ar.exception)).getCommandError()
2649 == CommandException.Error.PASSWORD_INCORRECT) {
2650 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002651 } //When UiccCardApp dispose,handle message and return exception
2652 else if (ar.exception instanceof CommandException &&
2653 ((CommandException) (ar.exception)).getCommandError()
2654 == CommandException.Error.ABORTED) {
2655 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002656 } else {
2657 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2658 }
2659 } else {
2660 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 mDone = true;
2663 UnlockSim.this.notifyAll();
2664 }
2665 break;
2666 }
2667 }
2668 };
2669 UnlockSim.this.notifyAll();
2670 }
2671 Looper.loop();
2672 }
2673
2674 /*
2675 * Use PIN or PUK to unlock SIM card
2676 *
2677 * If PUK is null, unlock SIM card with PIN
2678 *
2679 * If PUK is not null, unlock SIM card with PUK and set PIN code
2680 */
Wink Saville9de0f752013-10-22 19:04:03 -07002681 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682
2683 while (mHandler == null) {
2684 try {
2685 wait();
2686 } catch (InterruptedException e) {
2687 Thread.currentThread().interrupt();
2688 }
2689 }
2690 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2691
2692 if (puk == null) {
2693 mSimCard.supplyPin(pin, callback);
2694 } else {
2695 mSimCard.supplyPuk(puk, pin, callback);
2696 }
2697
2698 while (!mDone) {
2699 try {
2700 Log.d(LOG_TAG, "wait for done");
2701 wait();
2702 } catch (InterruptedException e) {
2703 // Restore the interrupted status
2704 Thread.currentThread().interrupt();
2705 }
2706 }
2707 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002708 int[] resultArray = new int[2];
2709 resultArray[0] = mResult;
2710 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002711
2712 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002713 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002714 }
2715
Wink Saville9de0f752013-10-22 19:04:03 -07002716 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
2718 }
2719
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002720 /**
2721 * This method has been removed due to privacy and stability concerns.
2722 */
2723 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002725 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2726 return;
Wink Saville36469e72014-06-11 15:17:00 -07002727 }
2728
Nathan Harold1f889d82020-06-04 17:05:26 -07002729 @Override
2730 public void updateServiceLocationWithPackageName(String callingPackage) {
2731 mApp.getSystemService(AppOpsManager.class)
2732 .checkPackage(Binder.getCallingUid(), callingPackage);
2733
Nathan Haroldf096d982020-11-18 17:18:06 -08002734 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002735 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2736 // Callers targeting S have no business invoking this method.
2737 return;
2738 }
2739
2740 LocationAccessPolicy.LocationPermissionResult locationResult =
2741 LocationAccessPolicy.checkLocationPermission(mApp,
2742 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2743 .setCallingPackage(callingPackage)
2744 .setCallingFeatureId(null)
2745 .setCallingPid(Binder.getCallingPid())
2746 .setCallingUid(Binder.getCallingUid())
2747 .setMethod("updateServiceLocation")
2748 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2749 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2750 .build());
2751 // Apps that lack location permission have no business calling this method;
2752 // however, because no permission was declared in the public API, denials must
2753 // all be "soft".
2754 switch (locationResult) {
2755 case DENIED_HARD: /* fall through */
2756 case DENIED_SOFT:
2757 return;
2758 }
2759
2760 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761 final long identity = Binder.clearCallingIdentity();
2762 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002763 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002765 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 }
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002772 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002773 @Override
2774 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002775 return isRadioOnWithFeature(callingPackage, null);
2776 }
2777
2778
2779 @Override
2780 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2781 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2782 callingFeatureId);
2783 }
2784
2785 @Deprecated
2786 @Override
2787 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2788 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002792 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002795 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002796 return false;
2797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 return isRadioOnForSubscriber(subId);
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002805 }
2806
2807 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 final Phone phone = getPhone(subId);
2811 if (phone != null) {
2812 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2813 } else {
2814 return false;
2815 }
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
2821 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002822 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 }
Wink Saville36469e72014-06-11 15:17:00 -07002824
Wink Savilleb564aae2014-10-23 10:18:09 -07002825 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
2828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 final Phone phone = getPhone(subId);
2831 if (phone != null) {
2832 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2833 }
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 }
Wink Saville36469e72014-06-11 15:17:00 -07002837 }
2838
2839 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002840 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002841 }
2842
Wink Savilleb564aae2014-10-23 10:18:09 -07002843 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 final Phone phone = getPhone(subId);
2849 if (phone == null) {
2850 return false;
2851 }
2852 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2853 toggleRadioOnOffForSubscriber(subId);
2854 }
2855 return true;
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
Wink Saville36469e72014-06-11 15:17:00 -07002860
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002861 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002862 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002863 /*
2864 * If any of the Radios are available, it will need to be
2865 * shutdown. So return true if any Radio is available.
2866 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2870 Phone phone = PhoneFactory.getPhone(i);
2871 if (phone != null && phone.isRadioAvailable()) return true;
2872 }
2873 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2874 return false;
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002877 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002878 }
2879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002881 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 enforceModifyPermission();
2883
2884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2887 logv("Shutting down Phone " + i);
2888 shutdownRadioUsingPhoneId(i);
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002892 }
2893 }
2894
2895 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002896 Phone phone = PhoneFactory.getPhone(phoneId);
2897 if (phone != null && phone.isRadioAvailable()) {
2898 phone.shutdownRadio();
2899 }
2900 }
2901
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002903 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2908 if (defaultPhone != null) {
2909 defaultPhone.setRadioPower(turnOn);
2910 return true;
2911 } else {
2912 loge("There's no default phone.");
2913 return false;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002917 }
Wink Saville36469e72014-06-11 15:17:00 -07002918 }
2919
Wink Savilleb564aae2014-10-23 10:18:09 -07002920 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 final Phone phone = getPhone(subId);
2926 if (phone != null) {
2927 phone.setRadioPower(turnOn);
2928 return true;
2929 } else {
2930 return false;
2931 }
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002934 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 }
2936
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002937 /**
2938 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2939 * no reason to power it off. When any of the voters want to power it off, it will be turned
2940 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2941 * powering it off, and these radio off votes will be cleared.
2942 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2943 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2944 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2945 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2946 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2947 * check its vote.
2948 *
2949 * @param subId The subscription ID.
2950 * @param reason The reason for powering off radio.
2951 * @return true on success and false on failure.
2952 */
2953 public boolean requestRadioPowerOffForReason(int subId,
2954 @TelephonyManager.RadioPowerReason int reason) {
2955 enforceModifyPermission();
2956
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 final Phone phone = getPhone(subId);
2960 if (phone != null) {
2961 phone.setRadioPowerForReason(false, reason);
2962 return true;
2963 } else {
2964 return false;
2965 }
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 /**
2972 * Remove the vote on powering off the radio for a reason, as requested by
2973 * {@link requestRadioPowerOffForReason}.
2974 *
2975 * @param subId The subscription ID.
2976 * @param reason The reason for powering off radio.
2977 * @return true on success and false on failure.
2978 */
2979 public boolean clearRadioPowerOffForReason(int subId,
2980 @TelephonyManager.RadioPowerReason int reason) {
2981 enforceModifyPermission();
2982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 final Phone phone = getPhone(subId);
2986 if (phone != null) {
2987 phone.setRadioPowerForReason(true, reason);
2988 return true;
2989 } else {
2990 return false;
2991 }
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 /**
2998 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2999 *
3000 * @param subId The subscription ID.
3001 * @param callingPackage The package making the call.
3002 * @param callingFeatureId The feature in the package.
3003 * @return List of reasons for powering off radio.
3004 */
3005 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3006 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3007
3008 final long identity = Binder.clearCallingIdentity();
3009 List result = new ArrayList();
3010 try {
3011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3012 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3013 return result;
3014 }
3015
3016 final Phone phone = getPhone(subId);
3017 if (phone != null) {
3018 result.addAll(phone.getRadioPowerOffReasons());
3019 }
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
3023 return result;
3024 }
3025
Wink Saville36469e72014-06-11 15:17:00 -07003026 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003028 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
Jack Yu285100e2022-12-02 22:48:35 -08003033 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 final Phone phone = getPhone(subId);
3035 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003036 phone.getDataSettingsManager().setDataEnabled(
3037 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 return true;
3039 } else {
3040 return false;
3041 }
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003045 }
3046
Wink Saville36469e72014-06-11 15:17:00 -07003047 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003048 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003049 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
Jack Yu285100e2022-12-02 22:48:35 -08003054 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 final Phone phone = getPhone(subId);
3056 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003057 phone.getDataSettingsManager().setDataEnabled(
3058 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 return true;
3060 } else {
3061 return false;
3062 }
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 }
3067
Sanket Padawe356d7632015-06-22 14:03:32 -07003068 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003069 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 final Phone phone = getPhone(subId);
3073 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003074 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075 } else {
3076 return false;
3077 }
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 }
3082
3083 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003084 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003085 }
3086
pkanwarae03a6b2016-11-06 20:37:09 -08003087 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088 enforceCallPermission();
3089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3093 return;
3094 }
3095 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3096 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
pkanwar32d516d2016-10-14 19:37:38 -07003100 };
3101
Wink Savilleb564aae2014-10-23 10:18:09 -07003102 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104
3105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3108 return false;
3109 }
3110 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 }
3115
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003116 /**
3117 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3118 * tag on getCallState Binder call.
3119 */
3120 @Deprecated
3121 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003123 if (CompatChanges.isChangeEnabled(
3124 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3125 Binder.getCallingUid())) {
3126 // Do not allow this API to be called on API version 31+, it should only be
3127 // called on old apps using this Binder call directly.
3128 throw new SecurityException("This method can only be used for applications "
3129 + "targeting API version 30 or less.");
3130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 final long identity = Binder.clearCallingIdentity();
3132 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003133 Phone phone = getPhone(getDefaultSubscription());
3134 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3135 PhoneConstantConversions.convertCallState(phone.getState());
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
3139 }
3140
3141 @Override
3142 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3143 if (CompatChanges.isChangeEnabled(
3144 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3145 Binder.getCallingUid())) {
3146 // Check READ_PHONE_STATE for API version 31+
3147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3148 featureId, "getCallStateForSubscription")) {
3149 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3150 + "targeting API level 31+.");
3151 }
3152 }
3153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3157 PhoneConstantConversions.convertCallState(phone.getState());
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 }
3162
Sanket Padawe356d7632015-06-22 14:03:32 -07003163 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003164 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003165 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003166 }
3167
3168 @Override
3169 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003172 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003174 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 } else {
3176 return PhoneConstantConversions.convertDataState(
3177 PhoneConstants.DataState.DISCONNECTED);
3178 }
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 }
3183
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003185 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003186 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003187 }
3188
3189 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003190 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191 final long identity = Binder.clearCallingIdentity();
3192 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003193 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003195 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 } else {
3197 return TelephonyManager.DATA_ACTIVITY_NONE;
3198 }
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 }
3203
3204 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003205 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003206 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003207 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003208
3209 LocationAccessPolicy.LocationPermissionResult locationResult =
3210 LocationAccessPolicy.checkLocationPermission(mApp,
3211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3212 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003213 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003214 .setCallingPid(Binder.getCallingPid())
3215 .setCallingUid(Binder.getCallingUid())
3216 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003217 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003218 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3219 .build());
3220 switch (locationResult) {
3221 case DENIED_HARD:
3222 throw new SecurityException("Not allowed to access cell location");
3223 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003224 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3225 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003226 }
3227
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003228 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003232 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003233 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Svetoslav64fad262015-04-14 14:35:21 -07003237 }
3238
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003240 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003241 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3242 // registered cell info, so return a NULL country instead.
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003245 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3246 // Get default phone in this case.
3247 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3248 }
Jack Yu285100e2022-12-02 22:48:35 -08003249 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003251 if (phone == null) return "";
3252 ServiceStateTracker sst = phone.getServiceStateTracker();
3253 if (sst == null) return "";
3254 LocaleTracker lt = sst.getLocaleTracker();
3255 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003256 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003257 } finally {
3258 Binder.restoreCallingIdentity(identity);
3259 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003260 }
3261
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003262 /**
3263 * This method was removed due to potential issues caused by performing partial
3264 * updates of service state, and lack of a credible use case.
3265 *
3266 * This has the ability to break the telephony implementation by disabling notification of
3267 * changes in device connectivity. DO NOT USE THIS!
3268 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003269 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 public void enableLocationUpdates() {
3271 mApp.enforceCallingOrSelfPermission(
3272 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003273 }
3274
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003275 /**
3276 * This method was removed due to potential issues caused by performing partial
3277 * updates of service state, and lack of a credible use case.
3278 *
3279 * This has the ability to break the telephony implementation by disabling notification of
3280 * changes in device connectivity. DO NOT USE THIS!
3281 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 @Override
3283 public void disableLocationUpdates() {
3284 mApp.enforceCallingOrSelfPermission(
3285 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 }
3287
3288 @Override
3289 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003290 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3291 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003292 try {
3293 mApp.getSystemService(AppOpsManager.class)
3294 .checkPackage(Binder.getCallingUid(), callingPackage);
3295 } catch (SecurityException e) {
3296 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3297 throw e;
3298 }
3299
Nathan Haroldf096d982020-11-18 17:18:06 -08003300 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003301 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3302 throw new SecurityException(
3303 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3304 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003305
Jordan Liu1617b712019-07-10 15:06:26 -07003306 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3308 return null;
3309 }
Svetoslav64fad262015-04-14 14:35:21 -07003310
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003311 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003313 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003314 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315
Nathan Haroldf180aac2018-06-01 18:43:55 -07003316 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3317 for (CellInfo ci : info) {
3318 if (ci instanceof CellInfoGsm) {
3319 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3320 } else if (ci instanceof CellInfoWcdma) {
3321 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003324 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003325 }
3326
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003327 private List<CellInfo> getCachedCellInfo() {
3328 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3329 for (Phone phone : PhoneFactory.getPhones()) {
3330 List<CellInfo> info = phone.getAllCellInfo();
3331 if (info != null) cellInfos.addAll(info);
3332 }
3333 return cellInfos;
3334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003335
3336 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003337 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003338 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003339 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003340
3341 LocationAccessPolicy.LocationPermissionResult locationResult =
3342 LocationAccessPolicy.checkLocationPermission(mApp,
3343 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3344 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003345 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003346 .setCallingPid(Binder.getCallingPid())
3347 .setCallingUid(Binder.getCallingUid())
3348 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003349 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003350 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3351 .build());
3352 switch (locationResult) {
3353 case DENIED_HARD:
3354 throw new SecurityException("Not allowed to access cell info");
3355 case DENIED_SOFT:
3356 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003357 }
3358
Nathan Haroldf096d982020-11-18 17:18:06 -08003359 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003360 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3361 return getCachedCellInfo();
3362 }
3363
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003364 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003365 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003366 final long identity = Binder.clearCallingIdentity();
3367 try {
3368 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3369 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003370 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003371 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372 if (info != null) cellInfos.addAll(info);
3373 }
3374 return cellInfos;
3375 } finally {
3376 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003377 }
3378 }
3379
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003380 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003381 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3382 String callingFeatureId) {
3383 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3384 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003385 }
3386
3387 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003388 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3389 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003390 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003391 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003392 }
3393
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003394 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3395 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003397 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003398
3399 LocationAccessPolicy.LocationPermissionResult locationResult =
3400 LocationAccessPolicy.checkLocationPermission(mApp,
3401 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3402 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003403 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003404 .setCallingPid(Binder.getCallingPid())
3405 .setCallingUid(Binder.getCallingUid())
3406 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003407 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3408 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003409 .build());
3410 switch (locationResult) {
3411 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003412 if (TelephonyPermissions
3413 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003414 // Safetynet logging for b/154934934
3415 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3416 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003417 throw new SecurityException("Not allowed to access cell info");
3418 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003419 if (TelephonyPermissions
3420 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003421 // Safetynet logging for b/154934934
3422 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3423 }
Nathan Harold5320c422019-05-09 10:26:08 -07003424 try {
3425 cb.onCellInfo(new ArrayList<CellInfo>());
3426 } catch (RemoteException re) {
3427 // Drop without consequences
3428 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003429 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003430 }
3431
Nathan Harolda939a962019-05-09 10:13:47 -07003432
3433 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003434 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3435
3436 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3437 }
3438
3439 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003440 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003441 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003446 Phone phone = getPhone(subId);
3447 if (phone == null) {
3448 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3449 } else {
3450 phone.setCellInfoListRate(rateInMillis, workSource);
3451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456
Shishir Agrawala9f32182016-04-12 12:00:16 -07003457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003458 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003459 Phone phone = PhoneFactory.getPhone(slotIndex);
3460 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003461 return null;
3462 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003463 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003464 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003465 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003466 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003467 return null;
3468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 return phone.getImei();
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
3475 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003476 }
3477
3478 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003479 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3480 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3481 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3482 callingFeatureId, "getPrimaryImei")) {
3483 throw new SecurityException("Caller does not have permission");
3484 }
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 for (Phone phone : PhoneFactory.getPhones()) {
3488 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3489 return phone.getImei();
3490 }
3491 }
3492 throw new UnsupportedOperationException("Operation not supported");
3493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
3498 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003499 public String getTypeAllocationCodeForSlot(int slotIndex) {
3500 Phone phone = PhoneFactory.getPhone(slotIndex);
3501 String tac = null;
3502 if (phone != null) {
3503 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003504 try {
3505 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3506 } catch (IndexOutOfBoundsException e) {
3507 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3508 return null;
3509 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003510 }
3511 return tac;
3512 }
3513
3514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003516 try {
3517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3518 } catch (SecurityException se) {
3519 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3520 throw new SecurityException("Package " + callingPackage + " does not belong to "
3521 + Binder.getCallingUid());
3522 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003523 Phone phone = PhoneFactory.getPhone(slotIndex);
3524 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003525 return null;
3526 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003527
Jeff Davidson913390f2018-02-23 17:11:49 -08003528 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003529 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003530 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003531 return null;
3532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 return phone.getMeid();
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
Jack Yu2af8d712017-03-15 17:14:14 -07003540 }
3541
3542 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003543 public String getManufacturerCodeForSlot(int slotIndex) {
3544 Phone phone = PhoneFactory.getPhone(slotIndex);
3545 String manufacturerCode = null;
3546 if (phone != null) {
3547 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003548 try {
3549 manufacturerCode =
3550 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3551 } catch (IndexOutOfBoundsException e) {
3552 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3553 return null;
3554 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003555 }
3556 return manufacturerCode;
3557 }
3558
3559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003560 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3561 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003562 Phone phone = PhoneFactory.getPhone(slotIndex);
3563 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003564 return null;
3565 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003566 int subId = phone.getSubId();
3567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 mApp, subId, callingPackage, callingFeatureId,
3569 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003570 return null;
3571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 return phone.getDeviceSvn();
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003579 }
3580
fionaxu43304da2017-11-27 22:51:16 -08003581 @Override
3582 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 final Phone phone = getPhone(subId);
3586 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
fionaxu43304da2017-11-27 22:51:16 -08003590 }
3591
3592 @Override
3593 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 final Phone phone = getPhone(subId);
3597 return phone == null ? null : phone.getCarrierName();
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
fionaxu43304da2017-11-27 22:51:16 -08003601 }
3602
calvinpanffe225e2018-11-01 19:43:06 +08003603 @Override
chen xu0026ca62019-03-06 15:28:50 -08003604 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 final Phone phone = getPhone(subId);
3608 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003609 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
3613 }
3614
3615 @Override
chen xu0026ca62019-03-06 15:28:50 -08003616 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003620 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003621 } finally {
3622 Binder.restoreCallingIdentity(identity);
3623 }
3624 }
3625
chen xu651eec72018-11-11 19:03:44 -08003626 @Override
chen xu864e11c2018-12-06 22:10:03 -08003627 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3628 if (!isSubscriptionMccMnc) {
3629 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3630 }
chen xu651eec72018-11-11 19:03:44 -08003631 final Phone phone = PhoneFactory.getPhone(slotIndex);
3632 if (phone == null) {
3633 return TelephonyManager.UNKNOWN_CARRIER_ID;
3634 }
3635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
3641 }
3642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 //
3644 // Internal helper methods.
3645 //
3646
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003647 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003648 * Make sure the caller is the calling package itself
3649 *
3650 * @throws SecurityException if the caller is not the calling package
3651 */
3652 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3653 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003654 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3655 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003656 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003657 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003658 } catch (PackageManager.NameNotFoundException e) {
3659 // packageUid is -1
3660 }
3661 if (packageUid != callingUid) {
3662 throw new SecurityException(message + ": Package " + callingPackage
3663 + " does not belong to " + callingUid);
3664 }
3665 }
3666
3667 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003668 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3669 *
3670 * @throws SecurityException if the caller does not have the required permission
3671 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003672 @VisibleForTesting
3673 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003674 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3675 }
3676
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003677 /**
3678 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3679 *
3680 * @throws SecurityException if the caller does not have the required permission
3681 */
3682 @VisibleForTesting
3683 public void enforceReadPermission() {
3684 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
3685 }
3686
Shuo Qian3b6ee772019-11-13 17:43:31 -08003687 private void enforceActiveEmergencySessionPermission() {
3688 mApp.enforceCallingOrSelfPermission(
3689 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3690 }
3691
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003692 /**
3693 * Make sure the caller has the CALL_PHONE permission.
3694 *
3695 * @throws SecurityException if the caller does not have the required permission
3696 */
3697 private void enforceCallPermission() {
3698 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3699 }
3700
paulhu5a773602019-08-23 19:17:33 +08003701 private void enforceSettingsPermission() {
3702 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003703 }
3704
Michele Berionne5e411512020-11-13 02:36:59 +00003705 private void enforceRebootPermission() {
3706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3707 }
3708
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003709 private String createTelUrl(String number) {
3710 if (TextUtils.isEmpty(number)) {
3711 return null;
3712 }
3713
Jake Hambye994d462014-02-03 13:10:13 -08003714 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003715 }
3716
Ihab Awadf9e92732013-12-05 18:02:52 -08003717 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3719 }
3720
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003721 private static void logv(String msg) {
3722 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3723 }
3724
Ihab Awadf9e92732013-12-05 18:02:52 -08003725 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003726 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3727 }
3728
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003730 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003731 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003732 }
3733
Sanket Padawe356d7632015-06-22 14:03:32 -07003734 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003735 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 final Phone phone = PhoneFactory.getPhone(slotIndex);
3739 if (phone == null) {
3740 return PhoneConstants.PHONE_TYPE_NONE;
3741 } else {
3742 return phone.getPhoneType();
3743 }
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003747 }
3748
3749 /**
3750 * Returns the CDMA ERI icon index to display
3751 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003752 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003753 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3754 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3755 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003756 }
3757
Sanket Padawe356d7632015-06-22 14:03:32 -07003758 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003759 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3760 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003762 mApp, subId, callingPackage, callingFeatureId,
3763 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003764 return -1;
3765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766
3767 final long identity = Binder.clearCallingIdentity();
3768 try {
3769 final Phone phone = getPhone(subId);
3770 if (phone != null) {
3771 return phone.getCdmaEriIconIndex();
3772 } else {
3773 return -1;
3774 }
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003778 }
3779
3780 /**
3781 * Returns the CDMA ERI icon mode,
3782 * 0 - ON
3783 * 1 - FLASHING
3784 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003786 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3787 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3788 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003789 }
3790
Sanket Padawe356d7632015-06-22 14:03:32 -07003791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003792 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003795 mApp, subId, callingPackage, callingFeatureId,
3796 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003797 return -1;
3798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 final Phone phone = getPhone(subId);
3803 if (phone != null) {
3804 return phone.getCdmaEriIconMode();
3805 } else {
3806 return -1;
3807 }
3808 } finally {
3809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003811 }
3812
3813 /**
3814 * Returns the CDMA ERI text,
3815 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003816 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003817 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3818 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3819 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003820 }
3821
Sanket Padawe356d7632015-06-22 14:03:32 -07003822 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003823 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3824 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003826 mApp, subId, callingPackage, callingFeatureId,
3827 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003828 return null;
3829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830
3831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 final Phone phone = getPhone(subId);
3834 if (phone != null) {
3835 return phone.getCdmaEriText();
3836 } else {
3837 return null;
3838 }
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003842 }
3843
3844 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003845 * Returns the CDMA MDN.
3846 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003847 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003848 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3850 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003855 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 return phone.getLine1Number();
3857 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003858 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859 return null;
3860 }
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003863 }
3864 }
3865
3866 /**
3867 * Returns the CDMA MIN.
3868 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003869 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003870 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3872 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873
3874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 final Phone phone = getPhone(subId);
3877 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3878 return phone.getCdmaMin();
3879 } else {
3880 return null;
3881 }
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003884 }
3885 }
3886
Hall Liud892bec2018-11-30 14:51:45 -08003887 @Override
3888 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3889 INumberVerificationCallback callback, String callingPackage) {
3890 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3891 != PERMISSION_GRANTED) {
3892 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3893 }
3894 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3895
3896 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3897 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003898 throw new SecurityException("Calling package must be configured in the device config: "
3899 + "calling package: " + callingPackage
3900 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003901 }
3902
3903 if (range == null) {
3904 throw new NullPointerException("Range must be non-null");
3905 }
3906
3907 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003908 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003909
3910 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3911 }
3912
Junda Liuca05d5d2014-08-14 22:36:34 -07003913 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003914 * Returns true if CDMA provisioning needs to run.
3915 */
3916 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 final long identity = Binder.clearCallingIdentity();
3918 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003919 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 } finally {
3921 Binder.restoreCallingIdentity(identity);
3922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003923 }
3924
3925 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003926 * Sets the voice mail number of a given subId.
3927 */
3928 @Override
3929 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003930 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3931 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3936 new Pair<String, String>(alphaTag, number), new Integer(subId));
3937 return success;
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003941 }
3942
Ta-wei Yen87c49842016-05-13 21:19:52 -07003943 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003944 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3945 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003946 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3947 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003948 if (!TextUtils.equals(callingPackage, systemDialer)) {
3949 throw new SecurityException("caller must be system dialer");
3950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3955 if (phoneAccountHandle == null) {
3956 return null;
3957 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003961 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003962 }
3963
3964 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003965 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3966 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003967 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003969 mApp, subId, callingPackage, callingFeatureId,
3970 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003971 return null;
3972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003974 final long identity = Binder.clearCallingIdentity();
3975 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003977 } finally {
3978 Binder.restoreCallingIdentity(identity);
3979 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003980 }
3981
3982 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003983 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3984 VisualVoicemailSmsFilterSettings settings) {
3985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986
3987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003990 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003994 }
3995
3996 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003997 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999
4000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004003 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 } finally {
4005 Binder.restoreCallingIdentity(identity);
4006 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004007 }
4008
4009 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004010 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4011 String callingPackage, int subId) {
4012 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013
4014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004017 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004021 }
4022
4023 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004024 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026
4027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004030 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004034 }
4035
4036 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004037 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4038 String callingAttributionTag, int subId, String number, int port, String text,
4039 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004041 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004042 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004043 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004044 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4045 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004046 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004047
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004048 /**
fionaxu0152e512016-11-14 13:36:14 -08004049 * Sets the voice activation state of a given subId.
4050 */
4051 @Override
4052 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4054 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055
4056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 final Phone phone = getPhone(subId);
4059 if (phone != null) {
4060 phone.setVoiceActivationState(activationState);
4061 } else {
4062 loge("setVoiceActivationState fails with invalid subId: " + subId);
4063 }
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004066 }
4067 }
4068
4069 /**
4070 * Sets the data activation state of a given subId.
4071 */
4072 @Override
4073 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4075 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 final Phone phone = getPhone(subId);
4080 if (phone != null) {
4081 phone.setDataActivationState(activationState);
4082 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004083 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084 }
4085 } finally {
4086 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004087 }
4088 }
4089
4090 /**
4091 * Returns the voice activation state of a given subId.
4092 */
4093 @Override
4094 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096
fionaxu0152e512016-11-14 13:36:14 -08004097 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 if (phone != null) {
4101 return phone.getVoiceActivationState();
4102 } else {
4103 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4104 }
4105 } finally {
4106 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004107 }
4108 }
4109
4110 /**
4111 * Returns the data activation state of a given subId.
4112 */
4113 @Override
4114 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116
fionaxu0152e512016-11-14 13:36:14 -08004117 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 if (phone != null) {
4121 return phone.getDataActivationState();
4122 } else {
4123 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4124 }
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004127 }
4128 }
4129
4130 /**
Wink Saville36469e72014-06-11 15:17:00 -07004131 * Returns the unread count of voicemails for a subId
4132 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004134 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4135 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004137 mApp, subId, callingPackage, callingFeatureId,
4138 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004139 return 0;
4140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 final Phone phone = getPhone(subId);
4144 if (phone != null) {
4145 return phone.getVoiceMessageCount();
4146 } else {
4147 return 0;
4148 }
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004152 }
4153
4154 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004155 * returns true, if the device is in a state where both voice and data
4156 * are supported simultaneously. This can change based on location or network condition.
4157 */
4158 @Override
4159 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 final Phone phone = getPhone(subId);
4163 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004167 }
4168
4169 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004170 * Send the dialer code if called from the current default dialer or the caller has
4171 * carrier privilege.
4172 * @param inputCode The dialer code to send
4173 */
4174 @Override
4175 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004176 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004177 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004178 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4179 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004180 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004181 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004182 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184
4185 final long identity = Binder.clearCallingIdentity();
4186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004187 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
fionaxu235cc5e2017-03-06 22:25:57 -08004191 }
4192
Pengquan Menga1bb6272018-09-06 09:59:22 -07004193 @Override
4194 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004195 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004196 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004197 mApp, subId, "getNetworkSelectionMode");
4198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 if (!isActiveSubscription(subId)) {
4201 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4202 }
4203 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004206 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004207 }
4208
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004210 public boolean isInEmergencySmsMode() {
4211 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 for (Phone phone : PhoneFactory.getPhones()) {
4215 if (phone.isInEmergencySmsMode()) {
4216 return true;
4217 }
4218 }
4219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 return false;
4223 }
4224
shilu366312e2019-12-17 09:28:10 -08004225 /**
4226 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4227 * @param subId The subscription to use to check the configuration.
4228 * @param c The callback that will be used to send the result.
4229 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004230 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004231 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4232 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004233 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004234 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004235
4236 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4237 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4238 "IMS not available on device.");
4239 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 final long token = Binder.clearCallingIdentity();
4241 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004242 int slotId = getSlotIndexOrException(subId);
4243 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004244
4245 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4246 if (controller != null) {
4247 ImsManager imsManager = controller.getImsManager(subId);
4248 if (imsManager != null) {
4249 imsManager.addRegistrationCallbackForSubscription(c, subId);
4250 } else {
4251 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4252 }
4253 } else {
4254 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4255 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004256 } catch (ImsException e) {
4257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 } finally {
4259 Binder.restoreCallingIdentity(token);
4260 }
4261 }
4262
shilu366312e2019-12-17 09:28:10 -08004263 /**
4264 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4265 * @param subId The subscription to use to check the configuration.
4266 * @param c The callback that will be used to send the result.
4267 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004269 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004270 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004271 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004272 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4273 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4274 }
Meng Wangafbc5852019-09-19 17:37:13 -07004275 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004276
Meng Wangafbc5852019-09-19 17:37:13 -07004277 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004278 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4279 if (controller != null) {
4280 ImsManager imsManager = controller.getImsManager(subId);
4281 if (imsManager != null) {
4282 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4283 } else {
4284 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4285 + "is inactive, ignoring unregister.");
4286 // If the ImsManager is not valid, just return, since the callback
4287 // will already have been removed internally.
4288 }
4289 }
Meng Wangafbc5852019-09-19 17:37:13 -07004290 } finally {
4291 Binder.restoreCallingIdentity(token);
4292 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 }
4294
Brad Ebingera34a6c22019-10-22 17:36:18 -07004295 /**
4296 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4297 */
4298 @Override
4299 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4300 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4301 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4302 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4303 "IMS not available on device.");
4304 }
4305 final long token = Binder.clearCallingIdentity();
4306 try {
4307 Phone phone = getPhone(subId);
4308 if (phone == null) {
4309 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4310 + subId + "'");
4311 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4312 }
4313 phone.getImsRegistrationState(regState -> {
4314 try {
4315 consumer.accept((regState == null)
4316 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4317 } catch (RemoteException e) {
4318 // Ignore if the remote process is no longer available to call back.
4319 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4320 }
4321 });
4322 } finally {
4323 Binder.restoreCallingIdentity(token);
4324 }
4325 }
4326
4327 /**
4328 * Get the transport type for the IMS service registration state.
4329 */
4330 @Override
4331 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004332 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004333 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004334 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4336 "IMS not available on device.");
4337 }
4338 final long token = Binder.clearCallingIdentity();
4339 try {
4340 Phone phone = getPhone(subId);
4341 if (phone == null) {
4342 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4343 + subId + "'");
4344 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4345 }
4346 phone.getImsRegistrationTech(regTech -> {
4347 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4348 int regTechConverted = (regTech == null)
4349 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4350 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4351 regTechConverted);
4352 try {
4353 consumer.accept(regTechConverted);
4354 } catch (RemoteException e) {
4355 // Ignore if the remote process is no longer available to call back.
4356 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4357 }
4358 });
4359 } finally {
4360 Binder.restoreCallingIdentity(token);
4361 }
4362 }
4363
shilu366312e2019-12-17 09:28:10 -08004364 /**
4365 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4366 * @param subId The subscription to use to check the configuration.
4367 * @param c The callback that will be used to send the result.
4368 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004370 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4371 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004372 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004373 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004374 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4375 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4376 "IMS not available on device.");
4377 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 final long token = Binder.clearCallingIdentity();
4379 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004380 int slotId = getSlotIndexOrException(subId);
4381 verifyImsMmTelConfiguredOrThrow(slotId);
4382 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004383 } catch (ImsException e) {
4384 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 } finally {
4386 Binder.restoreCallingIdentity(token);
4387 }
4388 }
4389
shilu366312e2019-12-17 09:28:10 -08004390 /**
4391 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4392 * @param subId The subscription to use to check the configuration.
4393 * @param c The callback that will be used to send the result.
4394 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004396 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004397 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004398 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004399 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4400 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4401 }
Meng Wangafbc5852019-09-19 17:37:13 -07004402
4403 final long token = Binder.clearCallingIdentity();
4404 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004405 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004406 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004407 } catch (ImsException e) {
4408 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4409 + "is inactive, ignoring unregister.");
4410 // If the subscription is no longer active, just return, since the callback
4411 // will already have been removed internally.
4412 } finally {
4413 Binder.restoreCallingIdentity(token);
4414 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 }
4416
4417 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004418 public boolean isCapable(int subId, int capability, int regTech) {
4419 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004420 final long token = Binder.clearCallingIdentity();
4421 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004422 int slotId = getSlotIndexOrException(subId);
4423 verifyImsMmTelConfiguredOrThrow(slotId);
4424 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4425 } catch (com.android.ims.ImsException e) {
4426 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4427 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004428 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004429 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4430 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 } finally {
4432 Binder.restoreCallingIdentity(token);
4433 }
4434 }
4435
4436 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004437 public boolean isAvailable(int subId, int capability, int regTech) {
4438 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 final long token = Binder.clearCallingIdentity();
4440 try {
4441 Phone phone = getPhone(subId);
4442 if (phone == null) return false;
4443 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004444 } catch (com.android.ims.ImsException e) {
4445 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4446 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 } finally {
4448 Binder.restoreCallingIdentity(token);
4449 }
4450 }
4451
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004452 /**
4453 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4454 * subscription.
4455 * @param subId The subscription to use to check the configuration.
4456 * @param callback The callback that will be used to send the result.
4457 * @param capability The MmTelFeature capability that will be used to send the result.
4458 * @param transportType The transport type of the MmTelFeature capability.
4459 */
4460 @Override
4461 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4462 int transportType) {
4463 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004464 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4465 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4466 "IMS not available on device.");
4467 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004468 final long token = Binder.clearCallingIdentity();
4469 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004470 int slotId = getSlotIndex(subId);
4471 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4472 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4473 + subId + "'");
4474 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4475 }
4476 verifyImsMmTelConfiguredOrThrow(slotId);
4477 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4478 transportType, aBoolean -> {
4479 try {
4480 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4481 } catch (RemoteException e) {
4482 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4483 + "running. Ignore");
4484 }
4485 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004486 } catch (ImsException e) {
4487 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004488 } finally {
4489 Binder.restoreCallingIdentity(token);
4490 }
4491 }
4492
shilu366312e2019-12-17 09:28:10 -08004493 /**
4494 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4495 * @param subId The subscription to use to check the configuration.
4496 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 @Override
4498 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004499 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004500 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004501
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 final long token = Binder.clearCallingIdentity();
4503 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004505 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004506 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004507 } catch (ImsException e) {
4508 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 } finally {
4510 Binder.restoreCallingIdentity(token);
4511 }
4512 }
4513
4514 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004515 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004517 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004521 // This setting doesn't require an active ImsService connection, so do not verify. The
4522 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004524 } catch (ImsException e) {
4525 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
4529 }
4530
shilu366312e2019-12-17 09:28:10 -08004531 /**
4532 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4533 * @param subId The subscription to use to check the configuration.
4534 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004536 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004537 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004538 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004539 final long identity = Binder.clearCallingIdentity();
4540 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004542 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004543 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 } catch (ImsException e) {
4545 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
4549 }
4550
4551 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004552 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004554 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004555 final long identity = Binder.clearCallingIdentity();
4556 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004557 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004558 // This setting doesn't require an active ImsService connection, so do not verify. The
4559 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004561 } catch (ImsException e) {
4562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
shilu366312e2019-12-17 09:28:10 -08004568 /**
4569 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4570 * @param subId The subscription to use to check the configuration.
4571 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 @Override
4573 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004574 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004575 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 final long identity = Binder.clearCallingIdentity();
4577 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004578 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004579 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004580 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004581 } catch (ImsException e) {
4582 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586 }
4587
4588 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004589 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004591 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004595 // This setting doesn't require an active ImsService connection, so do not verify. The
4596 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004597 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
4603 }
4604
shilu366312e2019-12-17 09:28:10 -08004605 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004606 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4607 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4608 * @param subId The subscription to use to check the configuration.
4609 */
4610 @Override
4611 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004612 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004613 mApp, subId, "isCrossSimCallingEnabledByUser");
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004616 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004617 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004619 } catch (ImsException e) {
4620 throw new ServiceSpecificException(e.getCode());
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
4624 }
4625
4626 /**
4627 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4628 * Requires MODIFY_PHONE_STATE permission.
4629 * @param subId The subscription to use to check the configuration.
4630 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4631 * false otherwise
4632 */
4633 @Override
4634 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4636 "setCrossSimCallingEnabled");
4637 final long identity = Binder.clearCallingIdentity();
4638 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004639 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004640 // This setting doesn't require an active ImsService connection, so do not verify. The
4641 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004642 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004643 } catch (ImsException e) {
4644 throw new ServiceSpecificException(e.getCode());
4645 } finally {
4646 Binder.restoreCallingIdentity(identity);
4647 }
4648 }
4649
4650 /**
shilu366312e2019-12-17 09:28:10 -08004651 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4652 * @param subId The subscription to use to check the configuration.
4653 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004654 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004655
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004657 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004658 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 final long identity = Binder.clearCallingIdentity();
4660 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004661 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004662 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004663 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004664 } catch (ImsException e) {
4665 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
4669 }
4670
4671 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004672 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004674 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004675 final long identity = Binder.clearCallingIdentity();
4676 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004677 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004678 // This setting doesn't require an active ImsService connection, so do not verify. The
4679 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004680 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004681 } catch (ImsException e) {
4682 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
4685 }
4686 }
4687
4688 @Override
4689 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4691 "setVoWiFiNonPersistent");
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004694 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004695 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004696 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004697 } catch (ImsException e) {
4698 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004699 } finally {
4700 Binder.restoreCallingIdentity(identity);
4701 }
4702 }
4703
shilu366312e2019-12-17 09:28:10 -08004704 /**
4705 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4706 * @param subId The subscription to use to check the configuration.
4707 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 @Override
4709 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004710 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004711 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 final long identity = Binder.clearCallingIdentity();
4713 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004714 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004715 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004716 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004717 } catch (ImsException e) {
4718 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004719 } finally {
4720 Binder.restoreCallingIdentity(identity);
4721 }
4722 }
4723
4724 @Override
4725 public void setVoWiFiModeSetting(int subId, int mode) {
4726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4727 "setVoWiFiModeSetting");
4728 final long identity = Binder.clearCallingIdentity();
4729 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004730 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004731 // This setting doesn't require an active ImsService connection, so do not verify. The
4732 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004733 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004734 } catch (ImsException e) {
4735 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
4739 }
4740
4741 @Override
4742 public int getVoWiFiRoamingModeSetting(int subId) {
4743 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4744 final long identity = Binder.clearCallingIdentity();
4745 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004746 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004747 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004748 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004749 } catch (ImsException e) {
4750 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
4754 }
4755
4756 @Override
4757 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4759 "setVoWiFiRoamingModeSetting");
4760 final long identity = Binder.clearCallingIdentity();
4761 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004762 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004763 // This setting doesn't require an active ImsService connection, so do not verify. The
4764 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004765 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004766 } catch (ImsException e) {
4767 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
4771 }
4772
4773 @Override
4774 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4776 "setRttCapabilityEnabled");
4777 final long identity = Binder.clearCallingIdentity();
4778 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004779 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004780 // This setting doesn't require an active ImsService connection, so do not verify. The
4781 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004782 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004783 } catch (ImsException e) {
4784 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
4788 }
4789
shilu366312e2019-12-17 09:28:10 -08004790 /**
4791 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4792 * @param subId The subscription to use to check the configuration.
4793 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 @Override
4795 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004796 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004797 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004798 final long identity = Binder.clearCallingIdentity();
4799 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004800 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004801 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004802 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004803 } catch (ImsException e) {
4804 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
4808 }
4809
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004810 @Override
4811 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4812 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004813
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004814 final long identity = Binder.clearCallingIdentity();
4815 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004816 if (!isImsAvailableOnDevice()) {
4817 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4818 "IMS not available on device.");
4819 }
4820 int slotId = getSlotIndexOrException(subId);
4821 verifyImsMmTelConfiguredOrThrow(slotId);
4822 ImsManager.getInstance(mApp, slotId)
4823 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004824 } catch (ImsException e) {
4825 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004826 } finally {
4827 Binder.restoreCallingIdentity(identity);
4828 }
4829 }
4830
4831 @Override
4832 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4833 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004834
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004835 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4837 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4838 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004839 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004841 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004842 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004843 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4844 + "is inactive, ignoring unregister.");
4845 // If the subscription is no longer active, just return, since the callback will already
4846 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004847 } finally {
4848 Binder.restoreCallingIdentity(identity);
4849 }
4850 }
4851
joonhunshincffb7fc2021-11-28 07:32:01 +00004852 @Override
4853 public void registerFeatureProvisioningChangedCallback(int subId,
4854 IFeatureProvisioningCallback callback) {
4855 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4856 mApp, subId, "registerFeatureProvisioningChangedCallback");
4857
4858 final long identity = Binder.clearCallingIdentity();
4859 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4860 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4861 }
4862
joonhunshin91bc1952022-04-29 08:47:15 +00004863 try {
4864 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4865 if (controller == null) {
4866 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4867 "Device does not support IMS");
4868 }
4869 controller.addFeatureProvisioningChangedCallback(subId, callback);
4870 } finally {
4871 Binder.restoreCallingIdentity(identity);
4872 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004873 }
4874
4875 @Override
4876 public void unregisterFeatureProvisioningChangedCallback(int subId,
4877 IFeatureProvisioningCallback callback) {
4878 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4879 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4880
4881 final long identity = Binder.clearCallingIdentity();
4882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4883 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4884 }
4885
joonhunshin91bc1952022-04-29 08:47:15 +00004886 try {
4887 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4888 if (controller == null) {
4889 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4890 return;
4891 }
4892 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004896 }
allenwtsu99c623b2020-01-03 18:24:23 +08004897
4898 private void checkModifyPhoneStatePermission(int subId, String message) {
4899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4900 message);
4901 }
4902
allenwtsu99c623b2020-01-03 18:24:23 +08004903 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004904 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004905 boolean isProvisioned) {
4906 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4907
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004910 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4911 if (controller == null) {
4912 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4913 return;
4914 }
4915 controller.setRcsProvisioningStatusForCapability(
4916 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
allenwtsu99c623b2020-01-03 18:24:23 +08004920 }
4921
4922
4923 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004924 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4925 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4926 mApp, subId, "getRcsProvisioningStatusForCapability");
4927
allenwtsu99c623b2020-01-03 18:24:23 +08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004930 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4931 if (controller == null) {
4932 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4933
4934 // device does not support IMS, this method will return true always.
4935 return true;
4936 }
4937 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
4941 }
4942
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004943 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4945 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004946 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004947
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004948 final long identity = Binder.clearCallingIdentity();
4949 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004950 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4951 if (controller == null) {
4952 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4953 return;
4954 }
4955 controller.setImsProvisioningStatusForCapability(
4956 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
4960 }
4961
4962 @Override
4963 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004964 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4965 mApp, subId, "getProvisioningStatusForCapability");
4966
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004969 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4970 if (controller == null) {
4971 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972
joonhunshin91bc1952022-04-29 08:47:15 +00004973 // device does not support IMS, this method will return true always.
4974 return true;
4975 }
4976 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981
4982 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004983 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4984 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4985 mApp, subId, "isProvisioningRequiredForCapability");
4986
4987 final long identity = Binder.clearCallingIdentity();
4988 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004989 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4990 if (controller == null) {
4991 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4992
4993 // device does not support IMS, this method will return false
4994 return false;
4995 }
4996 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005000 }
5001
5002 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005003 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5004 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5005 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005006
joonhunshincffb7fc2021-11-28 07:32:01 +00005007 final long identity = Binder.clearCallingIdentity();
5008 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005009 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5010 if (controller == null) {
5011 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5012
5013 // device does not support IMS, this method will return false
5014 return false;
5015 }
5016 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005017 } finally {
5018 Binder.restoreCallingIdentity(identity);
5019 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005020 }
5021
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005022 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005023 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005024 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5025 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5026 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005027 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5028 mApp, subId, "getImsProvisioningInt");
5029
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005030 final long identity = Binder.clearCallingIdentity();
5031 try {
5032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005033 int slotId = getSlotIndex(subId);
5034 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5035 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5036 + subId + "' for key:" + key);
5037 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5038 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005039
joonhunshin91bc1952022-04-29 08:47:15 +00005040 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5041 if (controller == null) {
5042 loge("getImsProvisioningInt: Device does not support IMS");
5043
5044 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5045 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5046 }
5047 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005048 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5049 return retVal;
5050 }
5051
calvinpanb5a34062021-02-08 19:59:36 +08005052 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005053 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005054 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5055 + subId + "' for key:" + key);
5056 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005057 } finally {
5058 Binder.restoreCallingIdentity(identity);
5059 }
5060 }
5061
5062 @Override
5063 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005064 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5065 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5066 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005067 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5068 mApp, subId, "getImsProvisioningString");
5069
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005073 int slotId = getSlotIndex(subId);
5074 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5075 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5076 + subId + "' for key:" + key);
5077 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5078 }
calvinpanb5a34062021-02-08 19:59:36 +08005079 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005080 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005081 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5082 + subId + "' for key:" + key);
5083 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
5087 }
5088
5089 @Override
5090 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005091 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5092 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5093 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5095 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005096
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005100 int slotId = getSlotIndex(subId);
5101 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5102 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5103 + subId + "' for key:" + key);
5104 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5105 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005106
joonhunshin91bc1952022-04-29 08:47:15 +00005107 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5108 if (controller == null) {
5109 loge("setImsProvisioningInt: Device does not support IMS");
5110
5111 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5112 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5113 }
5114 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005115 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5116 return retVal;
5117 }
5118
calvinpanb5a34062021-02-08 19:59:36 +08005119 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5120 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005121 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005122 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005123 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
5127 }
5128
5129 @Override
5130 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005131 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5132 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5133 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5135 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005139 int slotId = getSlotIndex(subId);
5140 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5141 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5142 + subId + "' for key:" + key);
5143 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5144 }
calvinpanb5a34062021-02-08 19:59:36 +08005145 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5146 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005147 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005148 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
5153 }
5154
Brad Ebinger919631e2021-06-02 17:46:35 -07005155 /**
5156 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5157 * for the given slot ID or no ImsResolver instance has been created.
5158 * @param slotId The slot ID that the IMS service is created for.
5159 * @throws ImsException If there is no ImsService configured for this slot.
5160 */
5161 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5162 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5163 ImsFeature.FEATURE_MMTEL)) {
5164 throw new ImsException("This subscription does not support MMTEL over IMS",
5165 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5166 }
5167 }
5168
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005169 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005170 int slotId = SubscriptionManager.getSlotIndex(subId);
5171 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005172 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5173 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005174 }
5175 return slotId;
5176 }
5177
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005178 private int getSlotIndex(int subId) {
5179 int slotId = SubscriptionManager.getSlotIndex(subId);
5180 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5181 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5182 }
5183 return slotId;
5184 }
5185
Wink Saville36469e72014-06-11 15:17:00 -07005186 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005187 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005188 */
5189 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005190 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5191 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005192 try {
5193 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5194 } catch (SecurityException se) {
5195 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5196 throw new SecurityException("Package " + callingPackage + " does not belong to "
5197 + Binder.getCallingUid());
5198 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005199 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005200 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005201 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005202 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005203 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005204 mApp, subId, callingPackage, callingFeatureId,
5205 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005206 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5207 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 final long identity = Binder.clearCallingIdentity();
5210 try {
5211 final Phone phone = getPhone(subId);
5212 if (phone != null) {
5213 return phone.getServiceState().getDataNetworkType();
5214 } else {
5215 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5216 }
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005220 }
5221
5222 /**
5223 * Returns the data network type
5224 */
5225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005226 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005227 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005228 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005229 }
5230
5231 /**
5232 * Returns the data network type for a subId
5233 */
5234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005235 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5236 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005237 String functionName = "getDataNetworkTypeForSubscriber";
5238 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5239 mApp, functionName)) {
5240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5241 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5242 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5243 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005244 }
5245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 final Phone phone = getPhone(subId);
5249 if (phone != null) {
5250 return phone.getServiceState().getDataNetworkType();
5251 } else {
5252 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5253 }
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005257 }
5258
5259 /**
Wink Saville36469e72014-06-11 15:17:00 -07005260 * Returns the Voice network type for a subId
5261 */
5262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005263 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5264 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005265 String functionName = "getVoiceNetworkTypeForSubscriber";
5266 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5267 mApp, functionName)) {
5268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5269 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5270 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5271 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005272 }
5273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 final Phone phone = getPhone(subId);
5277 if (phone != null) {
5278 return phone.getServiceState().getVoiceNetworkType();
5279 } else {
5280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5281 }
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005285 }
5286
5287 /**
5288 * @return true if a ICC card is present
5289 */
5290 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005291 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005292 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005293 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005294 }
5295
5296 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005297 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005298 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005299 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005300 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 final Phone phone = PhoneFactory.getPhone(slotIndex);
5304 if (phone != null) {
5305 return phone.getIccCard().hasIccCard();
5306 } else {
5307 return false;
5308 }
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005312 }
5313
5314 /**
5315 * Return if the current radio is LTE on CDMA. This
5316 * is a tri-state return value as for a period of time
5317 * the mode may be unknown.
5318 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005319 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005320 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005321 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005322 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005323 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005324 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5325 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5326 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005327 }
5328
Sanket Padawe356d7632015-06-22 14:03:32 -07005329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005330 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5331 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005332 try {
5333 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5334 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005335 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5336 }
5337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 final Phone phone = getPhone(subId);
5341 if (phone == null) {
5342 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5343 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005344 return TelephonyProperties.lte_on_cdma_device()
5345 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 }
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005349 }
Wink Saville36469e72014-06-11 15:17:00 -07005350 }
5351
Wink Saville36469e72014-06-11 15:17:00 -07005352 /**
5353 * {@hide}
5354 * Returns Default subId, 0 in the case of single standby.
5355 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005356 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005357 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005358 }
5359
Shishir Agrawala9f32182016-04-12 12:00:16 -07005360 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005361 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005362 }
5363
Wink Savilleb564aae2014-10-23 10:18:09 -07005364 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005365 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005366 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005367
Pengquan Menge92a50d2018-09-21 15:54:48 -07005368 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005369 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5370 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5371 mApp.getOpPackageName(), mApp.getFeatureId());
5372 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005373 return mSubscriptionController.isActiveSubId(subId);
5374 }
5375
Ihab Awadf2177b72013-11-25 13:33:23 -08005376 /**
5377 * @see android.telephony.TelephonyManager.WifiCallingChoices
5378 */
5379 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 final long identity = Binder.clearCallingIdentity();
5381 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005382 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5384 getWhenToMakeWifiCallsDefaultPreference());
5385 } finally {
5386 Binder.restoreCallingIdentity(identity);
5387 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005388 }
5389
5390 /**
5391 * @see android.telephony.TelephonyManager.WifiCallingChoices
5392 */
5393 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005402 }
5403
Sailesh Nepald1e68152013-12-12 19:08:02 -08005404 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005405 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005406 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005407 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005408
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005409 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5410 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5411 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005412 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005413 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5414 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005415 }
5416 return PhoneFactory.getPhone(phoneId);
5417 }
5418
Shishir Agrawal566b7612013-10-28 14:41:00 -07005419 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005420 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005421 @NonNull IccLogicalChannelRequest request) {
5422 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5423 /*message=*/ "iccOpenLogicalChannel");
5424
5425 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5426 // Verify that the callingPackage in the request belongs to the calling UID
5427 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5428
5429 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005431
Rambo Wanga1782702021-11-10 20:15:19 -08005432 private Phone getPhoneFromValidIccLogicalChannelRequest(
5433 @NonNull IccLogicalChannelRequest request, String message) {
5434 Phone phone;
5435 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5437 mApp, request.subId, message);
5438 phone = getPhoneFromSubId(request.subId);
5439 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5440 enforceModifyPermission();
5441 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5442 } else {
5443 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005444 }
Rambo Wanga1782702021-11-10 20:15:19 -08005445 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005446 }
5447
5448 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005449 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005452 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005454 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5455 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005456 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5457 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 loge("The calling package is not allowed to access ISD-R.");
5459 throw new SecurityException(
5460 "The calling package is not allowed to access ISD-R.");
5461 }
Derek Tan740e1672017-06-27 14:56:27 -07005462 }
Derek Tan740e1672017-06-27 14:56:27 -07005463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005465 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5466 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 return response;
5468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005471 }
5472
5473 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005474 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5475 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5476 /*message=*/"iccCloseLogicalChannel");
5477
5478 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5479
5480 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005481 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005482
Rambo Wanga1782702021-11-10 20:15:19 -08005483 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5484 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005485 // before this feature is enabled, this API should only return false if
5486 // the operation fails instead of throwing runtime exception for
5487 // backward-compatibility.
5488 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5489 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 final long identity = Binder.clearCallingIdentity();
5491 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005492 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005493 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 }
Chen Xue9d737e2022-01-01 23:41:31 -08005495 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005496 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005497 Boolean success = false;
5498 if (result instanceof RuntimeException) {
5499 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005500 if (shouldThrowExceptionOnFailure) {
5501 throw (RuntimeException) result;
5502 } else {
5503 return false;
5504 }
Chen Xue9d737e2022-01-01 23:41:31 -08005505 } else if (result instanceof Boolean) {
5506 success = (Boolean) result;
5507 } else {
5508 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5509 }
Rambo Wanga1782702021-11-10 20:15:19 -08005510 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 return success;
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005514 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005515 }
5516
5517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005518 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005519 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5521 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005522 if (DBG) {
5523 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5524 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5525 + p3 + " data=" + data);
5526 }
5527 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5528 command, p1, p2, p3, data);
5529 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005530
Jordan Liu4c733742019-02-28 12:03:40 -08005531 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005532 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5533 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005534 enforceModifyPermission();
5535 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005536 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5537 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5538 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
5540 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005541 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5542 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005543 }
5544
5545 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5546 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 final long identity = Binder.clearCallingIdentity();
5548 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005549 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 return "";
5551 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005554 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5555 null /* workSource */);
5556 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 // Append the returned status code to the end of the response payload.
5559 String s = Integer.toHexString(
5560 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5561 if (response.payload != null) {
5562 s = IccUtils.bytesToHexString(response.payload) + s;
5563 }
5564 return s;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005567 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005568 }
Jake Hambye994d462014-02-03 13:10:13 -08005569
Evan Charltonc66da362014-05-16 14:06:40 -07005570 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005571 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5572 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5574 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005576 if (DBG) {
5577 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5578 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5579 }
5580 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5581 cla, command, p1, p2, p3, data);
5582 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005583
Jordan Liu4c733742019-02-28 12:03:40 -08005584 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005585 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5586 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005587 enforceModifyPermission();
5588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5589 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005590 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5591 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5592 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005593 }
5594
5595 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005596 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5597 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005598 }
5599
5600 // open APDU basic channel assuming the caller has sufficient permissions
5601 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5602 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5606 && TextUtils.equals(ISDR_AID, data)) {
5607 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005608 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5609 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 if (bestComponent == null
5611 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5612 loge("The calling package is not allowed to select ISD-R.");
5613 throw new SecurityException(
5614 "The calling package is not allowed to select ISD-R.");
5615 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005616 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005619 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5620 null /* workSource */);
5621 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 // Append the returned status code to the end of the response payload.
5624 String s = Integer.toHexString(
5625 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5626 if (response.payload != null) {
5627 s = IccUtils.bytesToHexString(response.payload) + s;
5628 }
5629 return s;
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005632 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005633 }
5634
5635 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005636 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005637 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5639 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 if (DBG) {
5644 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5645 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5646 }
5647
5648 IccIoResult response =
5649 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5650 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5651 subId);
5652
5653 if (DBG) {
5654 log("Exchange SIM_IO [R]" + response);
5655 }
5656
5657 byte[] result = null;
5658 int length = 2;
5659 if (response.payload != null) {
5660 length = 2 + response.payload.length;
5661 result = new byte[length];
5662 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5663 } else {
5664 result = new byte[length];
5665 }
5666
5667 result[length - 1] = (byte) response.sw2;
5668 result[length - 2] = (byte) response.sw1;
5669 return result;
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005672 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005673 }
5674
Nathan Haroldb3014052017-01-25 15:57:32 -08005675 /**
5676 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5677 * on a particular subscription
5678 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005679 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5680 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005682 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005683 return null;
5684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 if (appType != TelephonyManager.APPTYPE_USIM
5689 && appType != TelephonyManager.APPTYPE_SIM) {
5690 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5691 return null;
5692 }
5693 Object response = sendRequest(
5694 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5695 if (response instanceof String[]) {
5696 return (String[]) response;
5697 }
yincheng zhao2737e882019-09-06 17:06:54 -07005698 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005700 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 } finally {
5702 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005703 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005704 }
5705
yincheng zhao2737e882019-09-06 17:06:54 -07005706 /**
5707 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5708 * subscription.
5709 *
5710 * @param subId the id of the subscription.
5711 * @param appType the uicc app type, must be USIM or SIM.
5712 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5713 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005714 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005715 * @return number of fplmns that is successfully written to the SIM.
5716 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005717 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5718 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5720 mApp, subId, "setForbiddenPlmns");
5721
yincheng zhao2737e882019-09-06 17:06:54 -07005722 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5723 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5724 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5725 }
5726 if (fplmns == null) {
5727 throw new IllegalArgumentException("Fplmn List provided is null");
5728 }
5729 for (String fplmn : fplmns) {
5730 if (!CellIdentity.isValidPlmn(fplmn)) {
5731 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5732 }
5733 }
5734 final long identity = Binder.clearCallingIdentity();
5735 try {
5736 Object response = sendRequest(
5737 CMD_SET_FORBIDDEN_PLMNS,
5738 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5739 subId);
5740 return (int) response;
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
5744 }
5745
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005746 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005747 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5749 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5754 if (response.payload == null) {
5755 return "";
5756 }
Evan Charltonc66da362014-05-16 14:06:40 -07005757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 // Append the returned status code to the end of the response payload.
5759 String s = Integer.toHexString(
5760 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5761 s = IccUtils.bytesToHexString(response.payload) + s;
5762 return s;
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Evan Charltonc66da362014-05-16 14:06:40 -07005766 }
5767
Jake Hambye994d462014-02-03 13:10:13 -08005768 /**
5769 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5770 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5771 *
5772 * @param itemID the ID of the item to read
5773 * @return the NV item as a String, or null on error.
5774 */
5775 @Override
5776 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005777 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5779 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005784 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5786 return value;
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Jake Hambye994d462014-02-03 13:10:13 -08005790 }
5791
5792 /**
5793 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5794 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5795 *
5796 * @param itemID the ID of the item to read
5797 * @param itemValue the value to write, as a String
5798 * @return true on success; false on any failure
5799 */
5800 @Override
5801 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005802 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5804 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5809 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005810 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5812 return success;
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Jake Hambye994d462014-02-03 13:10:13 -08005816 }
5817
5818 /**
5819 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5820 * Used for device configuration by some CDMA operators.
5821 *
5822 * @param preferredRoamingList byte array containing the new PRL
5823 * @return true on success; false on any failure
5824 */
5825 @Override
5826 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5828 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829
5830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5833 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5834 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5835 return success;
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Jake Hambye994d462014-02-03 13:10:13 -08005839 }
5840
5841 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005842 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005843 * Used for device configuration by some CDMA operators.
5844 *
chen xu6dac5ab2018-10-26 17:39:23 -07005845 * @param slotIndex - device slot.
5846 *
Jake Hambye994d462014-02-03 13:10:13 -08005847 * @return true on success; false on any failure
5848 */
5849 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005850 public boolean resetModemConfig(int slotIndex) {
5851 Phone phone = PhoneFactory.getPhone(slotIndex);
5852 if (phone != null) {
5853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5854 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855
chen xu6dac5ab2018-10-26 17:39:23 -07005856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5859 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5860 return success;
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 }
chen xu6dac5ab2018-10-26 17:39:23 -07005865 return false;
5866 }
5867
5868 /**
5869 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5870 *
5871 * @param slotIndex - device slot.
5872 *
5873 * @return true on success; false on any failure
5874 */
5875 @Override
5876 public boolean rebootModem(int slotIndex) {
5877 Phone phone = PhoneFactory.getPhone(slotIndex);
5878 if (phone != null) {
5879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5880 mApp, phone.getSubId(), "rebootModem");
5881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5885 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5886 return success;
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
5890 }
5891 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005892 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005893
Brad Ebinger51f743a2017-01-23 13:50:20 -08005894 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005895 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5896 * {@link #disableIms(int)}.
5897 * @param slotIndex device slot.
5898 */
5899 public void resetIms(int slotIndex) {
5900 enforceModifyPermission();
5901
5902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 if (mImsResolver == null) {
5905 // may happen if the does not support IMS.
5906 return;
5907 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005908 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
5912 }
5913
5914 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005915 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5916 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005917 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005918 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005919 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920
5921 final long identity = Binder.clearCallingIdentity();
5922 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005923 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005924 // may happen if the device does not support IMS.
5925 return;
5926 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 } finally {
5929 Binder.restoreCallingIdentity(identity);
5930 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005931 }
5932
5933 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005934 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5935 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005936 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005937 public void disableIms(int slotId) {
5938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005943 // may happen if the device does not support IMS.
5944 return;
5945 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005946 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005950 }
5951
5952 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005953 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5954 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005955 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005956 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005957 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005958 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959
5960 final long identity = Binder.clearCallingIdentity();
5961 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005962 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005963 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5964 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005965 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005966 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005970 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005971 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005972 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5973 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005974 @Override
5975 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005976 enforceModifyPermission();
5977
5978 final long identity = Binder.clearCallingIdentity();
5979 try {
5980 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005981 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
5985 }
5986
5987 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005988 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005989 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005990 */
5991 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5992 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993
5994 final long identity = Binder.clearCallingIdentity();
5995 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005996 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005997 // may happen if the device does not support IMS.
5998 return null;
5999 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006000 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006004 }
6005
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006006 /**
6007 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006008 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006009 */
6010 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6011 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012
6013 final long identity = Binder.clearCallingIdentity();
6014 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006015 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006016 // may happen if the device does not support IMS.
6017 return null;
6018 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006019 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 } finally {
6021 Binder.restoreCallingIdentity(identity);
6022 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006023 }
6024
Brad Ebinger884c07b2018-02-15 16:17:40 -08006025 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006026 * Sets the ImsService Package Name that Telephony will bind to.
6027 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006028 * @param slotIndex the slot ID that the ImsService should bind for.
6029 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006030 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006031 * @param featureTypes An integer array of feature types associated with a packageName.
6032 * @param packageName The name of the package that the current configuration will be replaced
6033 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006034 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006035 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006036 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6037 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006038 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006040 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 final long identity = Binder.clearCallingIdentity();
6043 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006044 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006045 // may happen if the device does not support IMS.
6046 return false;
6047 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006048 Map<Integer, String> featureConfig = new HashMap<>();
6049 for (int featureType : featureTypes) {
6050 featureConfig.put(featureType, packageName);
6051 }
6052 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6053 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006057 }
6058
6059 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006060 * Clears any carrier ImsService overrides for the slot index specified that were previously
6061 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6062 *
6063 * This should only be used for testing.
6064 *
6065 * @param slotIndex the slot ID that the ImsService should bind for.
6066 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6067 */
6068 @Override
6069 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6071 "clearCarrierImsServiceOverride");
6072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006073 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006074
6075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 if (mImsResolver == null) {
6078 // may happen if the device does not support IMS.
6079 return false;
6080 }
6081 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
6084 }
6085 }
6086
6087 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006088 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006089 *
6090 * @param slotId The slot that the ImsService is associated with.
6091 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6092 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006093 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006094 * @return the package name of the ImsService configuration.
6095 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006096 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6097 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006098 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006099 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6100 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 final long identity = Binder.clearCallingIdentity();
6103 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006104 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006105 // may happen if the device does not support IMS.
6106 return "";
6107 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006108 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006109 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6110 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006114 }
6115
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006116 /**
6117 * Get the MmTelFeature state associated with the requested subscription id.
6118 * @param subId The subscription that the MmTelFeature is associated with.
6119 * @param callback A callback with an integer containing the
6120 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6121 */
6122 @Override
6123 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6124 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006125 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6126 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6127 "IMS not available on device.");
6128 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006129 final long token = Binder.clearCallingIdentity();
6130 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006131 int slotId = getSlotIndex(subId);
6132 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6133 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6134 + subId + "'");
6135 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6136 }
6137 verifyImsMmTelConfiguredOrThrow(slotId);
6138 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6139 try {
6140 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6141 } catch (RemoteException e) {
6142 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6143 + "Ignore");
6144 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006145 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006146 } catch (ImsException e) {
6147 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006148 } finally {
6149 Binder.restoreCallingIdentity(token);
6150 }
6151 }
6152
Daniel Brightbb5840b2021-01-12 15:48:18 -08006153 /**
6154 * Sets the ims registration state on all valid {@link Phone}s.
6155 */
6156 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158
6159 final long identity = Binder.clearCallingIdentity();
6160 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006161 // NOTE: Before S, this method only set the default phone.
6162 for (final Phone phone : PhoneFactory.getPhones()) {
6163 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6164 phone.setImsRegistrationState(registered);
6165 }
6166 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Wink Saville36469e72014-06-11 15:17:00 -07006170 }
6171
6172 /**
Stuart Scott54788802015-03-30 13:18:01 -07006173 * Set the network selection mode to automatic.
6174 *
6175 */
6176 @Override
6177 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6179 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180
6181 final long identity = Binder.clearCallingIdentity();
6182 try {
shilufc958392020-01-20 11:36:01 -08006183 if (!isActiveSubscription(subId)) {
6184 return;
6185 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006187 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6188 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
Stuart Scott54788802015-03-30 13:18:01 -07006192 }
6193
Jack Yud10cdd42020-09-28 20:28:01 -07006194 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006195 * Ask the radio to connect to the input network and change selection mode to manual.
6196 *
6197 * @param subId the id of the subscription.
6198 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6199 * the operator to attach to.
6200 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6201 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6202 * normal network selection next time.
6203 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006204 */
6205 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006206 public boolean setNetworkSelectionModeManual(
6207 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6209 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006210
Jack Yu285100e2022-12-02 22:48:35 -08006211 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006212 if (!isActiveSubscription(subId)) {
6213 return false;
6214 }
6215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006217 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006219 if (DBG) {
6220 log("setNetworkSelectionModeManual: subId: " + subId
6221 + " operator: " + operatorInfo);
6222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006227 }
shilu84f6e8b2019-12-19 13:58:01 -08006228 /**
6229 * Get the manual network selection
6230 *
6231 * @param subId the id of the subscription.
6232 *
6233 * @return the previously saved user selected PLMN
6234 */
6235 @Override
6236 public String getManualNetworkSelectionPlmn(int subId) {
6237 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006238 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006239 mApp, subId, "getManualNetworkSelectionPlmn");
6240
6241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006244 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006245 }
6246
6247 final Phone phone = getPhone(subId);
6248 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006249 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006250 }
6251 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6252 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6253 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
6257 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006258
6259 /**
6260 * Scans for available networks.
6261 */
6262 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006263 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6264 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6266 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006267 LocationAccessPolicy.LocationPermissionResult locationResult =
6268 LocationAccessPolicy.checkLocationPermission(mApp,
6269 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6270 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006271 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006272 .setCallingPid(Binder.getCallingPid())
6273 .setCallingUid(Binder.getCallingUid())
6274 .setMethod("getCellNetworkScanResults")
6275 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006276 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6277 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006278 .build());
6279 switch (locationResult) {
6280 case DENIED_HARD:
6281 throw new SecurityException("Not allowed to access scan results -- location");
6282 case DENIED_SOFT:
6283 return null;
6284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006285
Pengquan Menga1bb6272018-09-06 09:59:22 -07006286 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 try {
6288 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006289 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 } finally {
6292 Binder.restoreCallingIdentity(identity);
6293 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006294 }
6295
6296 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006297 * Get the call forwarding info, given the call forwarding reason.
6298 */
6299 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006300 public void getCallForwarding(int subId, int callForwardingReason,
6301 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006302 enforceReadPrivilegedPermission("getCallForwarding");
6303 long identity = Binder.clearCallingIdentity();
6304 try {
6305 if (DBG) {
6306 log("getCallForwarding: subId " + subId
6307 + " callForwardingReason" + callForwardingReason);
6308 }
Hall Liu27d24262020-09-18 19:04:59 -07006309
6310 Phone phone = getPhone(subId);
6311 if (phone == null) {
6312 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006313 callback.onError(
6314 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006315 } catch (RemoteException e) {
6316 // ignore
6317 }
6318 return;
6319 }
6320
6321 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6322 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6323 @Override
6324 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6325 try {
6326 callback.onCallForwardingInfoAvailable(info);
6327 } catch (RemoteException e) {
6328 // ignore
6329 }
6330 }
6331
6332 @Override
6333 public void onError(int error) {
6334 try {
6335 callback.onError(error);
6336 } catch (RemoteException e) {
6337 // ignore
6338 }
6339 }
6340 });
6341 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006342 } finally {
6343 Binder.restoreCallingIdentity(identity);
6344 }
6345 }
6346
6347 /**
6348 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6349 * reason, the number to forward, and the timeout before the forwarding is attempted.
6350 */
6351 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006352 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6353 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006354 enforceModifyPermission();
6355 long identity = Binder.clearCallingIdentity();
6356 try {
6357 if (DBG) {
6358 log("setCallForwarding: subId " + subId
6359 + " callForwardingInfo" + callForwardingInfo);
6360 }
Hall Liu27d24262020-09-18 19:04:59 -07006361
6362 Phone phone = getPhone(subId);
6363 if (phone == null) {
6364 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006365 callback.accept(
6366 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006367 } catch (RemoteException e) {
6368 // ignore
6369 }
6370 return;
6371 }
6372
6373 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6374 FunctionalUtils.ignoreRemoteException(callback::accept));
6375
6376 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
6380 }
6381
6382 /**
Hall Liu27d24262020-09-18 19:04:59 -07006383 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006384 */
6385 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006386 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006387 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006388 long identity = Binder.clearCallingIdentity();
6389 try {
Hall Liu27d24262020-09-18 19:04:59 -07006390 Phone phone = getPhone(subId);
6391 if (phone == null) {
6392 try {
6393 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6394 } catch (RemoteException e) {
6395 // ignore
6396 }
6397 return;
6398 }
SongFerngWang0e767992021-03-31 22:08:45 +08006399 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6400 PersistableBundle c = configManager.getConfigForSubId(subId);
6401 boolean requireUssd = c.getBoolean(
6402 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006403
Shuo Qian4a594052020-01-23 11:59:30 -08006404 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006405 if (requireUssd) {
6406 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6407 getSubscriptionCarrierId(subId));
6408 String newUssdCommand = "";
6409 try {
6410 newUssdCommand = carrierXmlParser.getFeature(
6411 CarrierXmlParser.FEATURE_CALL_WAITING)
6412 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6413 } catch (NullPointerException e) {
6414 loge("Failed to generate USSD number" + e);
6415 }
6416 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6417 mMainThreadHandler, callback, carrierXmlParser,
6418 CarrierXmlParser.SsEntry.SSAction.QUERY);
6419 final String ussdCommand = newUssdCommand;
6420 Executors.newSingleThreadExecutor().execute(() -> {
6421 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6422 });
6423 } else {
6424 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6425 callback::accept);
6426 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6427 }
Shuo Qian4a594052020-01-23 11:59:30 -08006428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
6431 }
6432
6433 /**
Hall Liu27d24262020-09-18 19:04:59 -07006434 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006435 */
6436 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006437 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006438 enforceModifyPermission();
6439 long identity = Binder.clearCallingIdentity();
6440 try {
Hall Liu27d24262020-09-18 19:04:59 -07006441 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6442
6443 Phone phone = getPhone(subId);
6444 if (phone == null) {
6445 try {
6446 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6447 } catch (RemoteException e) {
6448 // ignore
6449 }
6450 return;
6451 }
6452
SongFerngWang0e767992021-03-31 22:08:45 +08006453 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6454 PersistableBundle c = configManager.getConfigForSubId(subId);
6455 boolean requireUssd = c.getBoolean(
6456 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006457
SongFerngWang0e767992021-03-31 22:08:45 +08006458 if (DBG) log("getCallWaitingStatus: subId " + subId);
6459 if (requireUssd) {
6460 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6461 getSubscriptionCarrierId(subId));
6462 CarrierXmlParser.SsEntry.SSAction ssAction =
6463 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6464 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6465 String newUssdCommand = "";
6466 try {
6467 newUssdCommand = carrierXmlParser.getFeature(
6468 CarrierXmlParser.FEATURE_CALL_WAITING)
6469 .makeCommand(ssAction, null);
6470 } catch (NullPointerException e) {
6471 loge("Failed to generate USSD number" + e);
6472 }
6473 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6474 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6475 final String ussdCommand = newUssdCommand;
6476 Executors.newSingleThreadExecutor().execute(() -> {
6477 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6478 });
6479 } else {
6480 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6481 FunctionalUtils.ignoreRemoteException(callback::accept));
6482
6483 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6484 }
Shuo Qian4a594052020-01-23 11:59:30 -08006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
6490 /**
yinxub1bed742017-04-17 11:45:04 -07006491 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006492 *
yinxub1bed742017-04-17 11:45:04 -07006493 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006494 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6495 * location related information which will be sent if the caller already possess
6496 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006497 * @param request contains the radio access networks with bands/channels to scan
6498 * @param messenger callback messenger for scan results or errors
6499 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006500 * @return the id of the requested scan which can be used to stop the scan.
6501 */
6502 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006503 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6504 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006505 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6507 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006508 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006509 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6510 if (!renounceFineLocationAccess) {
6511 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6512 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6513 .setCallingPackage(callingPackage)
6514 .setCallingFeatureId(callingFeatureId)
6515 .setCallingPid(Binder.getCallingPid())
6516 .setCallingUid(Binder.getCallingUid())
6517 .setMethod("requestNetworkScan")
6518 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6519 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6520 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6521 .build());
6522 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006523 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006524 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6525 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006526 if (e != null) {
6527 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6528 throw e;
6529 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006530 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006531 return TelephonyScanManager.INVALID_SCAN_ID;
6532 }
6533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534 }
Hall Liu912dfd32019-04-25 14:02:26 -07006535 int callingUid = Binder.getCallingUid();
6536 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006540 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006541 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006542 } finally {
6543 Binder.restoreCallingIdentity(identity);
6544 }
yinxu504e1392017-04-12 16:03:22 -07006545 }
6546
Hall Liub2ac8ef2019-02-28 15:56:23 -08006547 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006548 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006549 boolean hasCarrierPriv;
6550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6553 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6554 } finally {
6555 Binder.restoreCallingIdentity(identity);
6556 }
Hall Liu558027f2019-05-15 19:14:05 -07006557 boolean hasNetworkScanPermission =
6558 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6559 == PERMISSION_GRANTED;
6560
6561 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6562 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6563 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006564 }
6565
6566 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6567 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006568 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6569 return new SecurityException("Specific channels must not be"
6570 + " scanned without location access.");
6571 }
6572 }
6573 }
6574
Hall Liub2ac8ef2019-02-28 15:56:23 -08006575 return null;
6576 }
6577
yinxu504e1392017-04-12 16:03:22 -07006578 /**
6579 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006580 *
6581 * @param subId id of the subscription
6582 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006583 */
6584 @Override
6585 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6587 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588
Hall Liu912dfd32019-04-25 14:02:26 -07006589 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 final long identity = Binder.clearCallingIdentity();
6591 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006592 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 } finally {
6594 Binder.restoreCallingIdentity(identity);
6595 }
yinxu504e1392017-04-12 16:03:22 -07006596 }
6597
6598 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006599 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006600 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006601 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006602 */
6603 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006604 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006605 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006606 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006607 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608
6609 final long identity = Binder.clearCallingIdentity();
6610 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006611 if (DBG) log("getAllowedNetworkTypesBitmask");
6612 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6613 int networkTypesBitmask = (result != null ? result[0] : -1);
6614 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6615 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 } finally {
6617 Binder.restoreCallingIdentity(identity);
6618 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006619 }
6620
6621 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006622 * Get the allowed network types for certain reason.
6623 *
6624 * @param subId the id of the subscription.
6625 * @param reason the reason the allowed network type change is taking place
6626 * @return the allowed network types.
6627 */
6628 @Override
6629 public long getAllowedNetworkTypesForReason(int subId,
6630 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006631 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006632 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 }
6640
6641 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006642 * Enable/Disable E-UTRA-NR Dual Connectivity
6643 * @param subId subscription id of the sim card
6644 * @param nrDualConnectivityState expected NR dual connectivity state
6645 * This can be passed following states
6646 * <ol>
6647 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6648 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6649 * <li>Disable NR dual connectivity and force secondary cell to be released
6650 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6651 * </ol>
6652 * @return operation result.
6653 */
6654 @Override
6655 public int setNrDualConnectivityState(int subId,
6656 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6658 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006659 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006660 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6661 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6662 }
6663
Sooraj Sasindran37444802020-08-11 10:40:43 -07006664 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6668 nrDualConnectivityState, subId,
6669 workSource);
6670 if (DBG) log("enableNRDualConnectivity result: " + result);
6671 return result;
6672 } finally {
6673 Binder.restoreCallingIdentity(identity);
6674 }
6675 }
6676
6677 /**
6678 * Is E-UTRA-NR Dual Connectivity enabled
6679 * @return true if dual connectivity is enabled else false
6680 */
6681 @Override
6682 public boolean isNrDualConnectivityEnabled(int subId) {
6683 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006684 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006685 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006686 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006687 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6688 return false;
6689 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6691 final long identity = Binder.clearCallingIdentity();
6692 try {
6693 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6694 null, subId, workSource);
6695 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6696 return isEnabled;
6697 } finally {
6698 Binder.restoreCallingIdentity(identity);
6699 }
6700 }
6701
6702 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006703 * Set the allowed network types of the device and
6704 * provide the reason triggering the allowed network change.
6705 *
6706 * @param subId the id of the subscription.
6707 * @param reason the reason the allowed network type change is taking place
6708 * @param allowedNetworkTypes the allowed network types.
6709 * @return true on success; false on any failure.
6710 */
6711 @Override
6712 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006713 @TelephonyManager.AllowedNetworkTypesReason int reason,
6714 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6716 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006717 // If the caller only has carrier privileges, then they should not be able to override
6718 // any network types which were set for security reasons.
6719 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6720 != PERMISSION_GRANTED
6721 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6722 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6723 throw new SecurityException(
6724 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6725 + " reason "
6726 + reason);
6727 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006728 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006729 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6730 return false;
6731 }
6732 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6733 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006734 return false;
6735 }
6736
Aishwarya Mallampati32336e82023-01-04 23:02:56 +00006737 log("setAllowedNetworkTypesForReason: " + reason + " value: "
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006738 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6739
6740
Aishwarya Mallampati32336e82023-01-04 23:02:56 +00006741 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006742 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6743 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006744 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006745
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006746 final long identity = Binder.clearCallingIdentity();
6747 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006748 Boolean success = (Boolean) sendRequest(
6749 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6750 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6751
6752 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6753 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006754 } finally {
6755 Binder.restoreCallingIdentity(identity);
6756 }
6757 }
6758
6759 /**
Miaoa84611c2019-03-15 09:21:10 +08006760 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006761 *
Miaoa84611c2019-03-15 09:21:10 +08006762 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006763 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006764 * @hide
6765 */
6766 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006767 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006768 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006770 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 try {
Miaoa84611c2019-03-15 09:21:10 +08006772 if (phone != null) {
6773 return phone.hasMatchedTetherApnSetting();
6774 } else {
6775 return false;
6776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 } finally {
6778 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006779 }
Junda Liu475951f2014-11-07 16:45:03 -08006780 }
6781
6782 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006783 * Get the user enabled state of Mobile Data.
6784 *
6785 * TODO: remove and use isUserDataEnabled.
6786 * This can't be removed now because some vendor codes
6787 * calls through ITelephony directly while they should
6788 * use TelephonyManager.
6789 *
6790 * @return true on enabled
6791 */
6792 @Override
6793 public boolean getDataEnabled(int subId) {
6794 return isUserDataEnabled(subId);
6795 }
6796
6797 /**
6798 * Get whether mobile data is enabled per user setting.
6799 *
6800 * There are other factors deciding whether mobile data is actually enabled, but they are
6801 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006802 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006803 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6804 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006805 *
6806 * @return {@code true} if data is enabled else {@code false}
6807 */
6808 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006809 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006810 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006811 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006812 try {
6813 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6814 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006815 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006816 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6817 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006818 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006820 mApp, subId, functionName);
6821
Robert Greenwalt646120a2014-05-23 11:54:03 -07006822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823
6824 final long identity = Binder.clearCallingIdentity();
6825 try {
Jack Yu285100e2022-12-02 22:48:35 -08006826 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6828 Phone phone = PhoneFactory.getPhone(phoneId);
6829 if (phone != null) {
6830 boolean retVal = phone.isUserDataEnabled();
6831 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6832 return retVal;
6833 } else {
6834 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6835 return false;
6836 }
6837 } finally {
6838 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006839 }
6840 }
6841
6842 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006843 * Checks if the device is capable of mobile data by considering whether whether the
6844 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6845 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006846 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006847 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006848 */
6849 @Override
6850 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006851 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006852 try {
6853 try {
6854 mApp.enforceCallingOrSelfPermission(
6855 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006856 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006857 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006858 try {
6859 mApp.enforceCallingOrSelfPermission(
6860 android.Manifest.permission.READ_PHONE_STATE,
6861 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006862 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006863 mApp.enforceCallingOrSelfPermission(
6864 permission.READ_BASIC_PHONE_STATE, functionName);
6865 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006866 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006867 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006868 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870
6871 final long identity = Binder.clearCallingIdentity();
6872 try {
Jack Yu285100e2022-12-02 22:48:35 -08006873 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 Phone phone = PhoneFactory.getPhone(phoneId);
6875 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006876 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006877 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 return retVal;
6879 } else {
6880 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6881 return false;
6882 }
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006885 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006886 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006887
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006888 /**
6889 * Check if data is enabled for a specific reason
6890 * @param subId Subscription index
6891 * @param reason the reason the data enable change is taking place
6892 * @return {@code true} if the overall data is enabled; {@code false} if not.
6893 */
6894 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006895 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006896 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006897 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006898 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006899 try {
6900 mApp.enforceCallingOrSelfPermission(
6901 android.Manifest.permission.ACCESS_NETWORK_STATE,
6902 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006903 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006904 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6905 functionName);
6906 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006907 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006908 try {
6909 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006910 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006911 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006913 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006914 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006915 }
6916
6917
6918 final long identity = Binder.clearCallingIdentity();
6919 try {
Jack Yu285100e2022-12-02 22:48:35 -08006920 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006921 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006922 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006923 + " reason=" + reason);
6924 }
6925 Phone phone = PhoneFactory.getPhone(phoneId);
6926 if (phone != null) {
6927 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006928 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006929 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006930 return retVal;
6931 } else {
6932 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006933 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006934 + subId + " retVal=false");
6935 }
6936 return false;
6937 }
6938 } finally {
6939 Binder.restoreCallingIdentity(identity);
6940 }
6941 }
6942
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006943 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006944 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006945 // No permission needed; this only lets the caller inspect their own status.
6946 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006947 }
Junda Liu29340342014-07-10 15:23:27 -07006948
6949 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006950 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006951 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006952 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6953 }
6954
6955 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6956 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006957 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006958 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006959 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6960 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006961 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6962 if (cpt == null) {
6963 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006964 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6965 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006966 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006967 }
6968
6969 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006970 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006971 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006972 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006973 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006974 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006975 Phone phone = getPhone(subId);
6976 if (phone == null) {
6977 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6978 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6979 }
6980 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6981 if (cpt == null) {
6982 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006983 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6984 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006985 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006986 }
6987
6988 @Override
6989 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006990 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006991 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6992 }
6993
6994 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006995 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006996 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006997 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006998 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006999 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7000 Phone phone = PhoneFactory.getPhone(phoneId);
7001 if (phone == null) {
7002 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007003 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007004 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7005 if (cpt == null) {
7006 continue;
7007 }
7008 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007009 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7010 break;
7011 }
7012 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007013 return result;
Junda Liu29340342014-07-10 15:23:27 -07007014 }
Derek Tan89e89d42014-07-08 17:00:10 -07007015
7016 @Override
Junda Liue64de782015-04-16 17:19:16 -07007017 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007018 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007019 Phone phone = PhoneFactory.getPhone(phoneId);
7020 if (phone == null) {
7021 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007022 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007023 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7024 if (cpt == null) {
7025 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007026 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007027 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007028 }
7029
Amith Yamasani6e118872016-02-19 12:53:51 -08007030 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007031 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007032 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007033 Phone phone = PhoneFactory.getPhone(phoneId);
7034 if (phone == null) {
7035 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007036 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007037 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7038 if (cpt == null) {
7039 return Collections.emptyList();
7040 }
7041 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007042 }
7043
chen xuf7e9fe82019-05-09 19:31:02 -07007044 @Override
7045 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007046 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007047 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007048 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007049 try {
7050 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7051 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7052 }
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007055 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007056 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007057 }
7058
Rambo Wang6812ffb2022-03-15 16:54:17 -07007059 @Override
7060 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7061 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7062
7063 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7064 if (phone == null) {
7065 return null;
7066 }
7067 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7068 if (cpt == null) {
7069 return null;
7070 }
7071 return cpt.getCarrierServicePackageName();
7072 }
7073
Wink Savilleb564aae2014-10-23 10:18:09 -07007074 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007075 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007076 UiccPort port = phone == null ? null : phone.getUiccPort();
7077 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007078 return null;
7079 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007080 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007081 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007082 return null;
7083 }
7084 return iccId;
7085 }
7086
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007087 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007088 public void setCallComposerStatus(int subId, int status) {
7089 enforceModifyPermission();
7090
7091 final long identity = Binder.clearCallingIdentity();
7092 try {
7093 Phone phone = getPhone(subId);
7094 if (phone != null) {
7095 Phone defaultPhone = phone.getImsPhone();
7096 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7097 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7098 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007099 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7100 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007101 }
7102 }
Shuo Qian284ae752020-12-22 19:10:14 -08007103 } catch (ImsException e) {
7104 throw new ServiceSpecificException(e.getCode());
7105 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007106 Binder.restoreCallingIdentity(identity);
7107 }
7108 }
7109
7110 @Override
7111 public int getCallComposerStatus(int subId) {
7112 enforceReadPrivilegedPermission("getCallComposerStatus");
7113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 Phone phone = getPhone(subId);
7117 if (phone != null) {
7118 Phone defaultPhone = phone.getImsPhone();
7119 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7120 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7121 return imsPhone.getCallComposerStatus();
7122 }
7123 }
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
7127 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7128 }
7129
7130 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007131 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7132 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007133 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007134 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 final String iccId = getIccId(subId);
7139 final Phone phone = getPhone(subId);
7140 if (phone == null) {
7141 return false;
7142 }
7143 final String subscriberId = phone.getSubscriberId();
7144
7145 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007146 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 + subscriberId + " to " + number);
7148 }
7149
7150 if (TextUtils.isEmpty(iccId)) {
7151 return false;
7152 }
7153
7154 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7155
7156 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7157 if (alphaTag == null) {
7158 editor.remove(alphaTagPrefKey);
7159 } else {
7160 editor.putString(alphaTagPrefKey, alphaTag);
7161 }
7162
7163 // Record both the line number and IMSI for this ICCID, since we need to
7164 // track all merged IMSIs based on line number
7165 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7166 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7167 if (number == null) {
7168 editor.remove(numberPrefKey);
7169 editor.remove(subscriberPrefKey);
7170 } else {
7171 editor.putString(numberPrefKey, number);
7172 editor.putString(subscriberPrefKey, subscriberId);
7173 }
7174
7175 editor.commit();
7176 return true;
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007179 }
Derek Tan7226c842014-07-02 17:42:23 -07007180 }
7181
7182 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007183 public String getLine1NumberForDisplay(int subId, String callingPackage,
7184 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007185 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007187 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007188 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007189 return null;
7190 }
Derek Tan97ebb422014-09-05 16:55:38 -07007191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 String iccId = getIccId(subId);
7195 if (iccId != null) {
7196 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7197 if (DBG_MERGE) {
7198 log("getLine1NumberForDisplay returning "
7199 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7200 }
7201 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7204 return null;
7205 } finally {
7206 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007207 }
Derek Tan7226c842014-07-02 17:42:23 -07007208 }
7209
7210 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007211 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7212 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007214 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007215 return null;
7216 }
Derek Tan97ebb422014-09-05 16:55:38 -07007217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 String iccId = getIccId(subId);
7221 if (iccId != null) {
7222 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7223 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7224 }
7225 return null;
7226 } finally {
7227 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007228 }
Derek Tan7226c842014-07-02 17:42:23 -07007229 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007230
7231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007232 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7233 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007234 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7235 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007237 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007238 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007239 return null;
7240 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007241
Jordan Liub49b04b2019-05-06 14:45:15 -07007242 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7243 // the process, where TelephonyManager was instantiated.
7244 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007245 final long identity = Binder.clearCallingIdentity();
7246 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007247 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 final TelephonyManager tele = TelephonyManager.from(context);
7249 final SubscriptionManager sub = SubscriptionManager.from(context);
7250
7251 // Figure out what subscribers are currently active
7252 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253
Jordan Liub49b04b2019-05-06 14:45:15 -07007254 // Only consider subs which match the current subId
7255 // This logic can be simplified. See b/131189269 for progress.
7256 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007257 activeSubscriberIds.add(tele.getSubscriberId(subId));
7258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259
7260 // First pass, find a number override for an active subscriber
7261 String mergeNumber = null;
7262 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7263 for (String key : prefs.keySet()) {
7264 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7265 final String subscriberId = (String) prefs.get(key);
7266 if (activeSubscriberIds.contains(subscriberId)) {
7267 final String iccId = key.substring(
7268 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7269 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7270 mergeNumber = (String) prefs.get(numberKey);
7271 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007272 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273 + " for active subscriber " + subscriberId);
7274 }
7275 if (!TextUtils.isEmpty(mergeNumber)) {
7276 break;
7277 }
7278 }
7279 }
7280 }
7281
7282 // Shortcut when no active merged subscribers
7283 if (TextUtils.isEmpty(mergeNumber)) {
7284 return null;
7285 }
7286
7287 // Second pass, find all subscribers under that line override
7288 final ArraySet<String> result = new ArraySet<>();
7289 for (String key : prefs.keySet()) {
7290 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7291 final String number = (String) prefs.get(key);
7292 if (mergeNumber.equals(number)) {
7293 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7294 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7295 final String subscriberId = (String) prefs.get(subscriberKey);
7296 if (!TextUtils.isEmpty(subscriberId)) {
7297 result.add(subscriberId);
7298 }
7299 }
7300 }
7301 }
7302
7303 final String[] resultArray = result.toArray(new String[result.size()]);
7304 Arrays.sort(resultArray);
7305 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007306 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7308 }
7309 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007310 } finally {
7311 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007312 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007313 }
7314
7315 @Override
zoey chen38003472019-12-13 17:16:31 +08007316 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7317 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007318
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 final TelephonyManager telephonyManager = mApp.getSystemService(
7322 TelephonyManager.class);
7323 String subscriberId = telephonyManager.getSubscriberId(subId);
7324 if (subscriberId == null) {
7325 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007326 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007327 + subId);
7328 }
7329 return null;
7330 }
7331
Jack Yu285100e2022-12-02 22:48:35 -08007332 ParcelUuid groupUuid;
7333 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7334 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7335 .getSubscriptionInfo(subId);
7336 groupUuid = info.getGroupUuid();
7337 } else {
7338 final SubscriptionInfo info = mSubscriptionController
7339 .getSubscriptionInfo(subId);
7340 groupUuid = info.getGroupUuid();
7341 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007342 // If it doesn't belong to any group, return just subscriberId of itself.
7343 if (groupUuid == null) {
7344 return new String[]{subscriberId};
7345 }
7346
7347 // Get all subscriberIds from the group.
7348 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007349 List<SubscriptionInfo> groupInfos;
7350 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7351 groupInfos = SubscriptionManagerService.getInstance()
7352 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7353 mApp.getAttributionTag());
7354 } else {
7355 groupInfos = mSubscriptionController
7356 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7357 mApp.getAttributionTag());
7358 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007359 for (SubscriptionInfo subInfo : groupInfos) {
7360 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7361 if (subscriberId != null) {
7362 mergedSubscriberIds.add(subscriberId);
7363 }
7364 }
7365
7366 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369
7370 }
7371 }
7372
7373 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007374 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007375 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007376 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377
7378 final long identity = Binder.clearCallingIdentity();
7379 try {
7380 final Phone phone = getPhone(subId);
7381 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7382 } finally {
7383 Binder.restoreCallingIdentity(identity);
7384 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007385 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007386
7387 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007388 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007389 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7390 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007391 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7392 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393
7394 final long identity = Binder.clearCallingIdentity();
7395 try {
7396 final Phone phone = getPhone(subId);
7397 if (phone == null) {
7398 return false;
7399 }
7400 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7401 cdmaNonRoamingList);
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007404 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007405 }
7406
7407 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007408 @Deprecated
7409 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7410 enforceModifyPermission();
7411
7412 int returnValue = 0;
7413 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007414 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007415 if(result.exception == null) {
7416 if (result.result != null) {
7417 byte[] responseData = (byte[])(result.result);
7418 if(responseData.length > oemResp.length) {
7419 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7420 responseData.length + "bytes. Buffer Size is " +
7421 oemResp.length + "bytes.");
7422 }
7423 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7424 returnValue = responseData.length;
7425 }
7426 } else {
7427 CommandException ex = (CommandException) result.exception;
7428 returnValue = ex.getCommandError().ordinal();
7429 if(returnValue > 0) returnValue *= -1;
7430 }
7431 } catch (RuntimeException e) {
7432 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7433 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7434 if(returnValue > 0) returnValue *= -1;
7435 }
7436
7437 return returnValue;
7438 }
7439
7440 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007441 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007442 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007443 try {
7444 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007445 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007446 mApp, phone.getSubId(), "getRadioAccessFamily");
7447 } catch (SecurityException e) {
7448 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7449 throw e;
7450 }
chen xub97461a2018-10-26 14:17:57 -07007451 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007452 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007453 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 final long identity = Binder.clearCallingIdentity();
7456 try {
chen xub97461a2018-10-26 14:17:57 -07007457 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007458 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007459 mApp, phone.getSubId(), "getRadioAccessFamily");
7460 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 } finally {
7462 Binder.restoreCallingIdentity(identity);
7463 }
chen xub97461a2018-10-26 14:17:57 -07007464 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007465 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007466
7467 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007468 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007469 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007470 try {
7471 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7472 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007473 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007474 }
7475 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007476 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007477 }
7478 RoleManager rm = mApp.getSystemService(RoleManager.class);
7479 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7480 if (!dialerRoleHolders.contains(callingPackage)) {
7481 throw new SecurityException("App must be the dialer role holder to"
7482 + " upload a call composer pic");
7483 }
7484
7485 Executors.newSingleThreadExecutor().execute(() -> {
7486 ByteArrayOutputStream output = new ByteArrayOutputStream(
7487 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7488 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7489 boolean readUntilEnd = false;
7490 int totalBytesRead = 0;
7491 byte[] buffer = new byte[16 * 1024];
7492 while (true) {
7493 int numRead;
7494 try {
7495 numRead = input.read(buffer);
7496 } catch (IOException e) {
7497 try {
7498 fd.checkError();
7499 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7500 null);
7501 } catch (IOException e1) {
7502 // This means that the other side closed explicitly with an error. If this
7503 // happens, log and ignore.
7504 loge("Remote end of call composer picture pipe closed: " + e1);
7505 }
7506 break;
7507 }
7508 if (numRead == -1) {
7509 readUntilEnd = true;
7510 break;
7511 }
7512 totalBytesRead += numRead;
7513 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7514 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7515 try {
7516 input.close();
7517 } catch (IOException e) {
7518 // ignore
7519 }
7520 break;
7521 }
7522 output.write(buffer, 0, numRead);
7523 }
7524 // Generally, the remote end will close the file descriptors. The only case where we
7525 // close is above, where the picture size is too big.
7526
7527 try {
7528 fd.checkError();
7529 } catch (IOException e) {
7530 loge("Remote end for call composer closed with an error: " + e);
7531 return;
7532 }
7533
Hall Liuaa4211e2021-01-20 15:43:39 -08007534 if (!readUntilEnd) {
7535 loge("Did not finish reading entire image; aborting");
7536 return;
7537 }
Hall Liu82694d52020-12-11 18:22:04 -08007538
Hall Liuaa4211e2021-01-20 15:43:39 -08007539 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7540 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7541 new CallComposerPictureTransfer.Factory() {},
7542 imageData,
7543 (result) -> {
7544 if (result.first != null) {
7545 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7546 Bundle outputResult = new Bundle();
7547 outputResult.putParcelable(
7548 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7549 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7550 outputResult);
7551 } else {
7552 callback.send(result.second, null);
7553 }
7554 }
7555 );
Hall Liu82694d52020-12-11 18:22:04 -08007556 });
7557 }
7558
7559 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007560 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007561 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563
7564 final long identity = Binder.clearCallingIdentity();
7565 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007566 ImsManager.getInstance(defaultPhone.getContext(),
7567 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007571 }
7572
7573 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007575 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7577 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007578 return false;
7579 }
Svet Ganovb320e182015-04-16 12:30:10 -07007580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 // Check the user preference and the system-level IMS setting. Even if the user has
7584 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7585 // In the long run, we may instead need to check if there exists a connection service
7586 // which can support video calling.
7587 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007588 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 return imsManager.isVtEnabledByPlatform()
7590 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7591 && imsManager.isVtEnabledByUser();
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007595 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007596
Andrew Leea1239f22015-03-02 17:44:07 -08007597 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007598 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7599 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007601 mApp, subId, callingPackage, callingFeatureId,
7602 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 return false;
7604 }
7605
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 CarrierConfigManager configManager =
7609 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007610 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
Andrew Leea1239f22015-03-02 17:44:07 -08007615 }
7616
7617 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007618 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007620 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 return false;
7622 }
7623
7624 final long identity = Binder.clearCallingIdentity();
7625 try {
7626 CarrierConfigManager configManager =
7627 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007628 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
Andrew Leea1239f22015-03-02 17:44:07 -08007633 }
7634
Andrew Lee9431b832015-03-09 18:46:45 -07007635 @Override
7636 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007637 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007638 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007639 }
7640
7641 @Override
7642 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 final long identity = Binder.clearCallingIdentity();
7644 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007645 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 } finally {
7647 Binder.restoreCallingIdentity(identity);
7648 }
Andrew Lee9431b832015-03-09 18:46:45 -07007649 }
7650
Hall Liuf6668912018-10-31 17:05:23 -07007651 /**
7652 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7653 * support for the feature and device firmware support.
7654 *
7655 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7656 */
7657 @Override
7658 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007660 final Phone phone = getPhone(subscriptionId);
7661 if (phone == null) {
7662 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7663 return false;
7664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007666 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7668 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007669 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670 return isCarrierSupported && isDeviceSupported;
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
Hall Liu98187582018-01-22 19:15:32 -08007674 }
7675
Hall Liuf6668912018-10-31 17:05:23 -07007676 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007677 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7678 * RTT setting, will return true if the device and carrier both support RTT.
7679 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007680 */
7681 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 final long identity = Binder.clearCallingIdentity();
7683 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007684 boolean isRttSupported = isRttSupported(subscriptionId);
7685 boolean isUserRttSettingOn = Settings.Secure.getInt(
7686 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7687 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7688 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7689 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 } finally {
7691 Binder.restoreCallingIdentity(identity);
7692 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007693 }
7694
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007695 @Deprecated
7696 @Override
7697 public String getDeviceId(String callingPackage) {
7698 return getDeviceIdWithFeature(callingPackage, null);
7699 }
7700
Sanket Padawe7310cc72015-01-14 09:53:20 -08007701 /**
7702 * Returns the unique device ID of phone, for example, the IMEI for
7703 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7704 *
7705 * <p>Requires Permission:
7706 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7707 */
7708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007709 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007710 try {
7711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7712 } catch (SecurityException se) {
7713 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7714 throw new SecurityException("Package " + callingPackage + " does not belong to "
7715 + Binder.getCallingUid());
7716 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007717 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007718 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007719 return null;
7720 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007721 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007722 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007723 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007724 return null;
7725 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726
7727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 return phone.getDeviceId();
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
7732 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007733 }
7734
Ping Sunc67b7c22016-03-02 19:16:45 +08007735 /**
7736 * {@hide}
7737 * Returns the IMS Registration Status on a particular subid
7738 *
7739 * @param subId
7740 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007741 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007742 Phone phone = getPhone(subId);
7743 if (phone != null) {
7744 return phone.isImsRegistered();
7745 } else {
7746 return false;
7747 }
7748 }
7749
Santos Cordon7a1885b2015-02-03 11:15:19 -08007750 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007751 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007752 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007754 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007755 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7756 }
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
7762 }
7763 }
7764
7765 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007766 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007767 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007768 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007769 mApp,
7770 subscriptionId,
7771 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007772 final long identity = Binder.clearCallingIdentity();
7773 try {
7774 Phone phone = getPhone(subscriptionId);
7775 if (phone == null) {
7776 return null;
7777 }
7778 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7779 } finally {
7780 Binder.restoreCallingIdentity(identity);
7781 }
7782 }
7783
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007784 /**
7785 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007786 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007787 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 final long identity = Binder.clearCallingIdentity();
7789 try {
7790 Phone phone = getPhone(subId);
7791 if (phone != null) {
7792 return phone.isWifiCallingEnabled();
7793 } else {
7794 return false;
7795 }
7796 } finally {
7797 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007798 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007799 }
7800
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007801 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007802 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007803 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007804 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 final long identity = Binder.clearCallingIdentity();
7806 try {
7807 Phone phone = getPhone(subId);
7808 if (phone != null) {
7809 return phone.isVideoEnabled();
7810 } else {
7811 return false;
7812 }
7813 } finally {
7814 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007815 }
7816 }
7817
7818 /**
7819 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7820 * defined in {@link ImsRegistrationImplBase}.
7821 */
7822 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 final long identity = Binder.clearCallingIdentity();
7824 try {
7825 Phone phone = getPhone(subId);
7826 if (phone != null) {
7827 return phone.getImsRegistrationTech();
7828 } else {
7829 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7830 }
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007833 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007834 }
7835
Stuart Scott8eef64f2015-04-08 15:13:54 -07007836 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007837 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007838 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007839 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7840 return;
7841 }
Kai Shif70f46f2021-03-03 13:59:46 -08007842 Phone defaultPhone = getDefaultPhone();
7843 if (defaultPhone != null) {
7844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7845 mApp, getDefaultPhone().getSubId(), "factoryReset");
7846 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007847 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007848
Svet Ganovcc087f82015-05-12 20:35:54 -07007849 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007850 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7851 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007852 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007853 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007854 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007855 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007856 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007857 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007858 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007859 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007860 // There has been issues when Sms raw table somehow stores orphan
7861 // fragments. They lead to garbled message when new fragments come
7862 // in and combined with those stale ones. In case this happens again,
7863 // user can reset all network settings which will clean up this table.
7864 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007865 // Clean up IMS settings as well here.
7866 int slotId = getSlotIndex(subId);
7867 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7868 ImsManager.getInstance(mApp, slotId).factoryReset();
7869 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007870
Kai Shif70f46f2021-03-03 13:59:46 -08007871 if (defaultPhone == null) {
7872 return;
7873 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007874 // Erase modem config if erase modem on network setting is enabled.
7875 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7876 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7877 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007878 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007879 }
Kai Shif70f46f2021-03-03 13:59:46 -08007880
7881 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007882 } finally {
7883 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007884 }
7885 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007886
SongFerngWangfd89b102021-05-27 22:44:54 +08007887 @VisibleForTesting
7888 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7889 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7890 return;
7891 }
7892 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7893 RILConstants.PREFERRED_NETWORK_MODE);
7894 SubscriptionManager.setSubscriptionProperty(subId,
7895 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7896 "user=" + defaultNetworkType);
7897 phone.loadAllowedNetworksFromSubscriptionDatabase();
7898 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7899 defaultNetworkType, null);
7900 }
7901
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007902 private void cleanUpSmsRawTable(Context context) {
7903 ContentResolver resolver = context.getContentResolver();
7904 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7905 resolver.delete(uri, null, null);
7906 }
7907
Narayan Kamath1c496c22015-04-16 14:40:19 +01007908 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007909 public String getSimLocaleForSubscriber(int subId) {
7910 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7911 final Phone phone = getPhone(subId);
7912 if (phone == null) {
7913 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007914 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916 final long identity = Binder.clearCallingIdentity();
7917 try {
Jack Yu285100e2022-12-02 22:48:35 -08007918 SubscriptionInfo info;
7919 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7920 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7921 phone.getContext().getOpPackageName(),
7922 phone.getContext().getAttributionTag());
7923 if (info == null) {
7924 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7925 return null;
7926 }
7927 } else {
7928 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7929 phone.getContext().getOpPackageName(),
7930 phone.getContext().getAttributionTag());
7931 if (info == null) {
7932 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7933 return null;
7934 }
chen xu6291c472019-02-04 12:55:53 -08007935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 // Try and fetch the locale from the carrier properties or from the SIM language
7937 // preferences (EF-PL and EF-LI)...
7938 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007940 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7941 if (localeFromDefaultSim != null) {
7942 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7943 if (DBG) log("Using locale from subId: " + subId + " locale: "
7944 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007945 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007946 } else {
7947 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 }
7949 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 // The SIM language preferences only store a language (e.g. fr = French), not an
7952 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7953 // the SIM and carrier preferences does not include a country we add the country
7954 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007955 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007957 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007958 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 }
7960
7961 if (DBG) log("No locale found - returning null");
7962 return null;
7963 } finally {
7964 Binder.restoreCallingIdentity(identity);
7965 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007966 }
7967
tom hsu0b59d292022-09-29 23:49:21 +08007968 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007969 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007970 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007971 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007972 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007973 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7974 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007975 Locale.forLanguageTag(localeTag).getCountry())) {
7976 return localeTag;
7977 }
7978 }
7979 return inputLocale.toLanguageTag();
7980 }
7981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007982 /**
7983 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7984 */
7985 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007986 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7987 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7988 mApp.getOpPackageName(), mApp.getAttributionTag());
7989 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007990 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007991 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007992 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007993
Gary Jian3aa9a762022-01-24 16:41:19 +08007994 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7995 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007996
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007997 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007998 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7999 * representing the state of the modem.
8000 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008001 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8002 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008003 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008004 */
8005 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008006 public void requestModemActivityInfo(ResultReceiver result) {
8007 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008012 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 } finally {
8014 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008015 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008016 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008017
Siddharth Rayb8114062018-06-17 15:02:38 -07008018 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
8019 // less than total activity duration.
8020 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8021 if (info == null) {
8022 return false;
8023 }
8024 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008025 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
8026 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8027
Siddharth Rayb8114062018-06-17 15:02:38 -07008028 return (info.isValid()
8029 && (info.getSleepTimeMillis() <= activityDurationMs)
8030 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07008031 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07008032 && (totalTxTimeMs <= activityDurationMs));
8033 }
8034
Gary Jian3aa9a762022-01-24 16:41:19 +08008035 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8036 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8037 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8038 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8039
8040 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8041 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8042 }
8043
8044 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8045 mLastModemActivityInfo.setReceiveTimeMillis(
8046 rat,
8047 freq,
8048 info.getReceiveTimeMillis(rat, freq)
8049 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8050 }
8051
8052 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8053 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8054 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8055 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8056
8057 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8058 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8059 }
8060 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8061 mLastModemActivityInfo.setReceiveTimeMillis(
8062 rat,
8063 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8064 }
8065
8066 /**
8067 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8068 * @param info recent ModemActivityInfo
8069 */
8070 private void mergeModemActivityInfo(ModemActivityInfo info) {
8071 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008072 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008073 boolean matched;
8074 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8075 matched = false;
8076 int rat = info.getSpecificInfoRat(i);
8077 int freq = info.getSpecificInfoFrequencyRange(i);
8078 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8079 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8080 //if it already exists
8081 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8082 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8083 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8084 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8085 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8086 updateLastModemActivityInfo(info, rat, freq);
8087 matched = true;
8088 }
8089 } else {
8090 updateLastModemActivityInfo(info, rat);
8091 matched = true;
8092 }
8093 }
8094 }
8095
8096 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008097 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008098 new ActivityStatsTechSpecificInfo(
8099 rat,
8100 freq,
8101 info.getTransmitTimeMillis(rat, freq),
8102 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008103 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008104 }
8105 }
8106 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8107 mLastModemActivitySpecificInfo =
8108 new ActivityStatsTechSpecificInfo[merged.size()];
8109 merged.toArray(mLastModemActivitySpecificInfo);
8110
8111 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8112 mLastModemActivityInfo.setSleepTimeMillis(
8113 info.getSleepTimeMillis()
8114 + mLastModemActivityInfo.getSleepTimeMillis());
8115 mLastModemActivityInfo.setIdleTimeMillis(
8116 info.getIdleTimeMillis()
8117 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008118
8119 mLastModemActivityInfo =
8120 new ModemActivityInfo(
8121 mLastModemActivityInfo.getTimestampMillis(),
8122 mLastModemActivityInfo.getSleepTimeMillis(),
8123 mLastModemActivityInfo.getIdleTimeMillis(),
8124 mLastModemActivitySpecificInfo);
8125 }
8126
8127 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8128 ActivityStatsTechSpecificInfo[] info) {
8129 int infoSize = info.length;
8130 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8131 for (int i = 0; i < infoSize; i++) {
8132 ret[i] = new ActivityStatsTechSpecificInfo(
8133 info[i].getRat(), info[i].getFrequencyRange(),
8134 info[i].getTransmitTimeMillis(),
8135 (int) info[i].getReceiveTimeMillis());
8136 }
8137 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008138 }
8139
Jack Yu85bd38a2015-11-09 11:34:32 -08008140 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008141 * Returns the service state information on specified subscription.
8142 */
8143 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008144 public ServiceState getServiceStateForSubscriber(int subId,
8145 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8146 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008148 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008149 return null;
8150 }
8151
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008152 boolean hasFinePermission = false;
8153 boolean hasCoarsePermission = false;
8154 if (!renounceFineLocationAccess) {
8155 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8156 LocationAccessPolicy.checkLocationPermission(mApp,
8157 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8158 .setCallingPackage(callingPackage)
8159 .setCallingFeatureId(callingFeatureId)
8160 .setCallingPid(Binder.getCallingPid())
8161 .setCallingUid(Binder.getCallingUid())
8162 .setMethod("getServiceStateForSubscriber")
8163 .setLogAsInfo(true)
8164 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8165 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8166 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8167 .build());
8168 hasFinePermission =
8169 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8170 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008171
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008172 if (!renounceCoarseLocationAccess) {
8173 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8174 LocationAccessPolicy.checkLocationPermission(mApp,
8175 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8176 .setCallingPackage(callingPackage)
8177 .setCallingFeatureId(callingFeatureId)
8178 .setCallingPid(Binder.getCallingPid())
8179 .setCallingUid(Binder.getCallingUid())
8180 .setMethod("getServiceStateForSubscriber")
8181 .setLogAsInfo(true)
8182 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8183 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8184 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8185 .build());
8186 hasCoarsePermission =
8187 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8188 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008189
Jack Yu479f40e2020-10-27 21:29:25 -07008190 final Phone phone = getPhone(subId);
8191 if (phone == null) {
8192 return null;
8193 }
8194
Jordan Liu0f2bc442020-11-18 16:47:37 -08008195 final long identity = Binder.clearCallingIdentity();
8196
Jack Yu479f40e2020-10-27 21:29:25 -07008197 boolean isCallingPackageDataService = phone.getDataServicePackages()
8198 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008200 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008201 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8202 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8203 .getSubscriptionInfoInternal(subId);
8204 if (subInfo == null || !subInfo.isActive()) {
8205 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8206 + "subId=" + subId);
8207 return null;
8208 }
8209 } else {
8210 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8211 callingFeatureId)) {
8212 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8213 + "subId=" + subId);
8214 return null;
8215 }
Jordan Liuc437b192020-08-17 10:59:12 -07008216 }
8217
Hall Liuf19c44f2018-11-27 14:38:17 -08008218 ServiceState ss = phone.getServiceState();
8219
8220 // Scrub out the location info in ServiceState depending on what level of access
8221 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008222 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008223 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8224 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008228 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008229
8230 /**
8231 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8232 *
8233 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8234 * voicemail ringtone.
8235 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8236 * PhoneAccount.
8237 */
8238 @Override
8239 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240 final long identity = Binder.clearCallingIdentity();
8241 try {
8242 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8243 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008244 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008251 }
8252
8253 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008254 * Sets the per-account voicemail ringtone.
8255 *
8256 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8257 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8258 *
8259 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8260 * voicemail ringtone.
8261 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8262 * PhoneAccount.
8263 */
8264 @Override
8265 public void setVoicemailRingtoneUri(String callingPackage,
8266 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008267 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008269 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8270 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8272 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8273 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
8278 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8279 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008280 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 }
8282 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008285 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008286 }
8287
8288 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008289 * Returns whether vibration is set for voicemail notification in Phone settings.
8290 *
8291 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8292 * voicemail vibration setting.
8293 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8294 */
8295 @Override
8296 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 final long identity = Binder.clearCallingIdentity();
8298 try {
8299 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8300 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8305 } finally {
8306 Binder.restoreCallingIdentity(identity);
8307 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008308 }
8309
Youhan Wange64578a2016-05-02 15:32:42 -07008310 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008311 * Sets the per-account voicemail vibration.
8312 *
8313 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8314 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8315 *
8316 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8317 * voicemail vibration setting.
8318 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8319 * specific PhoneAccount.
8320 */
8321 @Override
8322 public void setVoicemailVibrationEnabled(String callingPackage,
8323 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008324 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008325 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008326 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8327 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8329 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8330 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008331 }
8332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8336 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008337 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 }
8339 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008342 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008343 }
8344
8345 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008346 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8347 *
8348 * @throws SecurityException if the caller does not have the required permission
8349 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008350 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008351 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008352 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008353 }
8354
8355 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008356 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8357 * permission.
8358 *
8359 * @throws SecurityException if the caller does not have the required permission
8360 */
8361 private void enforceSendSmsPermission() {
8362 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8363 }
8364
8365 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008366 * Make sure either called from same process as self (phone) or IPC caller has interact across
8367 * users permission.
8368 *
8369 * @throws SecurityException if the caller does not have the required permission
8370 */
8371 private void enforceInteractAcrossUsersPermission(String message) {
8372 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8373 }
8374
8375 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008376 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008377 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008378 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008379 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008380 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008384 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 if (componentName == null) {
8386 throw new SecurityException(
8387 "Caller not current active visual voicemail package[null]");
8388 }
8389 String vvmPackage = componentName.getPackageName();
8390 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008391 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 }
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008395 }
8396 }
8397
8398 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008399 * Return the application ID for the app type.
8400 *
8401 * @param subId the subscription ID that this request applies to.
8402 * @param appType the uicc app type.
8403 * @return Application ID for specificied app type, or null if no uicc.
8404 */
8405 @Override
8406 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008407 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008408 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409
8410 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008411 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 if (phone == null) {
8413 return null;
8414 }
8415 String aid = null;
8416 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008417 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008418 .getApplicationByType(appType).getAid();
8419 } catch (Exception e) {
8420 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8421 }
8422 return aid;
8423 } finally {
8424 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008425 }
Youhan Wange64578a2016-05-02 15:32:42 -07008426 }
8427
Youhan Wang4001d252016-05-11 10:29:41 -07008428 /**
8429 * Return the Electronic Serial Number.
8430 *
8431 * @param subId the subscription ID that this request applies to.
8432 * @return ESN or null if error.
8433 */
8434 @Override
8435 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008436 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008437 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438
8439 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008440 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441 if (phone == null) {
8442 return null;
8443 }
8444 String esn = null;
8445 try {
8446 esn = phone.getEsn();
8447 } catch (Exception e) {
8448 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8449 }
8450 return esn;
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008453 }
Youhan Wang4001d252016-05-11 10:29:41 -07008454 }
8455
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008456 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008457 * Return the Preferred Roaming List Version.
8458 *
8459 * @param subId the subscription ID that this request applies to.
8460 * @return PRLVersion or null if error.
8461 */
8462 @Override
8463 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008464 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008465 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466
8467 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008468 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 if (phone == null) {
8470 return null;
8471 }
8472 String cdmaPrlVersion = null;
8473 try {
8474 cdmaPrlVersion = phone.getCdmaPrlVersion();
8475 } catch (Exception e) {
8476 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8477 }
8478 return cdmaPrlVersion;
8479 } finally {
8480 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008481 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008482 }
8483
8484 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008485 * Get snapshot of Telephony histograms
8486 * @return List of Telephony histograms
8487 * @hide
8488 */
8489 @Override
8490 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8492 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493
8494 final long identity = Binder.clearCallingIdentity();
8495 try {
8496 return RIL.getTelephonyRILTimingHistograms();
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008500 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008501
8502 /**
8503 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008504 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8505 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008506 * Require system privileges. In the future we may add this to carrier APIs.
8507 *
Michele Berionne482f8202018-11-27 18:57:59 -08008508 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008509 */
8510 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008511 @TelephonyManager.SetCarrierRestrictionResult
8512 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008513 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008515
Michele Berionne482f8202018-11-27 18:57:59 -08008516 if (carrierRestrictionRules == null) {
8517 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008518 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520 final long identity = Binder.clearCallingIdentity();
8521 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008522 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008523 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 } finally {
8525 Binder.restoreCallingIdentity(identity);
8526 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008527 }
8528
8529 /**
8530 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008531 * Get the allowed carrier list and the excluded carrier list, including the priority between
8532 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008533 * Require system privileges. In the future we may add this to carrier APIs.
8534 *
Michele Berionne482f8202018-11-27 18:57:59 -08008535 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008536 */
8537 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008538 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008539 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541
8542 final long identity = Binder.clearCallingIdentity();
8543 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008544 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8545 if (response instanceof CarrierRestrictionRules) {
8546 return (CarrierRestrictionRules) response;
8547 }
8548 // Response is an Exception of some kind,
8549 // which is signalled to the user as a NULL retval
8550 return null;
8551 } catch (Exception e) {
8552 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8553 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008557 }
8558
fionaxu59545b42016-05-25 15:53:37 -07008559 /**
fionaxu59545b42016-05-25 15:53:37 -07008560 * Action set from carrier signalling broadcast receivers to enable/disable radio
8561 * @param subId the subscription ID that this action applies to.
8562 * @param enabled control enable or disable radio.
8563 * {@hide}
8564 */
8565 @Override
8566 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8567 enforceModifyPermission();
8568 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569
8570 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008571 if (phone == null) {
8572 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8573 return;
8574 }
8575 try {
8576 phone.carrierActionSetRadioEnabled(enabled);
8577 } catch (Exception e) {
8578 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 } finally {
8580 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008581 }
8582 }
8583
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008584 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008585 * Enable or disable Voice over NR (VoNR)
8586 * @param subId the subscription ID that this action applies to.
8587 * @param enabled enable or disable VoNR.
8588 * @return operation result.
8589 */
8590 @Override
8591 public int setVoNrEnabled(int subId, boolean enabled) {
8592 enforceModifyPermission();
8593 final Phone phone = getPhone(subId);
8594
8595 final long identity = Binder.clearCallingIdentity();
8596 if (phone == null) {
8597 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8598 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8599 }
8600
8601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8602 try {
8603 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8604 workSource);
8605 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008606
8607 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8608 if (DBG) {
8609 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8610 }
8611 SubscriptionManager.setSubscriptionProperty(
8612 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8613 (enabled ? "1" : "0"));
8614 }
8615
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008616 return result;
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
8620 }
8621
8622 /**
8623 * Is voice over NR enabled
8624 * @return true if VoNR is enabled else false
8625 */
8626 @Override
8627 public boolean isVoNrEnabled(int subId) {
8628 enforceReadPrivilegedPermission("isVoNrEnabled");
8629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8633 null, subId, workSource);
8634 if (DBG) log("isVoNrEnabled: " + isEnabled);
8635 return isEnabled;
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
8639 }
8640
8641 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008642 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8643 * network status based on which carrier apps could apply actions accordingly,
8644 * enable/disable default url handler for example.
8645 *
8646 * @param subId the subscription ID that this action applies to.
8647 * @param report control start/stop reporting the default network status.
8648 * {@hide}
8649 */
8650 @Override
8651 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8652 enforceModifyPermission();
8653 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008654
8655 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008656 if (phone == null) {
8657 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8658 return;
8659 }
8660 try {
8661 phone.carrierActionReportDefaultNetworkStatus(report);
8662 } catch (Exception e) {
8663 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 } finally {
8665 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008666 }
8667 }
8668
8669 /**
fionaxud9622282017-07-17 17:51:30 -07008670 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8671 * @param subId the subscription ID that this action applies to.
8672 * {@hide}
8673 */
8674 @Override
8675 public void carrierActionResetAll(int subId) {
8676 enforceModifyPermission();
8677 final Phone phone = getPhone(subId);
8678 if (phone == null) {
8679 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8680 return;
8681 }
8682 try {
8683 phone.carrierActionResetAll();
8684 } catch (Exception e) {
8685 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8686 }
8687 }
8688
8689 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008690 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8691 * bug report is being generated.
8692 */
8693 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008694 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008695 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8696 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008697 writer.println("Permission Denial: can't dump Phone from pid="
8698 + Binder.getCallingPid()
8699 + ", uid=" + Binder.getCallingUid()
8700 + "without permission "
8701 + android.Manifest.permission.DUMP);
8702 return;
8703 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008704 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008705 }
Jack Yueb89b242016-06-22 13:27:47 -07008706
Brad Ebingerdac2f002018-04-03 15:17:52 -07008707 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008708 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8709 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8710 @NonNull String[] args) {
8711 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8712 this, in.getFileDescriptor(), out.getFileDescriptor(),
8713 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008714 }
8715
Jack Yueb89b242016-06-22 13:27:47 -07008716 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008717 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008718 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008719 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008720 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008721 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008722 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008723 */
8724 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008725 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008726 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008727 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8728 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8729 try {
8730 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008731 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008732 } catch (SecurityException se) {
8733 enforceModifyPermission();
8734 }
8735 } else {
8736 enforceModifyPermission();
8737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008738
8739 final long identity = Binder.clearCallingIdentity();
8740 try {
8741 Phone phone = getPhone(subId);
8742 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008743 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8744 phone.carrierActionSetMeteredApnsEnabled(enabled);
8745 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008746 phone.getDataSettingsManager().setDataEnabled(
8747 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008749 }
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008752 }
8753 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008754
8755 /**
8756 * Get Client request stats
8757 * @return List of Client Request Stats
8758 * @hide
8759 */
8760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008761 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8762 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008764 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008765 return null;
8766 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008767 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008769 final long identity = Binder.clearCallingIdentity();
8770 try {
8771 if (phone != null) {
8772 return phone.getClientRequestStats();
8773 }
8774
8775 return null;
8776 } finally {
8777 Binder.restoreCallingIdentity(identity);
8778 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008779 }
8780
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008781 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008782 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008783 if (uid == Process.ROOT_UID && packageName == null) {
8784 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8785 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8786 // exception. ROOT_UID seems not to have a valid package name returned by
8787 // PackageManager, so just fake it here to avoid issues when running telephony shell
8788 // commands that plumb through the RIL as root, like so:
8789 // $ adb root
8790 // $ adb shell cmd phone ...
8791 packageName = "root";
8792 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008793 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008794 }
Jack Yueb4124c2017-02-16 15:32:43 -08008795
8796 /**
Grace Chen70990072017-03-24 17:21:30 -07008797 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008798 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008799 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008800 * @param state State of SIM (power down, power up, pass through)
8801 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8802 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8803 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008804 *
8805 **/
8806 @Override
Grace Chen70990072017-03-24 17:21:30 -07008807 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008808 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008809 Phone phone = PhoneFactory.getPhone(slotIndex);
8810
vagdeviaf9a5b92018-08-15 16:01:53 -07008811 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008813 final long identity = Binder.clearCallingIdentity();
8814 try {
8815 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008816 phone.setSimPowerState(state, null, workSource);
8817 }
8818 } finally {
8819 Binder.restoreCallingIdentity(identity);
8820 }
8821 }
8822
8823 /**
8824 * Set SIM card power state.
8825 *
8826 * @param slotIndex SIM slot id.
8827 * @param state State of SIM (power down, power up, pass through)
8828 * @param callback callback to trigger after success or failure
8829 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8830 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8831 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8832 *
8833 **/
8834 @Override
8835 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8836 IIntegerConsumer callback) {
8837 enforceModifyPermission();
8838 Phone phone = PhoneFactory.getPhone(slotIndex);
8839
8840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8841
8842 final long identity = Binder.clearCallingIdentity();
8843 try {
8844 if (phone != null) {
8845 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8846 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008847 }
8848 } finally {
8849 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008850 }
8851 }
Shuo Qiandd210312017-04-12 22:11:33 +00008852
Tyler Gunn65d45c22017-06-05 11:22:26 -07008853 private boolean isUssdApiAllowed(int subId) {
8854 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008855 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008856 if (configManager == null) {
8857 return false;
8858 }
8859 PersistableBundle pb = configManager.getConfigForSubId(subId);
8860 if (pb == null) {
8861 return false;
8862 }
8863 return pb.getBoolean(
8864 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8865 }
8866
Shuo Qiandd210312017-04-12 22:11:33 +00008867 /**
8868 * Check if phone is in emergency callback mode
8869 * @return true if phone is in emergency callback mode
8870 * @param subId sub id
8871 */
goneil9c5f4872017-12-05 14:07:56 -08008872 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008873 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008874 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008875 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876
8877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 if (phone != null) {
8880 return phone.isInEcm();
8881 } else {
8882 return false;
8883 }
8884 } finally {
8885 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008886 }
8887 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008888
8889 /**
8890 * Get the current signal strength information for the given subscription.
8891 * Because this information is not updated when the device is in a low power state
8892 * it should not be relied-upon to be current.
8893 * @param subId Subscription index
8894 * @return the most recent cached signal strength info from the modem
8895 */
8896 @Override
8897 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 Phone p = getPhone(subId);
8901 if (p == null) {
8902 return null;
8903 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008905 return p.getSignalStrength();
8906 } finally {
8907 Binder.restoreCallingIdentity(identity);
8908 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008909 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008910
Pengquan Meng77b7f132018-08-22 14:49:57 -07008911 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008912 * Get the current modem radio state for the given slot.
8913 * @param slotIndex slot index.
8914 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008915 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008916 * @return the current radio power state from the modem
8917 */
8918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008919 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008920 Phone phone = PhoneFactory.getPhone(slotIndex);
8921 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8923 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008924 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8925 }
8926
8927 final long identity = Binder.clearCallingIdentity();
8928 try {
8929 return phone.getRadioPowerState();
8930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
8934 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8935 }
8936
8937 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008938 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8939 *
8940 * <p>Requires one of the following permissions:
8941 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008942 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008943 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8944 * privileges.
8945 *
8946 * @param subId subscription id
8947 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8948 * {@code false}.
8949 */
8950 @Override
8951 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008952 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008953 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008954 try {
8955 mApp.enforceCallingOrSelfPermission(
8956 android.Manifest.permission.ACCESS_NETWORK_STATE,
8957 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008958 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008959 mApp.enforceCallingOrSelfPermission(
8960 permission.READ_BASIC_PHONE_STATE, functionName);
8961 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008962 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008963 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008964 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008965 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008966
Pengquan Menga1bb6272018-09-06 09:59:22 -07008967 boolean isEnabled = false;
8968 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008969 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008970 Phone phone = getPhone(subId);
8971 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008972 } finally {
8973 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008974 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008975 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008976 }
8977
8978
8979 /**
8980 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8981 *
8982 * <p> Requires permission:
8983 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8984 * privileges.
8985 *
8986 * @param subId subscription id
8987 * @param isEnabled {@code true} means enable, {@code false} means disable.
8988 */
8989 @Override
8990 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8992 mApp, subId, "setDataRoamingEnabled");
8993
Pengquan Menga1bb6272018-09-06 09:59:22 -07008994 final long identity = Binder.clearCallingIdentity();
8995 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008996 Phone phone = getPhone(subId);
8997 if (phone != null) {
8998 phone.setDataRoamingEnabled(isEnabled);
8999 }
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009002 }
9003 }
9004
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009005 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009006 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009007 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009008 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009009 mApp, subId, "isManualNetworkSelectionAllowed");
9010
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009011 boolean isAllowed = true;
9012 final long identity = Binder.clearCallingIdentity();
9013 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009014 Phone phone = getPhone(subId);
9015 if (phone != null) {
9016 isAllowed = phone.isCspPlmnEnabled();
9017 }
9018 } finally {
9019 Binder.restoreCallingIdentity(identity);
9020 }
9021 return isAllowed;
9022 }
9023
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009024 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9025 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009026 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009027 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009028 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009029 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9030 if (phone == null) {
9031 return false;
9032 }
9033 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9034 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9035 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009036 }
9037
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009038 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009039 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009040 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009041 mApp.getSystemService(AppOpsManager.class)
9042 .checkPackage(Binder.getCallingUid(), callingPackage);
9043
Jordan Liu1e142fc2019-04-22 15:10:43 -07009044 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009045 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009046 try {
9047 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009048 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009049 } catch (SecurityException e) {
9050 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9051 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009052 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009053 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009054 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009055 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009056 }
sandeepjsb6c87872021-09-27 15:34:44 +00009057 // checking compatibility, if calling app's target SDK is T and beyond.
9058 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9059 Binder.getCallingUid())) {
9060 isIccIdAccessRestricted = true;
9061 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009062 final long identity = Binder.clearCallingIdentity();
9063 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009064 UiccController uiccController = UiccController.getInstance();
9065 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009066 if (hasReadPermission) {
9067 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009068 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009069
9070 // Remove private info if the caller doesn't have access
9071 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9072 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009073 //setting the value after compatibility check
9074 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009075 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9076 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009077 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009078 if (card == null) {
9079 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009080 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009081 continue;
9082 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009083 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9084 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009085 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009086 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009087 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009088 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9089 for (UiccPortInfo portInfo : portInfos) {
9090 UiccPort port = uiccController.getUiccPortForSlot(
9091 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9092 if (port == null) {
9093 // assume no access if port is null
9094 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9095 continue;
9096 }
9097 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9098 uiccPortInfos.add(portInfo);
9099 } else {
9100 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9101 }
9102 }
9103 filteredInfos.add(new UiccCardInfo(
9104 cardInfo.isEuicc(),
9105 cardInfo.getCardId(),
9106 null,
9107 cardInfo.getPhysicalSlotIndex(),
9108 cardInfo.isRemovable(),
9109 cardInfo.isMultipleEnabledProfilesSupported(),
9110 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009111 }
9112 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009113 } finally {
9114 Binder.restoreCallingIdentity(identity);
9115 }
9116 }
9117
sandeepjsb6c87872021-09-27 15:34:44 +00009118 /**
9119 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9120 * generally private and require carrier privileges to view.
9121 *
9122 * @hide
9123 */
9124 @NonNull
9125 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9126 List<UiccPortInfo> portinfo = new ArrayList<>();
9127 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9128 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9129 }
9130 return new UiccCardInfo(
9131 cardInfo.isEuicc(),
9132 cardInfo.getCardId(),
9133 null,
9134 cardInfo.getPhysicalSlotIndex(),
9135 cardInfo.isRemovable(),
9136 cardInfo.isMultipleEnabledProfilesSupported(),
9137 portinfo
9138 );
9139 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009140
sandeepjsb6c87872021-09-27 15:34:44 +00009141 /**
9142 * @hide
9143 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9144 * These values are generally private and require carrier privileges to view.
9145 */
9146 @NonNull
9147 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9148 return new UiccPortInfo(
9149 UiccPortInfo.ICCID_REDACTED,
9150 portInfo.getPortIndex(),
9151 portInfo.getLogicalSlotIndex(),
9152 portInfo.isActive()
9153 );
9154 }
9155 @Override
9156 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009157 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009158 mApp.getSystemService(AppOpsManager.class)
9159 .checkPackage(Binder.getCallingUid(), callingPackage);
9160
sandeepjsb6c87872021-09-27 15:34:44 +00009161 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009162
Aman Guptaf3c90b32022-03-17 04:54:16 +00009163 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9164 // we are reading iccId which is PII data.
9165 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009166
9167 // checking compatibility, if calling app's target SDK is T and beyond.
9168 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9169 Binder.getCallingUid())) {
9170 isLogicalSlotAccessRestricted = true;
9171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009172 final long identity = Binder.clearCallingIdentity();
9173 try {
9174 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009175 if (slots == null || slots.length == 0) {
9176 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009177 return null;
9178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009179 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9180 for (int i = 0; i < slots.length; i++) {
9181 UiccSlot slot = slots[i];
9182 if (slot == null) {
9183 continue;
9184 }
9185
Jordan Liu7be7e652019-05-06 18:55:02 +00009186 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009187 UiccCard card = slot.getUiccCard();
9188 if (card != null) {
9189 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009190 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009191 cardId = slot.getEid();
9192 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009193 // If cardId is null, use iccId of default port as cardId.
9194 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009196 }
9197
Jordan Liu857451f2019-05-09 16:35:35 -07009198 if (cardId != null) {
9199 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9200 // if cardId is an EID, it's all digits so this is fine
9201 cardId = IccUtils.stripTrailingFs(cardId);
9202 }
9203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009204 int cardState = 0;
9205 switch (slot.getCardState()) {
9206 case CARDSTATE_ABSENT:
9207 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9208 break;
9209 case CARDSTATE_PRESENT:
9210 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9211 break;
9212 case CARDSTATE_ERROR:
9213 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9214 break;
9215 case CARDSTATE_RESTRICTED:
9216 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9217 break;
9218 default:
9219 break;
9220
9221 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009222 List<UiccPortInfo> portInfos = new ArrayList<>();
9223 int[] portIndexes = slot.getPortList();
9224 for (int portIdx : portIndexes) {
9225 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009226 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009227 portInfos.add(new UiccPortInfo(iccId, portIdx,
9228 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009230 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009231 slot.isEuicc(),
9232 cardId,
9233 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009234 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009235 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009236 //setting the value after compatibility check
9237 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009238 }
9239 return infos;
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009242 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009243 }
9244
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009245 /* Returns null if doesn't have read permission or carrier privilege access. */
9246 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9247 boolean hasReadPermission) {
9248 String iccId = slot.getIccId(portIndex);
9249 if (hasReadPermission) { // if has read permission
9250 return iccId;
9251 } else {
9252 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9253 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9254 // if no read permission, checking carrier privilege access
9255 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9256 return iccId;
9257 }
9258 }
9259 }
9260 // No read permission or carrier privilege access.
9261 return UiccPortInfo.ICCID_REDACTED;
9262 }
9263
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009264 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009265 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009266 public boolean switchSlots(int[] physicalSlots) {
9267 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009268
9269 final long identity = Binder.clearCallingIdentity();
9270 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009271 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9272 for (int i = 0; i < physicalSlots.length; i++) {
9273 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9274 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9275 physicalSlots[i], i));
9276 }
9277 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009278 } finally {
9279 Binder.restoreCallingIdentity(identity);
9280 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009281 }
Jack Yu4c988042018-02-27 15:30:01 -08009282
9283 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009284 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9285 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9286 enforceModifyPermission();
9287
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009290 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009291 } finally {
9292 Binder.restoreCallingIdentity(identity);
9293 }
9294 }
9295
9296 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009297 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009298 final long identity = Binder.clearCallingIdentity();
9299 try {
9300 return UiccController.getInstance().getCardIdForDefaultEuicc();
9301 } finally {
9302 Binder.restoreCallingIdentity(identity);
9303 }
9304 }
9305
Pengquan Meng85728fb2018-03-12 16:31:21 -07009306 /**
goneil47ffb6e2018-04-06 15:40:58 -07009307 * A test API to reload the UICC profile.
9308 *
9309 * <p>Requires that the calling app has permission
9310 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9311 * @hide
9312 */
9313 @Override
9314 public void refreshUiccProfile(int subId) {
9315 enforceModifyPermission();
9316
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
9319 Phone phone = getPhone(subId);
9320 if (phone == null) {
9321 return;
9322 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009323 UiccPort uiccPort = phone.getUiccPort();
9324 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009325 return;
9326 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009327 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009328 if (uiccProfile == null) {
9329 return;
9330 }
9331 uiccProfile.refresh();
9332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
9336
9337 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009338 * Returns false if the mobile data is disabled by default, otherwise return true.
9339 */
9340 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009341 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009342 }
9343
9344 /**
9345 * Returns true if the data roaming is enabled by default, i.e the system property
9346 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9347 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9348 */
9349 private boolean getDefaultDataRoamingEnabled(int subId) {
9350 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009351 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009352 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009353 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9354 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9355 return isDataRoamingEnabled;
9356 }
9357
9358 /**
9359 * Returns the default network type for the given {@code subId}, if the default network type is
9360 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9361 */
9362 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009363 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009364 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009365 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9366 return list.get(phoneId);
9367 }
9368 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009369 }
fionaxua13278b2018-03-21 00:08:13 -07009370
9371 @Override
9372 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009373 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009374 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009375
9376 final long identity = Binder.clearCallingIdentity();
9377 try {
9378 final Phone phone = getPhone(subId);
9379 if (phone == null) {
9380 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9381 return;
9382 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009383 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9384 if (cpt != null) {
9385 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9386 }
9387 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009388 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9389 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009390 if (carrierPrivilegeRules == null) {
9391 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9392 } else {
9393 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009395 } finally {
9396 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009397 }
fionaxua13278b2018-03-21 00:08:13 -07009398 }
9399
9400 @Override
9401 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009402 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009403
9404 final long identity = Binder.clearCallingIdentity();
9405 try {
9406 final Phone phone = getPhone(subId);
9407 if (phone == null) {
9408 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9409 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9410 }
9411 return phone.getCarrierIdListVersion();
9412 } finally {
9413 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009414 }
fionaxua13278b2018-03-21 00:08:13 -07009415 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009416
9417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009418 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9419 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009421 mApp, subId, callingPackage, callingFeatureId,
9422 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009423 return -1;
9424 }
9425
9426 final long identity = Binder.clearCallingIdentity();
9427 try {
9428 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9429 } finally {
9430 Binder.restoreCallingIdentity(identity);
9431 }
9432 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009433
9434 @Override
9435 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009436 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009437 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009438 mApp, subId, "getCdmaRoamingMode");
9439
9440 final long identity = Binder.clearCallingIdentity();
9441 try {
9442 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9443 } finally {
9444 Binder.restoreCallingIdentity(identity);
9445 }
9446 }
9447
9448 @Override
9449 public boolean setCdmaRoamingMode(int subId, int mode) {
9450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9451 mApp, subId, "setCdmaRoamingMode");
9452
9453 final long identity = Binder.clearCallingIdentity();
9454 try {
9455 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9456 } finally {
9457 Binder.restoreCallingIdentity(identity);
9458 }
9459 }
9460
9461 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009462 public int getCdmaSubscriptionMode(int subId) {
9463 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009464 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009465 mApp, subId, "getCdmaSubscriptionMode");
9466
9467 final long identity = Binder.clearCallingIdentity();
9468 try {
9469 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9470 } finally {
9471 Binder.restoreCallingIdentity(identity);
9472 }
9473 }
9474
9475 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009476 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9478 mApp, subId, "setCdmaSubscriptionMode");
9479
9480 final long identity = Binder.clearCallingIdentity();
9481 try {
9482 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
9486 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009487
sqianc5eccab2018-10-19 18:46:41 -07009488 @Override
sqian8c685422019-02-22 15:55:18 -08009489 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009490 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009492 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9493 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009494 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9495 }
9496 final long identity = Binder.clearCallingIdentity();
9497 try {
sqian854d44b2018-12-12 16:48:18 -08009498 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9499 for (Phone phone: PhoneFactory.getPhones()) {
9500 if (phone.getEmergencyNumberTracker() != null
9501 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9502 emergencyNumberListInternal.put(
9503 phone.getSubId(),
9504 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9505 }
sqian11b7a0e2018-12-05 18:48:28 -08009506 }
sqian854d44b2018-12-12 16:48:18 -08009507 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
sqianc5eccab2018-10-19 18:46:41 -07009511 }
9512
9513 @Override
sqian8c685422019-02-22 15:55:18 -08009514 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009515 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009516 if (!exactMatch) {
9517 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009518 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009519 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009520 }
9521 final long identity = Binder.clearCallingIdentity();
9522 try {
sqian854d44b2018-12-12 16:48:18 -08009523 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009524 //Note: we ignore passed in param exactMatch. We can remove it once
9525 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009526 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009527 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009528 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009529 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009530 }
sqian11b7a0e2018-12-05 18:48:28 -08009531 }
9532 return false;
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
sqianf4ca7ed2019-01-15 18:32:07 -08009538 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009539 * Start emergency callback mode for GsmCdmaPhone for testing.
9540 */
9541 @Override
9542 public void startEmergencyCallbackMode() {
9543 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9544 "startEmergencyCallbackMode");
9545 enforceModifyPermission();
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 for (Phone phone : PhoneFactory.getPhones()) {
9549 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9550 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9551 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9552 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9553 gsmCdmaPhone.obtainMessage(
9554 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9555 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9556 }
9557 }
9558 } finally {
9559 Binder.restoreCallingIdentity(identity);
9560 }
9561 }
9562
9563 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009564 * Update emergency number list for test mode.
9565 */
9566 @Override
9567 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9568 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9569 "updateEmergencyNumberListTestMode");
9570
9571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 for (Phone phone: PhoneFactory.getPhones()) {
9574 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9575 if (tracker != null) {
9576 tracker.executeEmergencyNumberTestModeCommand(action, num);
9577 }
9578 }
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
9583
9584 /**
9585 * Get the full emergency number list for test mode.
9586 */
9587 @Override
9588 public List<String> getEmergencyNumberListTestMode() {
9589 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9590 "getEmergencyNumberListTestMode");
9591
9592 final long identity = Binder.clearCallingIdentity();
9593 try {
9594 Set<String> emergencyNumbers = new HashSet<>();
9595 for (Phone phone: PhoneFactory.getPhones()) {
9596 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9597 if (tracker != null) {
9598 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9599 emergencyNumbers.add(num.getNumber());
9600 }
9601 }
9602 }
9603 return new ArrayList<>(emergencyNumbers);
9604 } finally {
9605 Binder.restoreCallingIdentity(identity);
9606 }
9607 }
9608
chen xud6b45bd2018-10-30 22:27:10 -07009609 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009610 public int getEmergencyNumberDbVersion(int subId) {
9611 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9612
9613 final long identity = Binder.clearCallingIdentity();
9614 try {
9615 final Phone phone = getPhone(subId);
9616 if (phone == null) {
9617 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9618 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9619 }
9620 return phone.getEmergencyNumberDbVersion();
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
9625
9626 @Override
9627 public void notifyOtaEmergencyNumberDbInstalled() {
9628 enforceModifyPermission();
9629
9630 final long identity = Binder.clearCallingIdentity();
9631 try {
9632 for (Phone phone: PhoneFactory.getPhones()) {
9633 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9634 if (tracker != null) {
9635 tracker.updateOtaEmergencyNumberDatabase();
9636 }
9637 }
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
9642
9643 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009644 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009645 enforceActiveEmergencySessionPermission();
9646
9647 final long identity = Binder.clearCallingIdentity();
9648 try {
9649 for (Phone phone: PhoneFactory.getPhones()) {
9650 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9651 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009652 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9653 }
9654 }
9655 } finally {
9656 Binder.restoreCallingIdentity(identity);
9657 }
9658 }
9659
9660 @Override
9661 public void resetOtaEmergencyNumberDbFilePath() {
9662 enforceActiveEmergencySessionPermission();
9663
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
9666 for (Phone phone: PhoneFactory.getPhones()) {
9667 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9668 if (tracker != null) {
9669 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009670 }
9671 }
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
9676
9677 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009678 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9679 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9680 Phone phone = getPhone(subId);
9681 if (phone == null) {
9682 return null;
9683 }
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
9686 UiccProfile profile = UiccController.getInstance()
9687 .getUiccProfileForPhone(phone.getPhoneId());
9688 if (profile != null) {
9689 return profile.getCertsFromCarrierPrivilegeAccessRules();
9690 }
9691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
9694 return null;
9695 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009696
9697 /**
9698 * Enable or disable a modem stack.
9699 */
9700 @Override
9701 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9702 enforceModifyPermission();
9703
9704 final long identity = Binder.clearCallingIdentity();
9705 try {
9706 Phone phone = PhoneFactory.getPhone(slotIndex);
9707 if (phone == null) {
9708 return false;
9709 } else {
9710 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9711 }
9712 } finally {
9713 Binder.restoreCallingIdentity(identity);
9714 }
9715 }
Michelecea4cf22018-12-21 15:00:11 -08009716
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009717 /**
9718 * Whether a modem stack is enabled or not.
9719 */
9720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009721 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9722 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009723 Phone phone = PhoneFactory.getPhone(slotIndex);
9724 if (phone == null) return false;
9725
9726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009727 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9728 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009729 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9730 }
9731
9732 final long identity = Binder.clearCallingIdentity();
9733 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009734 try {
9735 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9736 } catch (NoSuchElementException ex) {
9737 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9738 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742 }
9743
Michelecea4cf22018-12-21 15:00:11 -08009744 @Override
Michele0ea7d782019-03-19 14:58:42 -07009745 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009746 enforceModifyPermission();
9747
9748 final long identity = Binder.clearCallingIdentity();
9749 try {
9750 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009751 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009752 .commit();
9753 } finally {
9754 Binder.restoreCallingIdentity(identity);
9755 }
9756 }
9757
9758 @Override
Michele0ea7d782019-03-19 14:58:42 -07009759 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009760 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009762 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9763 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009764 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009765 }
Michelecea4cf22018-12-21 15:00:11 -08009766
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
Michele0ea7d782019-03-19 14:58:42 -07009769 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009770 } finally {
9771 Binder.restoreCallingIdentity(identity);
9772 }
9773 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009774
Michele0ea7d782019-03-19 14:58:42 -07009775 @TelephonyManager.IsMultiSimSupportedResult
9776 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009777 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9778 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9779 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009780 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9781 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009782 }
9783 // Check if the hardware supports multisim functionality. If usage of multisim is not
9784 // supported by the modem, indicate that it is restricted.
9785 PhoneCapability staticCapability =
9786 mPhoneConfigurationManager.getStaticPhoneCapability();
9787 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009788 loge("isMultiSimSupportedInternal: no static configuration available");
9789 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009790 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009791 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009792 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9793 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009794 }
9795 // Check if support of multiple SIMs is restricted by carrier
9796 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009797 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009798 }
9799
Michele0ea7d782019-03-19 14:58:42 -07009800 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009801 }
9802
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009803 /**
9804 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009805 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9806 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9807 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009808 * @param numOfSims number of active sims we want to switch to
9809 */
9810 @Override
9811 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009812 if (numOfSims == 1) {
9813 enforceModifyPermission();
9814 } else {
9815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9816 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9817 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009818 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009819
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009820 try {
Michele30b57b22019-03-01 12:01:14 -08009821 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009822 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009823 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9824 return;
9825 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009826 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9827 } finally {
9828 Binder.restoreCallingIdentity(identity);
9829 }
9830 }
9831
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009832 @Override
9833 public boolean isApplicationOnUicc(int subId, int appType) {
9834 enforceReadPrivilegedPermission("isApplicationOnUicc");
9835 Phone phone = getPhone(subId);
9836 if (phone == null) {
9837 return false;
9838 }
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009841 UiccPort uiccPort = phone.getUiccPort();
9842 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009843 return false;
9844 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009845 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009846 if (uiccProfile == null) {
9847 return false;
9848 }
9849 if (TelephonyManager.APPTYPE_SIM <= appType
9850 && appType <= TelephonyManager.APPTYPE_ISIM) {
9851 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9852 }
9853 return false;
9854 } finally {
9855 Binder.restoreCallingIdentity(identity);
9856 }
9857 }
9858
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009859 /**
chen xub4baa772019-04-03 10:23:41 -07009860 * Get whether making changes to modem configurations will trigger reboot.
9861 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009862 */
9863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009864 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9865 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009867 mApp, subId, callingPackage, callingFeatureId,
9868 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009869 return false;
9870 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009871 final long identity = Binder.clearCallingIdentity();
9872 try {
9873 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9874 } finally {
9875 Binder.restoreCallingIdentity(identity);
9876 }
9877 }
9878
Nathan Harold29f5f052019-02-15 13:41:57 -08009879 private void updateModemStateMetrics() {
9880 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9881 // TODO: check the state for each modem if the api is ready.
9882 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9883 }
9884
Pengquan Meng3889a572019-01-23 11:16:29 -08009885 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009886 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009887 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009888 // Verify that the callingPackage belongs to the calling UID
9889 mApp.getSystemService(AppOpsManager.class)
9890 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009891 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009892 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009893 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009894 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9895 if (slotInfos != null) {
9896 for (int i = 0; i < slotInfos.length; i++) {
9897 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9898 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9899 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9900 portInfo.getLogicalSlotIndex()));
9901 }
9902 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009903 }
9904 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009905 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009906 } finally {
9907 Binder.restoreCallingIdentity(identity);
9908 }
9909 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009910
9911 /**
9912 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009913 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009914 */
jimsunf9ec1622022-09-13 21:18:43 +08009915 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009916 @Override
9917 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009918 return getHalVersion(HAL_SERVICE_RADIO);
9919 }
9920
9921 /**
9922 * Get the HAL Version of a specific service
9923 */
9924 @Override
9925 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009926 Phone phone = getDefaultPhone();
9927 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009928 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009929 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9930 return hv.major * 100 + hv.minor;
9931 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009932
9933 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009934 * Get the current calling package name.
9935 * @return the current calling package name
9936 */
9937 @Override
9938 public String getCurrentPackageName() {
9939 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9940 }
9941
9942 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009943 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9944 * corresponding network requests on a subId.
9945 *
9946 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009947 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009948 * 2) APN is un-metered for this subscription, or
9949 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009950 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009951 *
9952 * @return whether data is allowed for a apn type.
9953 *
9954 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009955 */
9956 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009957 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009958 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9959 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009960
9961 // Now that all security checks passes, perform the operation as ourselves.
9962 final long identity = Binder.clearCallingIdentity();
9963 try {
9964 Phone phone = getPhone(subId);
9965 if (phone == null) return false;
9966
Jack Yu27422a52022-03-21 10:38:05 -07009967 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009968 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009969 isMetered = phone.getDataNetworkController().getDataConfigManager()
9970 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9971 phone.getServiceState().getDataRoaming());
9972 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009973 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009974 } finally {
9975 Binder.restoreCallingIdentity(identity);
9976 }
9977 }
9978
9979 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009980 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009981 enforceReadPrivilegedPermission("isApnMetered");
9982
9983 // Now that all security checks passes, perform the operation as ourselves.
9984 final long identity = Binder.clearCallingIdentity();
9985 try {
9986 Phone phone = getPhone(subId);
9987 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009988 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9989 DataUtils.apnTypeToNetworkCapability(apnType),
9990 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009995
9996 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009997 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9998 int subscriptionId, IBooleanConsumer resultCallback) {
9999 enforceModifyPermission();
10000 long token = Binder.clearCallingIdentity();
10001 try {
10002 Phone phone = getPhone(subscriptionId);
10003 if (phone == null) {
10004 try {
10005 if (resultCallback != null) {
10006 resultCallback.accept(false);
10007 }
10008 } catch (RemoteException e) {
10009 // ignore
10010 }
10011 return;
10012 }
10013 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10014 Pair.create(specifiers, (x) -> {
10015 try {
10016 if (resultCallback != null) {
10017 resultCallback.accept(x);
10018 }
10019 } catch (RemoteException e) {
10020 // ignore
10021 }
10022 });
10023 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10024 } finally {
10025 Binder.restoreCallingIdentity(token);
10026 }
10027 }
10028
10029 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010030 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10031 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010032 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010033 mApp, subId, "getSystemSelectionChannels");
10034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10035 final long identity = Binder.clearCallingIdentity();
10036 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010037 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10038 if (result instanceof IllegalStateException) {
10039 throw (IllegalStateException) result;
10040 }
10041 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010042 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10043 return specifiers;
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
10046 }
10047 }
10048
10049 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010050 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010051 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010052 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010053 }
10054
10055 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010056 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10057 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010058 if (callingPackage == null) {
10059 callingPackage = getCurrentPackageName();
10060 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010061 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10062 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010063 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10064 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010065 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10066 }
10067 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10068 Intent intent = new Intent();
10069 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10070 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10071 // Bring up choose default SMS subscription dialog right now
10072 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10073 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10074 mApp.startActivity(intent);
10075 }
chen xud5ca2d52019-05-28 15:20:57 -070010076
10077 @Override
10078 public String getMmsUAProfUrl(int subId) {
10079 //TODO investigate if this API should require proper permission check in R b/133791609
10080 final long identity = Binder.clearCallingIdentity();
10081 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010082 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10083 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10084 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10085 return carrierUAProfUrl;
10086 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010087 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10088 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010089 } finally {
10090 Binder.restoreCallingIdentity(identity);
10091 }
10092 }
10093
10094 @Override
10095 public String getMmsUserAgent(int subId) {
10096 //TODO investigate if this API should require proper permission check in R b/133791609
10097 final long identity = Binder.clearCallingIdentity();
10098 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010099 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10100 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10101 if (!TextUtils.isEmpty(carrierUserAgent)) {
10102 return carrierUserAgent;
10103 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010104 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10105 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010106 } finally {
10107 Binder.restoreCallingIdentity(identity);
10108 }
10109 }
Jack Yub07d4972019-05-28 16:12:25 -070010110
10111 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010112 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10113 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010114
Jack Yub07d4972019-05-28 16:12:25 -070010115 final long identity = Binder.clearCallingIdentity();
10116 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010117 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010118 if (phone == null) return false;
10119
Ling Maf188d502022-09-16 15:22:36 -070010120 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010121 } finally {
10122 Binder.restoreCallingIdentity(identity);
10123 }
10124 }
10125
10126 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010127 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010128 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010129 enforceModifyPermission();
10130
changbettyd5c246e2019-12-24 15:40:37 +080010131 final long identity = Binder.clearCallingIdentity();
10132 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010133 Phone phone = getPhone(subscriptionId);
10134 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010135
Ling Maf188d502022-09-16 15:22:36 -070010136 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010137 } finally {
10138 Binder.restoreCallingIdentity(identity);
10139 }
10140 }
10141
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010142 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010143 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010144 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10145 * otherwise.
10146 */
10147 @Override
10148 public void setCepEnabled(boolean isCepEnabled) {
10149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10150
10151 final long identity = Binder.clearCallingIdentity();
10152 try {
10153 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10154 for (Phone phone : PhoneFactory.getPhones()) {
10155 Phone defaultPhone = phone.getImsPhone();
10156 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10157 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10158 ImsPhoneCallTracker imsPhoneCallTracker =
10159 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10160 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10161 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10162 + imsPhone.getMsisdn());
10163 }
10164 }
10165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
allenwtsu46dcc572020-01-08 18:24:03 +080010169
10170 /**
10171 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10172 *
10173 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10174 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10175 * before being read.
10176 */
10177 @Override
10178 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10179 isCompressed) {
10180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10181 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010182 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10183 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10184 }
10185 if (!isImsAvailableOnDevice()) {
10186 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10187 "IMS not available on device.");
10188 }
10189
10190 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010191 try {
Hui Wang761a6682020-10-31 05:12:53 +000010192 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10193 } finally {
10194 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010195 }
10196 }
zoey chene02881a2019-12-30 16:11:23 +080010197
10198 @Override
10199 public boolean isIccLockEnabled(int subId) {
10200 enforceReadPrivilegedPermission("isIccLockEnabled");
10201
10202 // Now that all security checks passes, perform the operation as ourselves.
10203 final long identity = Binder.clearCallingIdentity();
10204 try {
10205 Phone phone = getPhone(subId);
10206 if (phone != null && phone.getIccCard() != null) {
10207 return phone.getIccCard().getIccLockEnabled();
10208 } else {
10209 return false;
10210 }
10211 } finally {
10212 Binder.restoreCallingIdentity(identity);
10213 }
10214 }
10215
10216 /**
10217 * Set the ICC pin lock enabled or disabled.
10218 *
10219 * @return an integer representing the status of IccLock enabled or disabled in the following
10220 * three cases:
10221 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10222 * successfully.
10223 * - Positive number and zero for remaining password attempts.
10224 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10225 *
10226 */
10227 @Override
10228 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10229 enforceModifyPermission();
10230
10231 Phone phone = getPhone(subId);
10232 if (phone == null) {
10233 return 0;
10234 }
10235 // Now that all security checks passes, perform the operation as ourselves.
10236 final long identity = Binder.clearCallingIdentity();
10237 try {
10238 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10239 new Pair<Boolean, String>(enabled, password), phone, null);
10240 return attemptsRemaining;
10241
10242 } catch (Exception e) {
10243 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10244 } finally {
10245 Binder.restoreCallingIdentity(identity);
10246 }
10247 return 0;
10248 }
10249
10250 /**
10251 * Change the ICC password used in ICC pin lock.
10252 *
10253 * @return an integer representing the status of IccLock changed in the following three cases:
10254 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10255 * - Positive number and zero for remaining password attempts.
10256 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10257 *
10258 */
10259 @Override
10260 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10261 enforceModifyPermission();
10262
10263 Phone phone = getPhone(subId);
10264 if (phone == null) {
10265 return 0;
10266 }
10267 // Now that all security checks passes, perform the operation as ourselves.
10268 final long identity = Binder.clearCallingIdentity();
10269 try {
10270 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10271 new Pair<String, String>(oldPassword, newPassword), phone, null);
10272 return attemptsRemaining;
10273
10274 } catch (Exception e) {
10275 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10276 } finally {
10277 Binder.restoreCallingIdentity(identity);
10278 }
10279 return 0;
10280 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010281
10282 /**
10283 * Request for receiving user activity notification
10284 */
10285 @Override
10286 public void requestUserActivityNotification() {
10287 if (!mNotifyUserActivity.get()
10288 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10289 mNotifyUserActivity.set(true);
10290 }
10291 }
10292
10293 /**
10294 * Called when userActivity is signalled in the power manager.
10295 * This is safe to call from any thread, with any window manager locks held or not.
10296 */
10297 @Override
10298 public void userActivity() {
10299 // ***************************************
10300 // * Inherited from PhoneWindowManager *
10301 // ***************************************
10302 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10303 // WITH ITS LOCKS HELD.
10304 //
10305 // This code must be VERY careful about the locks
10306 // it acquires.
10307 // In fact, the current code acquires way too many,
10308 // and probably has lurking deadlocks.
10309
10310 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10311 throw new SecurityException("Only the OS may call notifyUserActivity()");
10312 }
10313
10314 if (mNotifyUserActivity.getAndSet(false)) {
10315 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10316 USER_ACTIVITY_NOTIFICATION_DELAY);
10317 }
10318 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010319
10320 @Override
10321 public boolean canConnectTo5GInDsdsMode() {
10322 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10323 }
Jack Yud10cdd42020-09-28 20:28:01 -070010324
10325 @Override
10326 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10327 String callingFeatureId) {
10328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10329 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10330 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10331 }
10332
10333 Phone phone = getPhone(subId);
10334 if (phone == null) {
10335 throw new RuntimeException("phone is not available");
10336 }
10337 // Now that all security checks passes, perform the operation as ourselves.
10338 final long identity = Binder.clearCallingIdentity();
10339 try {
10340 return phone.getEquivalentHomePlmns();
10341 } finally {
10342 Binder.restoreCallingIdentity(identity);
10343 }
10344 }
Daniel Bright59e67312020-11-13 11:49:37 -080010345
10346 @Override
10347 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010348 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10349 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010350 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010351 if (radioInterfaceCapabilities == null) {
10352 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010353 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010354 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010355 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010356
Hui Wang641e81c2020-10-12 12:14:23 -070010357 @Override
10358 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10359 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010360 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10361 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10362 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10363 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10364 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010365 if (DBG) {
10366 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10367 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10368 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10369 }
10370
10371 if (!SubscriptionManager.isValidSubscriptionId(subId)
10372 || appType < TelephonyManager.APPTYPE_UNKNOWN
10373 || appType > TelephonyManager.APPTYPE_ISIM
10374 || nafUrl == null || securityProtocol == null || callback == null) {
10375 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10376 if (callback != null) {
10377 try {
10378 callback.onAuthenticationFailure(
10379 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10380 } catch (RemoteException exception) {
10381 log("Fail to notify onAuthenticationFailure due to " + exception);
10382 }
10383 return;
10384 }
10385 }
10386
10387 final long token = Binder.clearCallingIdentity();
10388 try {
10389 getGbaManager(subId).bootstrapAuthenticationRequest(
10390 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10391 forceBootStrapping, callback));
10392 } finally {
10393 Binder.restoreCallingIdentity(token);
10394 }
10395 }
10396
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010397 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010398 * Attempts to set the radio power state for all phones for thermal reason.
10399 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010400 * requested radio power state will actually be set. See {@link
10401 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10402 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010403 * @param enable {@code true} if trying to turn radio on.
10404 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10405 * false}.
10406 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010407 private boolean setRadioPowerForThermal(boolean enable) {
10408 boolean isPhoneAvailable = false;
10409 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10410 Phone phone = PhoneFactory.getPhone(i);
10411 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010412 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010413 isPhoneAvailable = true;
10414 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010415 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010416
10417 // return true if successfully informed the phone object about the thermal radio power
10418 // request.
10419 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010420 }
10421
10422 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010423 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010424 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10425 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10426 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10427 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10428 throw new IllegalArgumentException("modem does not support data throttling");
10429 }
10430
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010431 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10432 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010433 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010434 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10435 }
10436
Sarah Chinecc78c42022-03-31 21:16:48 -070010437 setDataEnabledForReason(
10438 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010439
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010440 if (isDataThrottlingSupported) {
10441 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010442 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010443 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10444 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10445 } else if (thermalMitigationResult
10446 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010447 log("Modem likely does not support data throttling on secondary carrier. Data " +
10448 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10449 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010450 }
10451 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010452 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010453
10454 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010455 }
10456
Jack Nudelman644b91a2021-03-12 14:09:48 -080010457 private static List<String> getThermalMitigationAllowlist(Context context) {
10458 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10459 for (String pckg : context.getResources()
10460 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10461 sThermalMitigationAllowlistedPackages.add(pckg);
10462 }
10463 }
10464
10465 return sThermalMitigationAllowlistedPackages;
10466 }
10467
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010468 private boolean isAnyPhoneInEmergencyState() {
10469 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10470 if (tm.isInEmergencyCall()) {
10471 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10472 return true;
10473 }
10474 for (Phone phone : PhoneFactory.getPhones()) {
10475 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10476 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10477 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10478 + phone.isInEcm());
10479 return true;
10480 }
10481 }
10482
10483 return false;
10484 }
10485
Jack Nudelman644b91a2021-03-12 14:09:48 -080010486 /**
10487 * Used by shell commands to add an authorized package name for thermal mitigation.
10488 * @param packageName name of package to be allowlisted
10489 * @param context
10490 */
10491 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10492 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10493 sThermalMitigationAllowlistedPackages.add(packageName);
10494 }
10495
10496 /**
10497 * Used by shell commands to remove an authorized package name for thermal mitigation.
10498 * @param packageName name of package to remove from allowlist
10499 * @param context
10500 */
10501 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10502 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10503 sThermalMitigationAllowlistedPackages.remove(packageName);
10504 }
10505
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010506 /**
10507 * Thermal mitigation request to control functionalities at modem.
10508 *
10509 * @param subId the id of the subscription.
10510 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010511 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010512 *
10513 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10514 */
10515 @Override
10516 @ThermalMitigationResult
10517 public int sendThermalMitigationRequest(
10518 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010519 ThermalMitigationRequest thermalMitigationRequest,
10520 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010521 enforceModifyPermission();
10522
Jack Nudelman644b91a2021-03-12 14:09:48 -080010523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10524 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10525 .contains(callingPackage)) {
10526 throw new SecurityException("Calling package must be configured in the device config. "
10527 + "calling package: " + callingPackage);
10528 }
10529
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010530 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10531 final long identity = Binder.clearCallingIdentity();
10532
10533 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10534 try {
10535 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10536 switch (thermalMitigationAction) {
10537 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10538 thermalMitigationResult =
10539 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010540 thermalMitigationRequest.getDataThrottlingRequest(),
10541 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010542 break;
10543 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10544 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10545 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10546 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10547 }
10548
10549 // Ensure that radio is on. If not able to power on due to phone being
10550 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010551 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010552 thermalMitigationResult =
10553 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10554 break;
10555 }
10556
10557 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010558 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010559 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10560 break;
10561 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10562 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10563 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10564 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10565 }
10566
10567 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10568 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010569 Phone phone = getPhone(subId);
10570 if (phone == null) {
10571 thermalMitigationResult =
10572 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10573 break;
10574 }
10575
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010576 TelephonyConnectionService service =
10577 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010578 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010579 Log.e(LOG_TAG, "An emergency call is pending");
10580 thermalMitigationResult =
10581 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10582 break;
10583 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010584 thermalMitigationResult =
10585 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10586 break;
10587 }
10588 } else {
10589 thermalMitigationResult =
10590 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10591 break;
10592 }
10593
10594 // Turn radio off. If not able to power off due to phone being unavailable,
10595 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010596 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010597 thermalMitigationResult =
10598 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10599 break;
10600 }
10601 thermalMitigationResult =
10602 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10603 break;
10604 default:
10605 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10606 + "not exist. Requested action: " + thermalMitigationAction);
10607 }
10608 } catch (IllegalArgumentException e) {
10609 throw e;
10610 } catch (Exception e) {
10611 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10612 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616
10617 if (DBG) {
10618 log("thermalMitigationRequest returning with thermalMitigationResult: "
10619 + thermalMitigationResult);
10620 }
10621
10622 return thermalMitigationResult;
10623 }
Hui Wang641e81c2020-10-12 12:14:23 -070010624
10625 /**
10626 * Set the GbaService Package Name that Telephony will bind to.
10627 *
10628 * @param subId The sim that the GbaService is associated with.
10629 * @param packageName The name of the package to be replaced with.
10630 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10631 */
10632 @Override
10633 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10634 enforceModifyPermission();
10635
10636 final long identity = Binder.clearCallingIdentity();
10637 try {
10638 return getGbaManager(subId).overrideServicePackage(packageName);
10639 } finally {
10640 Binder.restoreCallingIdentity(identity);
10641 }
10642 }
10643
10644 /**
10645 * Return the package name of the currently bound GbaService.
10646 *
10647 * @param subId The sim that the GbaService is associated with.
10648 * @return the package name of the GbaService configuration, null if GBA is not supported.
10649 */
10650 @Override
10651 public String getBoundGbaService(int subId) {
10652 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10653
10654 final long identity = Binder.clearCallingIdentity();
10655 try {
10656 return getGbaManager(subId).getServicePackage();
10657 } finally {
10658 Binder.restoreCallingIdentity(identity);
10659 }
10660 }
10661
10662 /**
10663 * Set the release time for telephony to unbind GbaService.
10664 *
10665 * @param subId The sim that the GbaService is associated with.
10666 * @param interval The release time to unbind GbaService by millisecond.
10667 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10668 */
10669 @Override
10670 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10671 enforceModifyPermission();
10672
10673 final long identity = Binder.clearCallingIdentity();
10674 try {
10675 return getGbaManager(subId).overrideReleaseTime(interval);
10676 } finally {
10677 Binder.restoreCallingIdentity(identity);
10678 }
10679 }
10680
10681 /**
10682 * Return the release time for telephony to unbind GbaService.
10683 *
10684 * @param subId The sim that the GbaService is associated with.
10685 * @return The release time to unbind GbaService by millisecond.
10686 */
10687 @Override
10688 public int getGbaReleaseTime(int subId) {
10689 enforceReadPrivilegedPermission("getGbaReleaseTime");
10690
10691 final long identity = Binder.clearCallingIdentity();
10692 try {
10693 return getGbaManager(subId).getReleaseTime();
10694 } finally {
10695 Binder.restoreCallingIdentity(identity);
10696 }
10697 }
10698
10699 private GbaManager getGbaManager(int subId) {
10700 GbaManager instance = GbaManager.getInstance(subId);
10701 if (instance == null) {
10702 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10703 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10704 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10705 }
10706 return instance;
10707 }
Hui Wang761a6682020-10-31 05:12:53 +000010708
10709 /**
10710 * indicate whether the device and the carrier can support
10711 * RCS VoLTE single registration.
10712 */
10713 @Override
10714 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010715 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10716 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10717 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10718 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010719
10720 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10721 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10722 }
10723
10724 final long identity = Binder.clearCallingIdentity();
10725 try {
10726 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10727 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010728 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10729 if (isCapable != null) {
10730 return isCapable;
10731 }
Hui Wang761a6682020-10-31 05:12:53 +000010732 }
Hui Wang67af90e2021-06-04 16:57:15 -070010733 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10734 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010735 } finally {
10736 Binder.restoreCallingIdentity(identity);
10737 }
10738 }
10739
10740 /**
10741 * Register RCS provisioning callback.
10742 */
10743 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010744 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010745 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010746 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010747 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010748 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10749 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010750
10751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10752 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10753 }
10754 if (!isImsAvailableOnDevice()) {
10755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10756 "IMS not available on device.");
10757 }
10758
10759 final long identity = Binder.clearCallingIdentity();
10760 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010761 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010762 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010763 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10764 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010765 }
Hui Wang761a6682020-10-31 05:12:53 +000010766 } finally {
10767 Binder.restoreCallingIdentity(identity);
10768 }
10769 }
10770
10771 /**
10772 * Unregister RCS provisioning callback.
10773 */
10774 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010775 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010776 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010777 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010778 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010779 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10780 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010781
10782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10783 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10784 }
10785 if (!isImsAvailableOnDevice()) {
10786 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10787 "IMS not available on device.");
10788 }
10789
10790 final long identity = Binder.clearCallingIdentity();
10791 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010792 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010793 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
10798
10799 /**
10800 * trigger RCS reconfiguration.
10801 */
10802 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010803 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10804 "triggerRcsReconfiguration",
10805 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010806
10807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10808 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10809 }
10810 if (!isImsAvailableOnDevice()) {
10811 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10812 "IMS not available on device.");
10813 }
10814
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
10822
10823 /**
10824 * Provide the client configuration parameters of the RCS application.
10825 */
10826 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010827 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10828 "setRcsClientConfiguration",
10829 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010830
10831 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10832 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10833 }
10834 if (!isImsAvailableOnDevice()) {
10835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10836 "IMS not available on device.");
10837 }
10838
10839 final long identity = Binder.clearCallingIdentity();
10840
10841 try {
10842 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10843 if (configBinder == null) {
10844 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010845 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10846 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010847 } else {
10848 configBinder.setRcsClientConfiguration(rcc);
10849 }
joonhunshin3e154242021-09-17 06:33:39 +000010850
10851 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10852 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010853 } catch (RemoteException e) {
10854 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010855 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10856 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010857 } finally {
10858 Binder.restoreCallingIdentity(identity);
10859 }
10860 }
10861
10862 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010863 * Enables or disables the test mode for RCS VoLTE single registration.
10864 */
10865 @Override
10866 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10868 "setRcsSingleRegistrationTestModeEnabled");
10869
10870 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10871 }
10872
10873 /**
10874 * Gets the test mode for RCS VoLTE single registration.
10875 */
10876 @Override
10877 public boolean getRcsSingleRegistrationTestModeEnabled() {
10878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10879 "getRcsSingleRegistrationTestModeEnabled");
10880
10881 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10882 }
10883
10884 /**
Hui Wang761a6682020-10-31 05:12:53 +000010885 * Overrides the config of RCS VoLTE single registration enabled for the device.
10886 */
10887 @Override
10888 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10889 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10890 "setDeviceSingleRegistrationEnabledOverride");
10891 enforceModifyPermission();
10892
10893 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10894 : Boolean.parseBoolean(enabledStr);
10895 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010896 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010897 }
10898
10899 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010900 * Sends a device to device communication message. Only usable via shell.
10901 * @param message message to send.
10902 * @param value message value.
10903 */
10904 @Override
10905 public void sendDeviceToDeviceMessage(int message, int value) {
10906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010907 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010908 enforceModifyPermission();
10909
10910 final long identity = Binder.clearCallingIdentity();
10911 try {
10912 TelephonyConnectionService service =
10913 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10914 if (service == null) {
10915 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10916 return;
10917 }
10918 service.sendTestDeviceToDeviceMessage(message, value);
10919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
10923
Tyler Gunnbabbda02021-02-10 11:05:02 -080010924 /**
10925 * Sets the specified device to device transport active.
10926 * @param transport The transport to set active.
10927 */
10928 @Override
10929 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10931 "setActiveDeviceToDeviceTransport");
10932 enforceModifyPermission();
10933
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 TelephonyConnectionService service =
10937 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10938 if (service == null) {
10939 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10940 return;
10941 }
10942 service.setActiveDeviceToDeviceTransport(transport);
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
Tyler Gunn92479152021-01-20 16:30:10 -080010947
Tyler Gunnd4339262021-05-03 14:46:49 -070010948 @Override
10949 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10951 "setDeviceToDeviceForceEnabled");
10952
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 Arrays.stream(PhoneFactory.getPhones()).forEach(
10956 p -> {
10957 Phone thePhone = p.getImsPhone();
10958 if (thePhone != null && thePhone instanceof ImsPhone) {
10959 ImsPhone imsPhone = (ImsPhone) thePhone;
10960 CallTracker tracker = imsPhone.getCallTracker();
10961 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10962 ImsPhoneCallTracker imsPhoneCallTracker =
10963 (ImsPhoneCallTracker) tracker;
10964 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10965 }
10966 }
10967 }
10968 );
10969 } finally {
10970 Binder.restoreCallingIdentity(identity);
10971 }
10972 }
10973
Tyler Gunn92479152021-01-20 16:30:10 -080010974 /**
Hui Wang761a6682020-10-31 05:12:53 +000010975 * Gets the config of RCS VoLTE single registration enabled for the device.
10976 */
10977 @Override
10978 public boolean getDeviceSingleRegistrationEnabled() {
10979 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10980 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10981 }
10982
10983 /**
10984 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10985 */
10986 @Override
10987 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10989 "setCarrierSingleRegistrationEnabledOverride");
10990 enforceModifyPermission();
10991
10992 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10993 : Boolean.parseBoolean(enabledStr);
10994 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10995 subId, enabled);
10996 }
10997
10998 /**
10999 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11000 */
11001 @Override
11002 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11003 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11004 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11005 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011006
11007 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011008 * Overrides the ims feature validation result
11009 */
11010 @Override
11011 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11013 "setImsFeatureValidationOverride");
11014
11015 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11016 : Boolean.parseBoolean(enabledStr);
11017 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11018 subId, enabled);
11019 }
11020
11021 /**
11022 * Gets the ims feature validation override value
11023 */
11024 @Override
11025 public boolean getImsFeatureValidationOverride(int subId) {
11026 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11027 "getImsFeatureValidationOverride");
11028 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11029 }
11030
11031 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011032 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11033 * their mobile plan.
11034 */
11035 @Override
11036 public String getMobileProvisioningUrl() {
11037 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11038 final long identity = Binder.clearCallingIdentity();
11039 try {
11040 return getDefaultPhone().getMobileProvisioningUrl();
11041 } finally {
11042 Binder.restoreCallingIdentity(identity);
11043 }
11044 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011045
James.cf Linbcdf8b32021-01-14 16:44:13 +080011046 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011047 * Get the EAB contact from the EAB database.
11048 */
11049 @Override
11050 public String getContactFromEab(String contact) {
11051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11052 enforceModifyPermission();
11053 final long identity = Binder.clearCallingIdentity();
11054 try {
11055 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11056 } finally {
11057 Binder.restoreCallingIdentity(identity);
11058 }
11059 }
11060
11061 /**
Calvin Pana1434322021-07-01 19:27:01 +080011062 * Get the EAB capability from the EAB database.
11063 */
11064 @Override
11065 public String getCapabilityFromEab(String contact) {
11066 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11067 enforceModifyPermission();
11068 final long identity = Binder.clearCallingIdentity();
11069 try {
11070 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11071 } finally {
11072 Binder.restoreCallingIdentity(identity);
11073 }
11074 }
11075
11076 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011077 * Remove the EAB contacts from the EAB database.
11078 */
11079 @Override
11080 public int removeContactFromEab(int subId, String contacts) {
11081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11082 enforceModifyPermission();
11083 final long identity = Binder.clearCallingIdentity();
11084 try {
11085 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11086 } finally {
11087 Binder.restoreCallingIdentity(identity);
11088 }
11089 }
11090
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011091 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011092 public boolean getDeviceUceEnabled() {
11093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11094 final long identity = Binder.clearCallingIdentity();
11095 try {
11096 return mApp.getDeviceUceEnabled();
11097 } finally {
11098 Binder.restoreCallingIdentity(identity);
11099 }
11100 }
11101
11102 @Override
11103 public void setDeviceUceEnabled(boolean isEnabled) {
11104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11105 final long identity = Binder.clearCallingIdentity();
11106 try {
11107 mApp.setDeviceUceEnabled(isEnabled);
11108 } finally {
11109 Binder.restoreCallingIdentity(identity);
11110 }
11111 }
11112
Brad Ebinger14d467f2021-02-12 06:18:28 +000011113 /**
11114 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11115 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11116 */
11117 // Used for SHELL command only right now.
11118 @Override
11119 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11120 List<String> featureTags) {
11121 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11122 "addUceRegistrationOverrideShell");
11123 final long identity = Binder.clearCallingIdentity();
11124 try {
11125 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11126 new ArraySet<>(featureTags));
11127 } catch (ImsException e) {
11128 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11129 } finally {
11130 Binder.restoreCallingIdentity(identity);
11131 }
11132 }
11133
11134 /**
11135 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11136 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11137 */
11138 // Used for SHELL command only right now.
11139 @Override
11140 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11141 List<String> featureTags) {
11142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11143 "removeUceRegistrationOverrideShell");
11144 final long identity = Binder.clearCallingIdentity();
11145 try {
11146 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11147 new ArraySet<>(featureTags));
11148 } catch (ImsException e) {
11149 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11150 } finally {
11151 Binder.restoreCallingIdentity(identity);
11152 }
11153 }
11154
11155 /**
11156 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11157 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11158 */
11159 // Used for SHELL command only right now.
11160 @Override
11161 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11163 "clearUceRegistrationOverrideShell");
11164 final long identity = Binder.clearCallingIdentity();
11165 try {
11166 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11167 } catch (ImsException e) {
11168 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11169 } finally {
11170 Binder.restoreCallingIdentity(identity);
11171 }
11172 }
11173
11174 /**
11175 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11176 */
11177 // Used for SHELL command only right now.
11178 @Override
11179 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11181 "getLatestRcsContactUceCapabilityShell");
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11185 } catch (ImsException e) {
11186 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11187 } finally {
11188 Binder.restoreCallingIdentity(identity);
11189 }
11190 }
11191
11192 /**
11193 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11194 * device does not have an active PUBLISH.
11195 */
11196 // Used for SHELL command only right now.
11197 @Override
11198 public String getLastUcePidfXmlShell(int subId) {
11199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11200 final long identity = Binder.clearCallingIdentity();
11201 try {
11202 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11203 } catch (ImsException e) {
11204 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11205 } finally {
11206 Binder.restoreCallingIdentity(identity);
11207 }
11208 }
11209
James.cf Line8713a42021-04-29 16:04:26 +080011210 /**
11211 * Remove UCE requests cannot be sent to the network status.
11212 */
11213 // Used for SHELL command only right now.
11214 @Override
11215 public boolean removeUceRequestDisallowedStatus(int subId) {
11216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11217 final long identity = Binder.clearCallingIdentity();
11218 try {
11219 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11220 } catch (ImsException e) {
11221 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11222 } finally {
11223 Binder.restoreCallingIdentity(identity);
11224 }
11225 }
11226
James.cf Lin18bb9002021-05-25 01:37:38 +080011227 /**
11228 * Remove UCE requests cannot be sent to the network status.
11229 */
11230 // Used for SHELL command only.
11231 @Override
11232 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11234 final long identity = Binder.clearCallingIdentity();
11235 try {
11236 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11237 } catch (ImsException e) {
11238 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11239 } finally {
11240 Binder.restoreCallingIdentity(identity);
11241 }
11242 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011243
James.cf Lin4b784aa2021-01-31 03:25:15 +080011244 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011245 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11246 String callingPackage) {
11247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11248 mApp, subId, "setSignalStrengthUpdateRequest");
11249
11250 final int callingUid = Binder.getCallingUid();
11251 // Verify that tha callingPackage belongs to the calling UID
11252 mApp.getSystemService(AppOpsManager.class)
11253 .checkPackage(callingUid, callingPackage);
11254
Rambo Wang3607f502021-02-01 21:51:40 -080011255 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011256
11257 final long identity = Binder.clearCallingIdentity();
11258 try {
11259 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11260 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11261
11262 if (result instanceof IllegalStateException) {
11263 throw (IllegalStateException) result;
11264 }
11265 } finally {
11266 Binder.restoreCallingIdentity(identity);
11267 }
11268 }
11269
11270 @Override
11271 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11272 String callingPackage) {
11273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11274 mApp, subId, "clearSignalStrengthUpdateRequest");
11275
11276 final int callingUid = Binder.getCallingUid();
11277 // Verify that tha callingPackage belongs to the calling UID
11278 mApp.getSystemService(AppOpsManager.class)
11279 .checkPackage(callingUid, callingPackage);
11280
11281 final long identity = Binder.clearCallingIdentity();
11282 try {
11283 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11284 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11285
11286 if (result instanceof IllegalStateException) {
11287 throw (IllegalStateException) result;
11288 }
11289 } finally {
11290 Binder.restoreCallingIdentity(identity);
11291 }
11292 }
11293
Rambo Wang3607f502021-02-01 21:51:40 -080011294 private static void validateSignalStrengthUpdateRequest(Context context,
11295 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011296 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11297 // phone/system process do not have further restriction on request
11298 return;
11299 }
11300
11301 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011302 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011303 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011304 context.enforceCallingOrSelfPermission(
11305 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11306 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011307 }
11308
11309 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011310 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011311 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011312 || info.isEnabled()) {
11313 throw new IllegalArgumentException(
11314 "Only system can set hide fields in SignalThresholdInfo");
11315 }
11316
11317 // Thresholds length for each RAN need in range. This has been validated in
11318 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11319 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11320 final int[] thresholds = info.getThresholds();
11321 Objects.requireNonNull(thresholds);
11322 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11323 || thresholds.length
11324 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11325 throw new IllegalArgumentException(
11326 "thresholds length is out of range: " + thresholds.length);
11327 }
11328 }
11329 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011330
11331 /**
11332 * Gets the current phone capability.
11333 *
11334 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11335 * @return the PhoneCapability which describes the data connection capability of modem.
11336 * It's used to evaluate possible phone config change, for example from single
11337 * SIM device to multi-SIM device.
11338 */
11339 @Override
11340 public PhoneCapability getPhoneCapability() {
11341 enforceReadPrivilegedPermission("getPhoneCapability");
11342 final long identity = Binder.clearCallingIdentity();
11343 try {
11344 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11345 } finally {
11346 Binder.restoreCallingIdentity(identity);
11347 }
11348 }
Michele Berionne5e411512020-11-13 02:36:59 +000011349
11350 /**
11351 * Prepare TelephonyManager for an unattended reboot. The reboot is
11352 * required to be done shortly after the API is invoked.
11353 */
11354 @Override
11355 @TelephonyManager.PrepareUnattendedRebootResult
11356 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011358 enforceRebootPermission();
11359
11360 final long identity = Binder.clearCallingIdentity();
11361 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011362 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011363 } finally {
11364 Binder.restoreCallingIdentity(identity);
11365 }
11366 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011367
11368 /**
11369 * Request to get the current slicing configuration including URSP rules and
11370 * NSSAIs (configured, allowed and rejected).
11371 *
11372 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11373 */
11374 @Override
11375 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011376 TelephonyPermissions
11377 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11378 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011379
11380 final long identity = Binder.clearCallingIdentity();
11381 try {
11382 Phone phone = getDefaultPhone();
11383 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11384 } finally {
11385 Binder.restoreCallingIdentity(identity);
11386 }
11387 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011388
11389 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011390 * Check whether the given premium capability is available for purchase from the carrier.
11391 *
11392 * @param capability The premium capability to check.
11393 * @param subId The subId to check the premium capability for.
11394 *
11395 * @return Whether the given premium capability is available to purchase.
11396 */
11397 @Override
11398 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11399 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11400 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11401 log("Premium capability "
11402 + TelephonyManager.convertPremiumCapabilityToString(capability)
11403 + " is not available for purchase due to missing permissions.");
11404 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11405 + "permission READ_BASIC_PHONE_STATE.");
11406 }
11407
11408 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011409 if (phone == null) {
11410 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11411 return false;
11412 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011413 final long identity = Binder.clearCallingIdentity();
11414 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011415 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011416 .isPremiumCapabilityAvailableForPurchase(capability);
11417 } finally {
11418 Binder.restoreCallingIdentity(identity);
11419 }
11420 }
11421
11422 /**
11423 * Purchase the given premium capability from the carrier.
11424 *
11425 * @param capability The premium capability to purchase.
11426 * @param callback The result of the purchase request.
11427 * @param subId The subId to purchase the premium capability for.
11428 */
11429 @Override
11430 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11431 log("purchasePremiumCapability: capability="
11432 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11433 + getCurrentPackageName());
11434
11435 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11436 mApp, "purchasePremiumCapability")) {
11437 log("purchasePremiumCapability "
11438 + TelephonyManager.convertPremiumCapabilityToString(capability)
11439 + " failed due to missing permissions.");
11440 throw new SecurityException("purchasePremiumCapability requires permission "
11441 + "READ_BASIC_PHONE_STATE.");
11442 }
11443
11444 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011445 if (phone == null) {
11446 try {
11447 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11448 callback.accept(result);
11449 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11450 } catch (RemoteException e) {
11451 String logStr = "Purchase premium capability "
11452 + TelephonyManager.convertPremiumCapabilityToString(capability)
11453 + " failed due to RemoteException handling null phone: " + e;
11454 if (DBG) log(logStr);
11455 AnomalyReporter.reportAnomaly(
11456 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11457 }
11458 return;
11459 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011460 String appName;
11461 try {
11462 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11463 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11464 } catch (PackageManager.NameNotFoundException e) {
11465 appName = "An application";
11466 }
11467 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11468 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011469 }
11470
11471 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011472 * Register an IMS connection state callback
11473 */
11474 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011475 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11476 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011477 if (feature == ImsFeature.FEATURE_MMTEL) {
11478 // ImsMmTelManager
11479 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11480 TelephonyPermissions
11481 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11482 mApp, subId, "registerImsStateCallback");
11483 } else if (feature == ImsFeature.FEATURE_RCS) {
11484 // ImsRcsManager or SipDelegateManager
11485 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11486 Binder.getCallingUid(), "registerImsStateCallback",
11487 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11488 Manifest.permission.READ_PRECISE_PHONE_STATE,
11489 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11490 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11491 }
11492
11493 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11494 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11495 "IMS not available on device.");
11496 }
11497
11498 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11499 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11500 }
11501
11502 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11503 if (controller == null) {
11504 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11505 "IMS not available on device.");
11506 }
11507
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011508 if (callingPackage == null) {
11509 callingPackage = getCurrentPackageName();
11510 }
11511
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011512 final long token = Binder.clearCallingIdentity();
11513 try {
11514 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011515 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011516 } catch (ImsException e) {
11517 throw new ServiceSpecificException(e.getCode());
11518 } finally {
11519 Binder.restoreCallingIdentity(token);
11520 }
11521 }
11522
11523 /**
11524 * Unregister an IMS connection state callback
11525 */
11526 @Override
11527 public void unregisterImsStateCallback(IImsStateCallback cb) {
11528 final long token = Binder.clearCallingIdentity();
11529 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11530 if (controller == null) {
11531 return;
11532 }
11533 try {
11534 controller.unregisterImsStateCallback(cb);
11535 } finally {
11536 Binder.restoreCallingIdentity(token);
11537 }
11538 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011539
11540 /**
11541 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11542 *
11543 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11544 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11545 * SecurityException.
11546 * If there is current registered network this value will be same as the registered cell
11547 * identity. If the device goes out of service the previous cell identity is cached and
11548 * will be returned. If the cache age of the Cell identity is more than 24 hours
11549 * it will be cleared and null will be returned.
11550 *
11551 */
11552 @Override
11553 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11554 String callingFeatureId) {
11555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11556 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11557 LocationAccessPolicy.checkLocationPermission(mApp,
11558 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11559 .setCallingPackage(callingPackage)
11560 .setCallingFeatureId(callingFeatureId)
11561 .setCallingPid(Binder.getCallingPid())
11562 .setCallingUid(Binder.getCallingUid())
11563 .setMethod("getLastKnownCellIdentity")
11564 .setLogAsInfo(true)
11565 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11566 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11567 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11568 .build());
11569
11570 boolean hasFinePermission =
11571 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11572 if (!hasFinePermission
11573 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11574 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011575 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011576 }
11577
11578 final long identity = Binder.clearCallingIdentity();
11579 try {
11580 Phone phone = getPhone(subId);
11581 if (phone == null) return null;
11582 ServiceStateTracker sst = phone.getServiceStateTracker();
11583 if (sst == null) return null;
11584 return sst.getLastKnownCellIdentity();
11585 } finally {
11586 Binder.restoreCallingIdentity(identity);
11587 }
11588 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011589
jimsun3b9ccac2021-10-26 15:01:23 +080011590 /**
11591 * Sets the modem service class Name that Telephony will bind to.
11592 *
11593 * @param serviceName The class name of the modem service.
11594 * @return true if the operation is succeed, otherwise false.
11595 */
11596 public boolean setModemService(String serviceName) {
11597 Log.d(LOG_TAG, "setModemService - " + serviceName);
11598 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11600 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11601 "setModemService");
11602 return mPhoneConfigurationManager.setModemService(serviceName);
11603 }
11604
11605 /**
11606 * Return the class name of the currently bounded modem service.
11607 *
11608 * @return the class name of the modem service.
11609 */
11610 public String getModemService() {
11611 String result;
11612 Log.d(LOG_TAG, "getModemService");
11613 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11614 TelephonyPermissions
11615 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11616 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11617 "getModemService");
11618 result = mPhoneConfigurationManager.getModemService();
11619 Log.d(LOG_TAG, "result = " + result);
11620 return result;
11621 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011622
11623 @Override
11624 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11625 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11626 mApp.enforceCallingOrSelfPermission(
11627 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11628 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11629
11630 final long identity = Binder.clearCallingIdentity();
11631 try {
11632 Phone phone = getPhone(subId);
11633 if (phone == null) return;
11634 phone.setVoiceServiceStateOverride(hasService);
11635 } finally {
11636 Binder.restoreCallingIdentity(identity);
11637 }
11638 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011639
11640 /**
11641 * set removable eSIM as default eUICC.
11642 *
11643 * @hide
11644 */
11645 @Override
11646 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11647 enforceModifyPermission();
11648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11649
11650 final long identity = Binder.clearCallingIdentity();
11651 try {
11652 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11653 } finally {
11654 Binder.restoreCallingIdentity(identity);
11655 }
11656 }
11657
11658 /**
11659 * Returns whether the removable eSIM is default eUICC or not.
11660 *
11661 * @hide
11662 */
11663 @Override
11664 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11665 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11667
11668 final long identity = Binder.clearCallingIdentity();
11669 try {
11670 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11671 } finally {
11672 Binder.restoreCallingIdentity(identity);
11673 }
11674 }
11675
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011676 /**
11677 * Get the component name of the default app to direct respond-via-message intent for the
11678 * user associated with this subscription, update the cache if there is no respond-via-message
11679 * application currently configured for this user.
11680 * @return component name of the app and class to direct Respond Via Message intent to, or
11681 * {@code null} if the functionality is not supported.
11682 * @hide
11683 */
11684 @Override
11685 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11686 boolean updateIfNeeded) {
11687 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011688
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011689 Context context = getPhone(subId).getContext();
11690 UserHandle userHandle = null;
11691 final long identity = Binder.clearCallingIdentity();
11692 try {
11693 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11694 } finally {
11695 Binder.restoreCallingIdentity(identity);
11696 }
11697 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11698 updateIfNeeded, userHandle);
11699 }
Jack Yuf5badd92022-12-08 00:50:53 -080011700
11701 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011702 * Set whether the device is able to connect with null ciphering or integrity
11703 * algorithms. This is a global setting and will apply to all active subscriptions
11704 * and all new subscriptions after this.
11705 *
11706 * @param enabled when true, null cipher and integrity algorithms are allowed.
11707 * @hide
11708 */
11709 @Override
11710 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11711 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11712 enforceModifyPermission();
11713 checkForNullCipherAndIntegritySupport();
11714
11715 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11716 // for listening to these preference changes and applying them immediately.
11717 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11718 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11719 editor.apply();
11720
11721 for (Phone phone: PhoneFactory.getPhones()) {
11722 phone.handleNullCipherEnabledChange();
11723 }
11724 }
11725
11726
11727 /**
11728 * Get whether the device is able to connect with null ciphering or integrity
11729 * algorithms. Note that this retrieves the phone-global preference and not
11730 * the state of the radio.
11731 *
11732 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11733 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11734 * version for this feature.
11735 * @hide
11736 */
11737 @Override
11738 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11739 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11740 enforceReadPermission();
11741 checkForNullCipherAndIntegritySupport();
11742 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11743 }
11744
11745 private void checkForNullCipherAndIntegritySupport() {
11746 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11747 throw new UnsupportedOperationException(
11748 "Null cipher and integrity operations require HAL 2.1 or above");
11749 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011750 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11751 throw new UnsupportedOperationException(
11752 "Null cipher and integrity operations unsupported by modem");
11753 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011754 }
11755
11756 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011757 * Get the SIM state for the slot index.
11758 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11759 *
11760 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11761 */
11762 @Override
11763 @SimState
11764 public int getSimStateForSlotIndex(int slotIndex) {
11765 IccCardConstants.State simState;
11766 if (slotIndex < 0) {
11767 simState = IccCardConstants.State.UNKNOWN;
11768 } else {
11769 Phone phone = null;
11770 try {
11771 phone = PhoneFactory.getPhone(slotIndex);
11772 } catch (IllegalStateException e) {
11773 // ignore
11774 }
11775 if (phone == null) {
11776 simState = IccCardConstants.State.UNKNOWN;
11777 } else {
11778 IccCard icc = phone.getIccCard();
11779 if (icc == null) {
11780 simState = IccCardConstants.State.UNKNOWN;
11781 } else {
11782 simState = icc.getState();
11783 }
11784 }
11785 }
11786 return simState.ordinal();
11787 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011788
11789 /**
11790 * Get current cell broadcast ranges.
11791 */
11792 @Override
11793 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11794 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11795 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11796 "getCellBroadcastIdRanges");
11797 final long identity = Binder.clearCallingIdentity();
11798 try {
11799 return getPhone(subId).getCellBroadcastIdRanges();
11800 } finally {
11801 Binder.restoreCallingIdentity(identity);
11802 }
11803 }
11804
11805 /**
11806 * Set reception of cell broadcast messages with the list of the given ranges
11807 *
11808 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11809 */
11810 @Override
11811 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11812 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11813 @Nullable IIntegerConsumer callback) {
11814 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11815 "setCellBroadcastIdRanges");
11816 final long identity = Binder.clearCallingIdentity();
11817 try {
11818 Phone phone = getPhoneFromSubId(subId);
11819 if (DBG) {
11820 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11821 }
11822 phone.setCellBroadcastIdRanges(ranges, result -> {
11823 if (callback != null) {
11824 try {
11825 callback.accept(result);
11826 } catch (RemoteException e) {
11827 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
11828 }
11829 }
11830 });
11831 } finally {
11832 Binder.restoreCallingIdentity(identity);
11833 }
11834 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000011835
11836 /**
11837 * Returns whether the device supports the domain selection service.
11838 *
11839 * @return {@code true} if the device supports the domain selection service.
11840 */
11841 @Override
11842 public boolean isDomainSelectionSupported() {
11843 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11844 "isDomainSelectionSupported");
11845
11846 final long identity = Binder.clearCallingIdentity();
11847 try {
11848 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
11849 } finally {
11850 Binder.restoreCallingIdentity(identity);
11851 }
11852 }
arunvoddud5c6ce02022-12-11 06:03:12 +000011853
11854 /**
11855 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
11856 *
11857 * <p>This method behaves in one of the following ways:
11858 * <ul>
11859 * <li>return true : if the calling package has the appop permission {@link
11860 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
11861 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
11862 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
11863 * Owner device identifier access check, or the calling package has carrier privileges</>
11864 * <li>throw SecurityException: if the caller does not meet any of the requirements.
11865 * </ul>
11866 */
11867 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
11868 String callingPackage, @Nullable String callingFeatureId, String message) {
11869 for (Phone phone : PhoneFactory.getPhones()) {
11870 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
11871 phone.getSubId(), callingPackage, callingFeatureId, message)) {
11872 return true;
11873 }
11874 }
11875 return false;
11876 }
11877}