blob: c1288e5873e9500b1344f8849017c1268d727a10 [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;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
54import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080056import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.Looper;
58import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070059import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080060import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070061import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080063import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080064import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070065import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070066import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080067import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070069import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070071import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070072import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080073import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070074import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090075import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080076import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080077import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070078import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080079import android.telephony.AccessNetworkConstants;
80import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070081import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070082import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070084import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080085import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070086import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080087import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060088import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070089import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080090import android.telephony.CellIdentityCdma;
91import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070093import android.telephony.CellInfoGsm;
94import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070095import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080096import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070097import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070098import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070099import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800100import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700101import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800102import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700103import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800104import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800105import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700106import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800107import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800109import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800110import android.telephony.SignalStrengthUpdateRequest;
111import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800112import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800113import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800114import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700115import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700116import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800117import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800118import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800119import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800120import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000121import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000122import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000123import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700124import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700125import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800126import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800127import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700128import android.telephony.gba.GbaAuthRequest;
129import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700130import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800131import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000132import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000133import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700134import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000135import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700136import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800137import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700138import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800139import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700140import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000141import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700142import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800144import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800146import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700147import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800149import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800150
Andrew Lee312e8172014-10-23 17:01:36 -0700151import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800152import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800153import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800154import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800155import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700157import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700158import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800159import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800160import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800163import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700164import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800165import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800166import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800167import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700168import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000169import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800171import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800173import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800174import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800175import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700176import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700177import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700178import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700180import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800181import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700182import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700183import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700184import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700185import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800186import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800187import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700188import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000189import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700190import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700191import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800192import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800193import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800194import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700195import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000196import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800197import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700198import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800199import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700200import com.android.internal.telephony.imsphone.ImsPhone;
201import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000202import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800203import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800204import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
205import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700206import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700207import com.android.internal.telephony.uicc.IccIoResult;
208import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800209import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700210import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800211import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700212import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000213import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800214import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000215import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800216import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000217import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700218import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700219import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800220import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800221import com.android.phone.callcomposer.CallComposerPictureManager;
222import com.android.phone.callcomposer.CallComposerPictureTransfer;
223import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700224import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700225import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700226import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800227import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700228import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700229import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800230import com.android.services.telephony.TelecomAccountRegistry;
231import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800232import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800233
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700235import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.io.IOException;
237import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700238import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800240import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000241import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800242import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800243import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800244import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800245import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100246import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800247import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700248import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800249import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800250import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700251import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800252import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800253import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800254import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255
256/**
257 * Implementation of the ITelephony interface.
258 */
Santos Cordon117fee72014-05-16 17:56:12 -0700259public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260 private static final String LOG_TAG = "PhoneInterfaceManager";
261 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
262 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800263 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264
265 // Message codes used with mMainThreadHandler
266 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700267 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
268 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700269 private static final int CMD_OPEN_CHANNEL = 9;
270 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
271 private static final int CMD_CLOSE_CHANNEL = 11;
272 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800273 private static final int CMD_NV_READ_ITEM = 13;
274 private static final int EVENT_NV_READ_ITEM_DONE = 14;
275 private static final int CMD_NV_WRITE_ITEM = 15;
276 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
277 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
278 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700279 private static final int CMD_RESET_MODEM_CONFIG = 19;
280 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800281 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
282 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800283 private static final int CMD_SEND_ENVELOPE = 25;
284 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000285 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
286 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700287 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
288 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
289 private static final int CMD_EXCHANGE_SIM_IO = 31;
290 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800291 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
292 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700293 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
294 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700295 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
296 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700297 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
298 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
299 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
300 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700301 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
302 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
303 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
304 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700305 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800306 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
307 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000308 private static final int CMD_SWITCH_SLOTS = 50;
309 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700310 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
311 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
312 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
313 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
314 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
315 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
316 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
317 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700318 private static final int CMD_GET_ALL_CELL_INFO = 60;
319 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
320 private static final int CMD_GET_CELL_LOCATION = 62;
321 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700322 private static final int CMD_MODEM_REBOOT = 64;
323 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700324 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
325 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800326 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
327 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700328 private static final int CMD_GET_MODEM_STATUS = 70;
329 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700330 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
331 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700332 private static final int CMD_ERASE_MODEM_CONFIG = 74;
333 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800334 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
335 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
336 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
337 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800338 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
339 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800340 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800341 private static final int CMD_GET_CALL_FORWARDING = 83;
342 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
343 private static final int CMD_SET_CALL_FORWARDING = 85;
344 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
345 private static final int CMD_GET_CALL_WAITING = 87;
346 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
347 private static final int CMD_SET_CALL_WAITING = 89;
348 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700349 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
350 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
351 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
352 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700353 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
354 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800355 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
356 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800357 private static final int CMD_SET_DATA_THROTTLING = 99;
358 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800359 private static final int CMD_SET_SIM_POWER = 101;
360 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800361 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
362 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
363 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
364 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800365 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
366 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000367 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800368 private static final int CMD_GET_SLICING_CONFIG = 110;
369 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800370 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700371 private static final int CMD_ENABLE_VONR = 113;
372 private static final int EVENT_ENABLE_VONR_DONE = 114;
373 private static final int CMD_IS_VONR_ENABLED = 115;
374 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700375 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
376 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800378 // Parameters of select command.
379 private static final int SELECT_COMMAND = 0xA4;
380 private static final int SELECT_P1 = 0x04;
381 private static final int SELECT_P2 = 0;
382 private static final int SELECT_P3 = 0x10;
383
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000384 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
385 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 /** The singleton instance. */
388 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800389 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390
Wink Saville3ab207e2014-11-20 13:07:20 -0800391 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800392 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800393 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700394 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800395 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700396 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800397 private MainThreadHandler mMainThreadHandler;
Aishwarya Mallampati32336e82023-01-04 23:02:56 +0000398 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800399 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700400 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800401 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000402 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
Peter Wangdafb9ac2020-01-15 14:13:38 -0800404 /** User Activity */
405 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800406 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
407
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700408 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
409
Derek Tan97ebb422014-09-05 16:55:38 -0700410 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
411 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800412 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800413 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700414
Michelecea4cf22018-12-21 15:00:11 -0800415 // String to store multi SIM allowed
416 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
417
Derek Tan740e1672017-06-27 14:56:27 -0700418 // The AID of ISD-R.
419 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
420
yinxub1bed742017-04-17 11:45:04 -0700421 private NetworkScanRequestTracker mNetworkScanRequestTracker;
422
David Kelly5e06a7f2018-03-12 14:10:59 +0000423 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
424 private static final int MANUFACTURER_CODE_LENGTH = 8;
425
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800426 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800427 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800428
Sarah Chin2ec39f62022-08-31 17:03:26 -0700429 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
430 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
431
Derek Tan89e89d42014-07-08 17:00:10 -0700432 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700433 * Experiment flag to enable erase modem config on reset network, default value is false
434 */
435 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
436 "reset_network_erase_modem_config_enabled";
437
Rambo Wang0f050d82021-02-12 11:43:36 -0800438 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800439
sandeepjsb6c87872021-09-27 15:34:44 +0000440 /**
441 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
442 * one ICCID active at the same time.
443 * Apps should use below API signatures if targeting SDK is T and beyond.
444 *
445 * @hide
446 */
447 @ChangeId
448 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
449 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800450
Naina Nallurid63128d2019-09-17 14:10:30 -0700451 /**
Chen Xu540470b2021-12-14 17:15:47 -0800452 * Apps targeting on Android T and beyond will get exception whenever icc close channel
453 * operation fails.
454 */
455 @ChangeId
456 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
457 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
458
459 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 * A request object to use for transmitting data to an ICC.
461 */
462 private static final class IccAPDUArgument {
463 public int channel, cla, command, p1, p2, p3;
464 public String data;
465
466 public IccAPDUArgument(int channel, int cla, int command,
467 int p1, int p2, int p3, String data) {
468 this.channel = channel;
469 this.cla = cla;
470 this.command = command;
471 this.p1 = p1;
472 this.p2 = p2;
473 this.p3 = p3;
474 this.data = data;
475 }
476 }
477
478 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700479 * A request object to use for transmitting data to an ICC.
480 */
481 private static final class ManualNetworkSelectionArgument {
482 public OperatorInfo operatorInfo;
483 public boolean persistSelection;
484
485 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
486 this.operatorInfo = operatorInfo;
487 this.persistSelection = persistSelection;
488 }
489 }
490
Sarah Chin71b3a852022-09-28 15:54:19 -0700491 private static final class PurchasePremiumCapabilityArgument {
492 public @TelephonyManager.PremiumCapability int capability;
493 public @NonNull String appName;
494 public @NonNull IIntegerConsumer callback;
495
496 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
497 @NonNull String appName, @NonNull IIntegerConsumer callback) {
498 this.capability = capability;
499 this.appName = appName;
500 this.callback = callback;
501 }
502 }
503
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700504 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
506 * request after sending. The main thread will notify the request when it is complete.
507 */
508 private static final class MainThreadRequest {
509 /** The argument to use for the request */
510 public Object argument;
511 /** The result of the request that is run on the main thread */
512 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800513 // The subscriber id that this request applies to. Defaults to
514 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
515 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516
Nathan Harold92bed182018-10-12 18:16:49 -0700517 // In cases where subId is unavailable, the caller needs to specify the phone.
518 public Phone phone;
519
vagdeviaf9a5b92018-08-15 16:01:53 -0700520 public WorkSource workSource;
521
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 public MainThreadRequest(Object argument) {
523 this.argument = argument;
524 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800525
Nathan Harold92bed182018-10-12 18:16:49 -0700526 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
527 this.argument = argument;
528 if (phone != null) {
529 this.phone = phone;
530 }
531 this.workSource = workSource;
532 }
533
vagdeviaf9a5b92018-08-15 16:01:53 -0700534 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800535 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800536 if (subId != null) {
537 this.subId = subId;
538 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700539 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 }
542
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800543 private static final class IncomingThirdPartyCallArgs {
544 public final ComponentName component;
545 public final String callId;
546 public final String callerDisplayName;
547
548 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
549 String callerDisplayName) {
550 this.component = component;
551 this.callId = callId;
552 this.callerDisplayName = callerDisplayName;
553 }
554 }
555
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 /**
557 * A handler that processes messages on the main thread in the phone process. Since many
558 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
559 * inbound binder threads to the main thread in the phone process. The Binder thread
560 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
561 * on, which will be notified when the operation completes and will contain the result of the
562 * request.
563 *
564 * <p>If a MainThreadRequest object is provided in the msg.obj field,
565 * note that request.result must be set to something non-null for the calling thread to
566 * unblock.
567 */
568 private final class MainThreadHandler extends Handler {
569 @Override
570 public void handleMessage(Message msg) {
571 MainThreadRequest request;
572 Message onCompleted;
573 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000574 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800576 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577
578 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 case CMD_HANDLE_USSD_REQUEST: {
580 request = (MainThreadRequest) msg.obj;
581 final Phone phone = getPhoneFromRequest(request);
582 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800583 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700585
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 if (!isUssdApiAllowed(request.subId)) {
587 // Carrier does not support use of this API, return failure.
588 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
589 UssdResponse response = new UssdResponse(ussdRequest, null);
590 Bundle returnData = new Bundle();
591 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
592 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700593
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 request.result = true;
595 notifyRequester(request);
596 return;
597 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700598
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 try {
600 request.result = phone != null
601 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
602 } catch (CallStateException cse) {
603 request.result = false;
604 }
605 // Wake up the requesting thread
606 notifyRequester(request);
607 break;
pkanwar32d516d2016-10-14 19:37:38 -0700608 }
609
Yorke Lee716f67e2015-06-17 15:39:16 -0700610 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700612 final Phone phone = getPhoneFromRequest(request);
613 request.result = phone != null ?
614 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
615 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000624 uiccPort = getUiccPortFromRequest(request);
625 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800627 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000632 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800633 iccArgument.channel, iccArgument.cla, iccArgument.command,
634 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
635 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
644 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 if (ar.result == null) {
647 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800648 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800650 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
652 loge("iccTransmitApduLogicalChannel: Unknown exception");
653 }
654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 break;
657
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
659 request = (MainThreadRequest) msg.obj;
660 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000661 uiccPort = getUiccPortFromRequest(request);
662 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800664 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 } else {
667 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000669 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800670 iccArgument.cla, iccArgument.command, iccArgument.p1,
671 iccArgument.p2,
672 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 }
674 break;
675
676 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 if (ar.result == null) {
684 loge("iccTransmitApduBasicChannel: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("iccTransmitApduBasicChannel: CommandException: " +
687 ar.exception);
688 } else {
689 loge("iccTransmitApduBasicChannel: Unknown exception");
690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 break;
694
695 case CMD_EXCHANGE_SIM_IO:
696 request = (MainThreadRequest) msg.obj;
697 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000698 uiccPort = getUiccPortFromRequest(request);
699 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800701 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 } else {
704 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
705 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000706 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
708 iccArgument.data, onCompleted);
709 }
710 break;
711
712 case EVENT_EXCHANGE_SIM_IO_DONE:
713 ar = (AsyncResult) msg.obj;
714 request = (MainThreadRequest) ar.userObj;
715 if (ar.exception == null && ar.result != null) {
716 request.result = ar.result;
717 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800718 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 break;
722
Derek Tan4d5e5c12014-02-04 11:54:58 -0800723 case CMD_SEND_ENVELOPE:
724 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000725 uiccPort = getUiccPortFromRequest(request);
726 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800728 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 } else {
731 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800732 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800734 break;
735
736 case EVENT_SEND_ENVELOPE_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700739 if (ar.exception == null && ar.result != null) {
740 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800741 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700743 if (ar.result == null) {
744 loge("sendEnvelopeWithStatus: Empty response");
745 } else if (ar.exception instanceof CommandException) {
746 loge("sendEnvelopeWithStatus: CommandException: " +
747 ar.exception);
748 } else {
749 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
750 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800753 break;
754
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 case CMD_OPEN_CHANNEL:
756 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000757 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800758 IccLogicalChannelRequest openChannelRequest =
759 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000760 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700761 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800762 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800763 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 } else {
766 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800767 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
768 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 break;
771
772 case EVENT_OPEN_CHANNEL_DONE:
773 ar = (AsyncResult) msg.obj;
774 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700775 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700777 int[] result = (int[]) ar.result;
778 int channelId = result[0];
779 byte[] selectResponse = null;
780 if (result.length > 1) {
781 selectResponse = new byte[result.length - 1];
782 for (int i = 1; i < result.length; ++i) {
783 selectResponse[i - 1] = (byte) result[i];
784 }
785 }
786 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800787 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800788
789 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700790 if (uiccPort == null) {
791 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
792 } else {
793 IccLogicalChannelRequest channelRequest =
794 (IccLogicalChannelRequest) request.argument;
795 channelRequest.channel = channelId;
796 uiccPort.onLogicalChannelOpened(channelRequest);
797 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 if (ar.result == null) {
800 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700802 if (ar.exception != null) {
803 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
804 }
805
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700806 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700807 if (ar.exception instanceof CommandException) {
808 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800809 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700810 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700811 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700812 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700813 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700814 }
815 }
816 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800817 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700818 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700819 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700820 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 break;
822
823 case CMD_CLOSE_CHANNEL:
824 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000825 uiccPort = getUiccPortFromRequest(request);
826 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700827 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800828 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800829 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800830 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700831 } else {
832 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000833 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700834 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 break;
836
837 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null) {
841 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800842 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700843 if (uiccPort == null) {
844 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
845 } else {
846 final int channelId = (Integer) request.argument;
847 uiccPort.onLogicalChannelClosed(channelId);
848 }
Chen Xu540470b2021-12-14 17:15:47 -0800849 } else {
850 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800851 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800852 if (ar.exception instanceof CommandException) {
853 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
854 CommandException.Error error =
855 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800856 if (error == CommandException.Error.INVALID_ARGUMENTS) {
857 // should only throw exceptions from the binder threads.
858 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800859 "iccCloseLogicalChannel: invalid argument ");
860 }
861 } else {
862 loge("iccCloseLogicalChannel: Unknown exception");
863 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800864 request.result = (exception != null) ? exception :
865 new IllegalStateException(
866 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800867 }
868 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case CMD_NV_READ_ITEM:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800874 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
875 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800876 break;
877
878 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800881 if (ar.exception == null && ar.result != null) {
882 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700883 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800884 request.result = "";
885 if (ar.result == null) {
886 loge("nvReadItem: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("nvReadItem: CommandException: " +
889 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700890 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800891 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700892 }
893 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700895 break;
896
Jake Hambye994d462014-02-03 13:10:13 -0800897 case CMD_NV_WRITE_ITEM:
898 request = (MainThreadRequest) msg.obj;
899 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
900 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800901 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700902 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800903 break;
904
905 case EVENT_NV_WRITE_ITEM_DONE:
906 handleNullReturnEvent(msg, "nvWriteItem");
907 break;
908
909 case CMD_NV_WRITE_CDMA_PRL:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800913 break;
914
915 case EVENT_NV_WRITE_CDMA_PRL_DONE:
916 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
917 break;
918
chen xu6dac5ab2018-10-26 17:39:23 -0700919 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800920 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700921 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800923 break;
924
chen xu6dac5ab2018-10-26 17:39:23 -0700925 case EVENT_RESET_MODEM_CONFIG_DONE:
926 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800927 break;
928
Sooraj Sasindran37444802020-08-11 10:40:43 -0700929 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
930 request = (MainThreadRequest) msg.obj;
931 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
932 request);
933 Phone phone = getPhoneFromRequest(request);
934 if (phone != null) {
935 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
936 } else {
937 loge("isNRDualConnectivityEnabled: No phone object");
938 request.result = false;
939 notifyRequester(request);
940 }
941 break;
942 }
943
944 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
947 if (ar.exception == null && ar.result != null) {
948 request.result = ar.result;
949 } else {
950 // request.result must be set to something non-null
951 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700952 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700953 request.result = ar.result;
954 } else {
955 request.result = false;
956 }
957 if (ar.result == null) {
958 loge("isNRDualConnectivityEnabled: Empty response");
959 } else if (ar.exception instanceof CommandException) {
960 loge("isNRDualConnectivityEnabled: CommandException: "
961 + ar.exception);
962 } else {
963 loge("isNRDualConnectivityEnabled: Unknown exception");
964 }
965 }
966 notifyRequester(request);
967 break;
968
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700969 case CMD_IS_VONR_ENABLED: {
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
972 request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.isVoNrEnabled(onCompleted, request.workSource);
976 } else {
977 loge("isVoNrEnabled: No phone object");
978 request.result = false;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_IS_VONR_ENABLED_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null && ar.result != null) {
988 request.result = ar.result;
989 } else {
990 // request.result must be set to something non-null
991 // for the calling thread to unblock
992 if (ar.result != null) {
993 request.result = ar.result;
994 } else {
995 request.result = false;
996 }
997 if (ar.result == null) {
998 loge("isVoNrEnabled: Empty response");
999 } else if (ar.exception instanceof CommandException) {
1000 loge("isVoNrEnabled: CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("isVoNrEnabled: Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008
Sooraj Sasindran37444802020-08-11 10:40:43 -07001009 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1012 Phone phone = getPhoneFromRequest(request);
1013 if (phone != null) {
1014 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1015 request.workSource);
1016 } else {
1017 loge("enableNrDualConnectivity: No phone object");
1018 request.result =
1019 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1020 notifyRequester(request);
1021 }
1022 break;
1023 }
1024
1025 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception == null) {
1029 request.result =
1030 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1031 } else {
1032 request.result =
1033 TelephonyManager
1034 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1035 if (ar.exception instanceof CommandException) {
1036 CommandException.Error error =
1037 ((CommandException) (ar.exception)).getCommandError();
1038 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1039 request.result =
1040 TelephonyManager
1041 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001042 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1043 request.result =
1044 TelephonyManager
1045 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001046 }
1047 loge("enableNrDualConnectivity" + ": CommandException: "
1048 + ar.exception);
1049 } else {
1050 loge("enableNrDualConnectivity" + ": Unknown exception");
1051 }
1052 }
1053 notifyRequester(request);
1054 break;
1055 }
1056
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001057 case CMD_ENABLE_VONR: {
1058 request = (MainThreadRequest) msg.obj;
1059 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1060 Phone phone = getPhoneFromRequest(request);
1061 if (phone != null) {
1062 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1063 request.workSource);
1064 } else {
1065 loge("setVoNrEnabled: No phone object");
1066 request.result =
1067 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1068 notifyRequester(request);
1069 }
1070 break;
1071 }
1072
1073 case EVENT_ENABLE_VONR_DONE: {
1074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 if (ar.exception == null) {
1077 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1078 } else {
1079 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1080 if (ar.exception instanceof CommandException) {
1081 CommandException.Error error =
1082 ((CommandException) (ar.exception)).getCommandError();
1083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1084 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1085 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1086 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1087 } else {
1088 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1089 }
1090 loge("setVoNrEnabled" + ": CommandException: "
1091 + ar.exception);
1092 } else {
1093 loge("setVoNrEnabled" + ": Unknown exception");
1094 }
1095 }
1096 notifyRequester(request);
1097 break;
1098 }
1099
SongFerngWang3ef3e072020-12-21 16:41:52 +08001100 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001102 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1103 request);
1104 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 break;
1106
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null && ar.result != null) {
1111 request.result = ar.result; // Integer
1112 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301113 // request.result must be set to something non-null
1114 // for the calling thread to unblock
1115 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001118 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 loge("getAllowedNetworkTypesBitmask: CommandException: "
1120 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001121 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001122 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 }
1124 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001125 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 break;
1127
SongFerngWang3ef3e072020-12-21 16:41:52 +08001128 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001129 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001130 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1131 request);
1132 Pair<Integer, Long> reasonWithNetworkTypes =
1133 (Pair<Integer, Long>) request.argument;
1134 getPhoneFromRequest(request).setAllowedNetworkTypes(
1135 reasonWithNetworkTypes.first,
1136 reasonWithNetworkTypes.second,
1137 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 break;
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1141 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 break;
1143
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001144 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1145 request = (MainThreadRequest)msg.obj;
1146 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001147 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001148 break;
1149
1150 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1151 ar = (AsyncResult)msg.obj;
1152 request = (MainThreadRequest)ar.userObj;
1153 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001154 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001155 break;
1156
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001157 case CMD_SET_VOICEMAIL_NUMBER:
1158 request = (MainThreadRequest) msg.obj;
1159 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1160 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001161 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1162 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001163 break;
1164
1165 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1166 handleNullReturnEvent(msg, "setVoicemailNumber");
1167 break;
1168
Stuart Scott54788802015-03-30 13:18:01 -07001169 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1170 request = (MainThreadRequest) msg.obj;
1171 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1172 request);
1173 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1174 break;
1175
1176 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1177 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1178 break;
1179
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 case CMD_PERFORM_NETWORK_SCAN:
1181 request = (MainThreadRequest) msg.obj;
1182 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1183 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1184 break;
1185
Hall Liu27d24262020-09-18 19:04:59 -07001186 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001189 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1190 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1191 request.argument;
1192 int callForwardingReason = args.first;
1193 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001194 break;
Hall Liu27d24262020-09-18 19:04:59 -07001195 }
1196 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001199 TelephonyManager.CallForwardingInfoCallback callback =
1200 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1201 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001203 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1205 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1206 // Service Class is a bit mask per 3gpp 27.007. Search for
1207 // any service for voice call.
1208 if ((callForwardInfo.serviceClass
1209 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001210 callForwardingInfo = new CallForwardingInfo(
1211 callForwardInfo.status
1212 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001213 callForwardInfo.reason,
1214 callForwardInfo.number,
1215 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001216 break;
1217 }
1218 }
1219 // Didn't find a call forward info for voice call.
1220 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001221 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1222 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001223 }
Hall Liu27d24262020-09-18 19:04:59 -07001224 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else {
1226 if (ar.result == null) {
1227 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1228 }
1229 if (ar.exception != null) {
1230 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1231 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001232 int errorCode = TelephonyManager
1233 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001234 if (ar.exception instanceof CommandException) {
1235 CommandException.Error error =
1236 ((CommandException) (ar.exception)).getCommandError();
1237 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001238 errorCode = TelephonyManager
1239 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001240 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001241 errorCode = TelephonyManager
1242 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001243 }
1244 }
Hall Liu27d24262020-09-18 19:04:59 -07001245 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247 break;
Hall Liu27d24262020-09-18 19:04:59 -07001248 }
Shuo Qian4a594052020-01-23 11:59:30 -08001249
Hall Liu27d24262020-09-18 19:04:59 -07001250 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001251 request = (MainThreadRequest) msg.obj;
1252 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001253 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001254 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001255 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1256 request.argument).first;
1257 request.phone.setCallForwardingOption(
1258 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001259 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001260 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001261 callForwardingInfoToSet.getReason(),
1262 callForwardingInfoToSet.getNumber(),
1263 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266
Hall Liu27d24262020-09-18 19:04:59 -07001267 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001270 Consumer<Integer> callback =
1271 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1272 request.argument).second;
1273 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001274 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 int errorCode = TelephonyManager.CallForwardingInfoCallback
1276 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001277 if (ar.exception instanceof CommandException) {
1278 CommandException.Error error =
1279 ((CommandException) (ar.exception)).getCommandError();
1280 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001281 errorCode = TelephonyManager.CallForwardingInfoCallback
1282 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001283 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001284 errorCode = TelephonyManager.CallForwardingInfoCallback
1285 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001286 }
1287 }
1288 callback.accept(errorCode);
1289 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001290 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001291 }
Shuo Qian4a594052020-01-23 11:59:30 -08001292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 request = (MainThreadRequest) msg.obj;
1297 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1298 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1299 break;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
Shuo Qian4a594052020-01-23 11:59:30 -08001301
Hall Liu27d24262020-09-18 19:04:59 -07001302 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001305 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001306 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001307 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001308 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001309 // Service Class is a bit mask per 3gpp 27.007.
1310 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001311 if (callForwardResults.length > 1
1312 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001313 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001314 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001315 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1316 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001317 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001318 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001319 }
1320 } else {
1321 if (ar.result == null) {
1322 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1323 }
1324 if (ar.exception != null) {
1325 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1326 }
1327 if (ar.exception instanceof CommandException) {
1328 CommandException.Error error =
1329 ((CommandException) (ar.exception)).getCommandError();
1330 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001332 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1334 callWaitingStatus =
1335 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 }
1337 }
1338 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001339 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001340 break;
Hall Liu27d24262020-09-18 19:04:59 -07001341 }
Shuo Qian4a594052020-01-23 11:59:30 -08001342
Hall Liu27d24262020-09-18 19:04:59 -07001343 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001344 request = (MainThreadRequest) msg.obj;
1345 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001346 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1347 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001348 break;
Hall Liu27d24262020-09-18 19:04:59 -07001349 }
Shuo Qian4a594052020-01-23 11:59:30 -08001350
Hall Liu27d24262020-09-18 19:04:59 -07001351 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001354 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1355 Consumer<Integer> callback =
1356 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1357 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001358 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1363 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001364 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1365 callback.accept(
1366 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001367 } else {
1368 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1369 }
1370 } else {
1371 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1372 }
1373 } else {
1374 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1375 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001376 }
Shuo Qian4a594052020-01-23 11:59:30 -08001377 break;
Hall Liu27d24262020-09-18 19:04:59 -07001378 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001379 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 CellNetworkScanResult cellScanResult;
1383 if (ar.exception == null && ar.result != null) {
1384 cellScanResult = new CellNetworkScanResult(
1385 CellNetworkScanResult.STATUS_SUCCESS,
1386 (List<OperatorInfo>) ar.result);
1387 } else {
1388 if (ar.result == null) {
1389 loge("getCellNetworkScanResults: Empty response");
1390 }
1391 if (ar.exception != null) {
1392 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1393 }
1394 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1395 if (ar.exception instanceof CommandException) {
1396 CommandException.Error error =
1397 ((CommandException) (ar.exception)).getCommandError();
1398 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1399 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1400 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1401 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1402 }
1403 }
1404 cellScanResult = new CellNetworkScanResult(errorCode, null);
1405 }
1406 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001407 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001408 break;
1409
1410 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1411 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001412 ManualNetworkSelectionArgument selArg =
1413 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001414 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1415 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001416 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1417 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001418 break;
1419
1420 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception == null) {
1424 request.result = true;
1425 } else {
1426 request.result = false;
1427 loge("setNetworkSelectionModeManual " + ar.exception);
1428 }
1429 notifyRequester(request);
1430 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001431 break;
1432
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001433 case CMD_GET_MODEM_ACTIVITY_INFO:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001436 if (defaultPhone != null) {
1437 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 } else {
1439 ResultReceiver result = (ResultReceiver) request.argument;
1440 Bundle bundle = new Bundle();
1441 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001442 new ModemActivityInfo(0, 0, 0,
1443 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001444 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001445 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 break;
1447
Hall Liud0f208c2020-10-14 16:54:44 -07001448 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001452 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001453 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001454 if (mLastModemActivityInfo == null) {
1455 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1456 mLastModemActivitySpecificInfo[0] =
1457 new ActivityStatsTechSpecificInfo(
1458 0,
1459 0,
1460 new int[ModemActivityInfo.getNumTxPowerLevels()],
1461 0);
1462 mLastModemActivityInfo =
1463 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1464 }
1465
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001467 // Update the last modem activity info and the result of the request.
1468 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1469 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001470 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 }
Kai Shi917fdc62022-11-28 14:01:02 -08001472 // This is needed to decouple ret from mLastModemActivityInfo
1473 // We don't want to return mLastModemActivityInfo which is updated
1474 // inside mergeModemActivityInfo()
1475 ret = new ModemActivityInfo(
1476 mLastModemActivityInfo.getTimestampMillis(),
1477 mLastModemActivityInfo.getSleepTimeMillis(),
1478 mLastModemActivityInfo.getIdleTimeMillis(),
1479 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001480
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001481 } else {
1482 if (ar.result == null) {
1483 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001484 error = TelephonyManager.ModemActivityInfoException
1485 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001486 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001487 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001488 error = TelephonyManager.ModemActivityInfoException
1489 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490 } else {
1491 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001492 error = TelephonyManager.ModemActivityInfoException
1493 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494 }
1495 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001496 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001497 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001498 bundle.putParcelable(
1499 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001500 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001501 } else {
1502 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1503 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001504 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001505 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001507 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001508
Meng Wang1a7c35a2016-05-05 20:56:15 -07001509 case CMD_SET_ALLOWED_CARRIERS:
1510 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001511 CarrierRestrictionRules argument =
1512 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001514 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 break;
1516
1517 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1518 ar = (AsyncResult) msg.obj;
1519 request = (MainThreadRequest) ar.userObj;
1520 if (ar.exception == null && ar.result != null) {
1521 request.result = ar.result;
1522 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001523 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1524 if (ar.exception instanceof CommandException) {
1525 loge("setAllowedCarriers: CommandException: " + ar.exception);
1526 CommandException.Error error =
1527 ((CommandException) (ar.exception)).getCommandError();
1528 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1529 request.result =
1530 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1531 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532 } else {
1533 loge("setAllowedCarriers: Unknown exception");
1534 }
1535 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001536 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 break;
1538
1539 case CMD_GET_ALLOWED_CARRIERS:
1540 request = (MainThreadRequest) msg.obj;
1541 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001542 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001543 break;
1544
1545 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 if (ar.exception == null && ar.result != null) {
1549 request.result = ar.result;
1550 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001551 request.result = new IllegalStateException(
1552 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001553 if (ar.result == null) {
1554 loge("getAllowedCarriers: Empty response");
1555 } else if (ar.exception instanceof CommandException) {
1556 loge("getAllowedCarriers: CommandException: " +
1557 ar.exception);
1558 } else {
1559 loge("getAllowedCarriers: Unknown exception");
1560 }
1561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 break;
1564
Nathan Haroldb3014052017-01-25 15:57:32 -08001565 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 if (ar.exception == null && ar.result != null) {
1569 request.result = ar.result;
1570 } else {
1571 request.result = new IllegalArgumentException(
1572 "Failed to retrieve Forbidden Plmns");
1573 if (ar.result == null) {
1574 loge("getForbiddenPlmns: Empty response");
1575 } else {
1576 loge("getForbiddenPlmns: Unknown exception");
1577 }
1578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001579 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001580 break;
1581
1582 case CMD_GET_FORBIDDEN_PLMNS:
1583 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001584 uiccPort = getUiccPortFromRequest(request);
1585 if (uiccPort == null) {
1586 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001587 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001588 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001589 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001590 break;
1591 }
1592 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001593 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001594 if (uiccApp == null) {
1595 loge("getForbiddenPlmns() no app with specified type -- "
1596 + appType);
1597 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001598 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001599 break;
1600 } else {
1601 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1602 + " specified type -- " + appType);
1603 }
1604 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1605 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1606 onCompleted);
1607 break;
1608
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001609 case CMD_SWITCH_SLOTS:
1610 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001611 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001612 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001613 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001614 break;
1615
1616 case EVENT_SWITCH_SLOTS_DONE:
1617 ar = (AsyncResult) msg.obj;
1618 request = (MainThreadRequest) ar.userObj;
1619 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001620 notifyRequester(request);
1621 break;
1622 case CMD_GET_NETWORK_SELECTION_MODE:
1623 request = (MainThreadRequest) msg.obj;
1624 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1625 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1626 break;
1627
1628 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception != null) {
1632 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1633 } else {
1634 int mode = ((int[]) ar.result)[0];
1635 if (mode == 0) {
1636 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1637 } else {
1638 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1639 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001641 notifyRequester(request);
1642 break;
1643 case CMD_GET_CDMA_ROAMING_MODE:
1644 request = (MainThreadRequest) msg.obj;
1645 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1646 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1647 break;
1648 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 if (ar.exception != null) {
1652 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1653 } else {
1654 request.result = ((int[]) ar.result)[0];
1655 }
1656 notifyRequester(request);
1657 break;
1658 case CMD_SET_CDMA_ROAMING_MODE:
1659 request = (MainThreadRequest) msg.obj;
1660 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1661 int mode = (int) request.argument;
1662 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1663 break;
1664 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
1667 request.result = ar.exception == null;
1668 notifyRequester(request);
1669 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001670 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1671 request = (MainThreadRequest) msg.obj;
1672 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1673 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1674 break;
1675 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1676 ar = (AsyncResult) msg.obj;
1677 request = (MainThreadRequest) ar.userObj;
1678 if (ar.exception != null) {
1679 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1680 } else {
1681 request.result = ((int[]) ar.result)[0];
1682 }
1683 notifyRequester(request);
1684 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001685 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1686 request = (MainThreadRequest) msg.obj;
1687 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1688 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001689 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1690 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001691 break;
1692 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 request.result = ar.exception == null;
1696 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001697 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001698 case CMD_GET_ALL_CELL_INFO:
1699 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001700 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001701 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001702 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 case EVENT_GET_ALL_CELL_INFO_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001706 // If a timeout occurs, the response will be null
1707 request.result = (ar.exception == null && ar.result != null)
1708 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 synchronized (request) {
1710 request.notifyAll();
1711 }
1712 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001713 case CMD_REQUEST_CELL_INFO_UPDATE:
1714 request = (MainThreadRequest) msg.obj;
1715 request.phone.requestCellInfoUpdate(request.workSource,
1716 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1717 break;
1718 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1719 ar = (AsyncResult) msg.obj;
1720 request = (MainThreadRequest) ar.userObj;
1721 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1722 try {
1723 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001724 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001725 cb.onError(
1726 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1727 ar.exception.getClass().getName(),
1728 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001729 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001730 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001731 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001732 } else {
1733 // use the result as returned
1734 cb.onCellInfo((List<CellInfo>) ar.result);
1735 }
1736 } catch (RemoteException re) {
1737 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1738 }
1739 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001741 request = (MainThreadRequest) msg.obj;
1742 WorkSource ws = (WorkSource) request.argument;
1743 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001744 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001746 }
1747 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001748 ar = (AsyncResult) msg.obj;
1749 request = (MainThreadRequest) ar.userObj;
1750 if (ar.exception == null) {
1751 request.result = ar.result;
1752 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001753 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001754 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001755 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001756 }
1757
1758 synchronized (request) {
1759 request.notifyAll();
1760 }
1761 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001762 }
chen xu6dac5ab2018-10-26 17:39:23 -07001763 case CMD_MODEM_REBOOT:
1764 request = (MainThreadRequest) msg.obj;
1765 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001766 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001767 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001768 case EVENT_CMD_MODEM_REBOOT_DONE:
1769 handleNullReturnEvent(msg, "rebootModem");
1770 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001771 case CMD_REQUEST_ENABLE_MODEM:
1772 request = (MainThreadRequest) msg.obj;
1773 boolean enable = (boolean) request.argument;
1774 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001775 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001776 PhoneConfigurationManager.getInstance()
1777 .enablePhone(request.phone, enable, onCompleted);
1778 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001779 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001780 ar = (AsyncResult) msg.obj;
1781 request = (MainThreadRequest) ar.userObj;
1782 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001783 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001784 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001785 if ((boolean) request.result) {
1786 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1787 updateModemStateMetrics();
1788 } else {
1789 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1790 + ar.exception);
1791 }
1792 notifyRequester(request);
1793 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001794 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001795 case CMD_GET_MODEM_STATUS:
1796 request = (MainThreadRequest) msg.obj;
1797 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1798 PhoneConfigurationManager.getInstance()
1799 .getPhoneStatusFromModem(request.phone, onCompleted);
1800 break;
1801 case EVENT_GET_MODEM_STATUS_DONE:
1802 ar = (AsyncResult) msg.obj;
1803 request = (MainThreadRequest) ar.userObj;
1804 int id = request.phone.getPhoneId();
1805 if (ar.exception == null && ar.result != null) {
1806 request.result = ar.result;
1807 //update the cache as modem status has changed
1808 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1809 (boolean) request.result);
1810 } else {
1811 // Return true if modem status cannot be retrieved. For most cases,
1812 // modem status is on. And for older version modems, GET_MODEM_STATUS
1813 // and disable modem are not supported. Modem is always on.
1814 // TODO: this should be fixed in R to support a third
1815 // status UNKNOWN b/131631629
1816 request.result = true;
1817 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1818 + ar.exception);
1819 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001820 notifyRequester(request);
1821 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001822 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1823 request = (MainThreadRequest) msg.obj;
1824 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1825 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1826 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1827 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1828 break;
1829 }
1830 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1831 ar = (AsyncResult) msg.obj;
1832 request = (MainThreadRequest) ar.userObj;
1833 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1834 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1835 args.second.accept(ar.exception == null);
1836 notifyRequester(request);
1837 break;
1838 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001839 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1840 request = (MainThreadRequest) msg.obj;
1841 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1842 Phone phone = getPhoneFromRequest(request);
1843 if (phone != null) {
1844 phone.getSystemSelectionChannels(onCompleted);
1845 } else {
1846 loge("getSystemSelectionChannels: No phone object");
1847 request.result = new ArrayList<RadioAccessSpecifier>();
1848 notifyRequester(request);
1849 }
1850 break;
1851 }
1852 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1853 ar = (AsyncResult) msg.obj;
1854 request = (MainThreadRequest) ar.userObj;
1855 if (ar.exception == null && ar.result != null) {
1856 request.result = ar.result;
1857 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001858 request.result = new IllegalStateException(
1859 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001860 if (ar.result == null) {
1861 loge("getSystemSelectionChannels: Empty response");
1862 } else {
1863 loge("getSystemSelectionChannels: Unknown exception");
1864 }
1865 }
1866 notifyRequester(request);
1867 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001868 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1869 ar = (AsyncResult) msg.obj;
1870 request = (MainThreadRequest) ar.userObj;
1871 if (ar.exception == null && ar.result != null) {
1872 request.result = ar.result;
1873 } else {
1874 request.result = -1;
1875 loge("Failed to set Forbidden Plmns");
1876 if (ar.result == null) {
1877 loge("setForbidenPlmns: Empty response");
1878 } else if (ar.exception != null) {
1879 loge("setForbiddenPlmns: Exception: " + ar.exception);
1880 request.result = -1;
1881 } else {
1882 loge("setForbiddenPlmns: Unknown exception");
1883 }
1884 }
1885 notifyRequester(request);
1886 break;
1887 case CMD_SET_FORBIDDEN_PLMNS:
1888 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001889 uiccPort = getUiccPortFromRequest(request);
1890 if (uiccPort == null) {
1891 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001892 request.result = -1;
1893 notifyRequester(request);
1894 break;
1895 }
1896 Pair<Integer, List<String>> setFplmnsArgs =
1897 (Pair<Integer, List<String>>) request.argument;
1898 appType = setFplmnsArgs.first;
1899 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001900 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001901 if (uiccApp == null) {
1902 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1903 request.result = -1;
1904 loge("Failed to get UICC App");
1905 notifyRequester(request);
1906 } else {
1907 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1908 ((SIMRecords) uiccApp.getIccRecords())
1909 .setForbiddenPlmns(onCompleted, fplmns);
1910 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001911 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001912 case CMD_ERASE_MODEM_CONFIG:
1913 request = (MainThreadRequest) msg.obj;
1914 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1915 defaultPhone.eraseModemConfig(onCompleted);
1916 break;
1917 case EVENT_ERASE_MODEM_CONFIG_DONE:
1918 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001919 break;
zoey chene02881a2019-12-30 16:11:23 +08001920
Kai Shif70f46f2021-03-03 13:59:46 -08001921 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1922 request = (MainThreadRequest) msg.obj;
1923 request.result = defaultPhone.eraseDataInSharedPreferences();
1924 notifyRequester(request);
1925 break;
1926
zoey chene02881a2019-12-30 16:11:23 +08001927 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1928 request = (MainThreadRequest) msg.obj;
1929 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1930 Pair<String, String> changed = (Pair<String, String>) request.argument;
1931 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1932 changed.first, changed.second, onCompleted);
1933 break;
1934 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1935 ar = (AsyncResult) msg.obj;
1936 request = (MainThreadRequest) ar.userObj;
1937 if (ar.exception == null) {
1938 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001939 // If the operation is successful, update the PIN storage
1940 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1941 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001942 UiccController.getInstance().getPinStorage()
1943 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001944 } else {
1945 request.result = msg.arg1;
1946 }
1947 notifyRequester(request);
1948 break;
1949
Michele Berionne5e411512020-11-13 02:36:59 +00001950 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001951 request = (MainThreadRequest) msg.obj;
1952 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1953 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1954 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1955 enabled.first, enabled.second, onCompleted);
1956 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001957 }
zoey chene02881a2019-12-30 16:11:23 +08001958 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1959 ar = (AsyncResult) msg.obj;
1960 request = (MainThreadRequest) ar.userObj;
1961 if (ar.exception == null) {
1962 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001963 // If the operation is successful, update the PIN storage
1964 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1965 int phoneId = getPhoneFromRequest(request).getPhoneId();
1966 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001967 UiccController.getInstance().getPinStorage()
1968 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001969 } else {
1970 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1971 }
zoey chene02881a2019-12-30 16:11:23 +08001972 } else {
1973 request.result = msg.arg1;
1974 }
Michele Berionne5e411512020-11-13 02:36:59 +00001975
1976
zoey chene02881a2019-12-30 16:11:23 +08001977 notifyRequester(request);
1978 break;
1979
Peter Wangdafb9ac2020-01-15 14:13:38 -08001980 case MSG_NOTIFY_USER_ACTIVITY:
1981 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001982 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001983 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1984 getDefaultPhone().getContext().sendBroadcastAsUser(
1985 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1986 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001987
1988 case CMD_SET_DATA_THROTTLING: {
1989 request = (MainThreadRequest) msg.obj;
1990 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1991 DataThrottlingRequest dataThrottlingRequest =
1992 (DataThrottlingRequest) request.argument;
1993 Phone phone = getPhoneFromRequest(request);
1994 if (phone != null) {
1995 phone.setDataThrottling(onCompleted,
1996 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1997 dataThrottlingRequest.getCompletionDurationMillis());
1998 } else {
1999 loge("setDataThrottling: No phone object");
2000 request.result =
2001 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2002 notifyRequester(request);
2003 }
2004
2005 break;
2006 }
2007 case EVENT_SET_DATA_THROTTLING_DONE:
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010
2011 if (ar.exception == null) {
2012 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2013 } else if (ar.exception instanceof CommandException) {
2014 loge("setDataThrottling: CommandException: " + ar.exception);
2015 CommandException.Error error =
2016 ((CommandException) (ar.exception)).getCommandError();
2017
2018 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2019 request.result = TelephonyManager
2020 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2021 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2022 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002023 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2024 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002025 } else {
2026 request.result =
2027 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2028 }
2029 } else {
2030 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2031 }
2032 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2033 notifyRequester(request);
2034 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002035
2036 case CMD_SET_SIM_POWER: {
2037 request = (MainThreadRequest) msg.obj;
2038 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2039 request = (MainThreadRequest) msg.obj;
2040 int stateToSet =
2041 ((Pair<Integer, IIntegerConsumer>)
2042 request.argument).first;
2043 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2044 break;
2045 }
2046 case EVENT_SET_SIM_POWER_DONE: {
2047 ar = (AsyncResult) msg.obj;
2048 request = (MainThreadRequest) ar.userObj;
2049 IIntegerConsumer callback =
2050 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2051 if (ar.exception != null) {
2052 loge("setSimPower exception: " + ar.exception);
2053 int errorCode = TelephonyManager.CallForwardingInfoCallback
2054 .RESULT_ERROR_UNKNOWN;
2055 if (ar.exception instanceof CommandException) {
2056 CommandException.Error error =
2057 ((CommandException) (ar.exception)).getCommandError();
2058 if (error == CommandException.Error.SIM_ERR) {
2059 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2060 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2061 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2062 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2063 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2064 } else {
2065 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2066 }
2067 }
2068 try {
2069 callback.accept(errorCode);
2070 } catch (RemoteException e) {
2071 // Ignore if the remote process is no longer available to call back.
2072 Log.w(LOG_TAG, "setSimPower: callback not available.");
2073 }
2074 } else {
2075 try {
2076 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2077 } catch (RemoteException e) {
2078 // Ignore if the remote process is no longer available to call back.
2079 Log.w(LOG_TAG, "setSimPower: callback not available.");
2080 }
2081 }
2082 break;
2083 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002084 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2085 request = (MainThreadRequest) msg.obj;
2086
2087 final Phone phone = getPhoneFromRequest(request);
2088 if (phone == null || phone.getServiceStateTracker() == null) {
2089 request.result = new IllegalStateException("Phone or SST is null");
2090 notifyRequester(request);
2091 break;
2092 }
2093
2094 Pair<Integer, SignalStrengthUpdateRequest> pair =
2095 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2096 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2097 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002098 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002099 request.subId, pair.first /*callingUid*/,
2100 pair.second /*request*/, onCompleted);
2101 break;
2102 }
2103 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2104 ar = (AsyncResult) msg.obj;
2105 request = (MainThreadRequest) ar.userObj;
2106 // request.result will be the exception of ar if present, true otherwise.
2107 // Be cautious not to leave result null which will wait() forever
2108 request.result = ar.exception != null ? ar.exception : true;
2109 notifyRequester(request);
2110 break;
2111 }
2112 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2113 request = (MainThreadRequest) msg.obj;
2114
2115 Phone phone = getPhoneFromRequest(request);
2116 if (phone == null || phone.getServiceStateTracker() == null) {
2117 request.result = new IllegalStateException("Phone or SST is null");
2118 notifyRequester(request);
2119 break;
2120 }
2121
2122 Pair<Integer, SignalStrengthUpdateRequest> pair =
2123 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2124 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2125 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002126 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002127 request.subId, pair.first /*callingUid*/,
2128 pair.second /*request*/, onCompleted);
2129 break;
2130 }
2131 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2132 ar = (AsyncResult) msg.obj;
2133 request = (MainThreadRequest) ar.userObj;
2134 request.result = ar.exception != null ? ar.exception : true;
2135 notifyRequester(request);
2136 break;
2137 }
Jordan Liu109698e2020-11-24 14:50:34 -08002138
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002139 case CMD_GET_SLICING_CONFIG: {
2140 request = (MainThreadRequest) msg.obj;
2141 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2142 request.phone.getSlicingConfig(onCompleted);
2143 break;
2144 }
2145 case EVENT_GET_SLICING_CONFIG_DONE: {
2146 ar = (AsyncResult) msg.obj;
2147 request = (MainThreadRequest) ar.userObj;
2148 ResultReceiver result = (ResultReceiver) request.argument;
2149
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002150 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002151 Bundle bundle = new Bundle();
2152 int resultCode = 0;
2153 if (ar.exception != null) {
2154 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2155 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002156 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002157 } else if (ar.result == null) {
2158 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002159 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002160 } else {
2161 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002162 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2163 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002164 }
2165
2166 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002167 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002168 }
2169 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2170 result.send(resultCode, bundle);
2171 notifyRequester(request);
2172 break;
2173 }
2174
Sarah Chin71b3a852022-09-28 15:54:19 -07002175 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002176 request = (MainThreadRequest) msg.obj;
2177 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002178 PurchasePremiumCapabilityArgument arg =
2179 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002180 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002181 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002182 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002183 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002184
Sarah Chin71b3a852022-09-28 15:54:19 -07002185 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002186 ar = (AsyncResult) msg.obj;
2187 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002188 PurchasePremiumCapabilityArgument arg =
2189 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002190 try {
2191 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002192 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002193 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002194 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002195 + ", result= "
2196 + TelephonyManager.convertPurchaseResultToString(result));
2197 } catch (RemoteException e) {
2198 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002199 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002200 + " failed: " + e;
2201 if (DBG) log(logStr);
2202 AnomalyReporter.reportAnomaly(
2203 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2204 }
2205 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002206 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002207
Michele Berionne5e411512020-11-13 02:36:59 +00002208 case CMD_PREPARE_UNATTENDED_REBOOT:
2209 request = (MainThreadRequest) msg.obj;
2210 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002211 UiccController.getInstance().getPinStorage()
2212 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002213 notifyRequester(request);
2214 break;
2215
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 default:
2217 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2218 break;
2219 }
2220 }
Jake Hambye994d462014-02-03 13:10:13 -08002221
Pengquan Menga1bb6272018-09-06 09:59:22 -07002222 private void notifyRequester(MainThreadRequest request) {
2223 synchronized (request) {
2224 request.notifyAll();
2225 }
2226 }
2227
Jake Hambye994d462014-02-03 13:10:13 -08002228 private void handleNullReturnEvent(Message msg, String command) {
2229 AsyncResult ar = (AsyncResult) msg.obj;
2230 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2231 if (ar.exception == null) {
2232 request.result = true;
2233 } else {
2234 request.result = false;
2235 if (ar.exception instanceof CommandException) {
2236 loge(command + ": CommandException: " + ar.exception);
2237 } else {
2238 loge(command + ": Unknown exception");
2239 }
2240 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002241 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 }
2244
2245 /**
2246 * Posts the specified command to be executed on the main thread,
2247 * waits for the request to complete, and returns the result.
2248 * @see #sendRequestAsync
2249 */
2250 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002251 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2252 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002253 }
2254
2255 /**
2256 * Posts the specified command to be executed on the main thread,
2257 * waits for the request to complete, and returns the result.
2258 * @see #sendRequestAsync
2259 */
2260 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2261 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002262 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002263 }
2264
2265 /**
2266 * Posts the specified command to be executed on the main thread,
2267 * waits for the request to complete, and returns the result.
2268 * @see #sendRequestAsync
2269 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002270 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002271 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2272 }
2273
2274 /**
2275 * Posts the specified command to be executed on the main thread,
2276 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2277 * if not timeout or null otherwise.
2278 * @see #sendRequestAsync
2279 */
2280 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2281 long timeoutInMs) {
2282 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002283 }
2284
2285 /**
2286 * Posts the specified command to be executed on the main thread,
2287 * waits for the request to complete, and returns the result.
2288 * @see #sendRequestAsync
2289 */
Nathan Harold92bed182018-10-12 18:16:49 -07002290 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002291 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002292 }
2293
2294 /**
2295 * Posts the specified command to be executed on the main thread,
2296 * waits for the request to complete, and returns the result.
2297 * @see #sendRequestAsync
2298 */
2299 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002300 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2301 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002302 }
2303
2304 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002305 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2306 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2307 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002308 * @see #sendRequestAsync
2309 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002310 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2311 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2313 throw new RuntimeException("This method will deadlock if called from the main thread.");
2314 }
2315
Nathan Harold92bed182018-10-12 18:16:49 -07002316 MainThreadRequest request = null;
2317 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2318 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2319 } else if (phone != null) {
2320 request = new MainThreadRequest(argument, phone, workSource);
2321 } else {
2322 request = new MainThreadRequest(argument, subId, workSource);
2323 }
2324
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 Message msg = mMainThreadHandler.obtainMessage(command, request);
2326 msg.sendToTarget();
2327
Rambo Wang0f050d82021-02-12 11:43:36 -08002328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002330 if (timeoutInMs >= 0) {
2331 // Wait for at least timeoutInMs before returning null request result
2332 long now = SystemClock.elapsedRealtime();
2333 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002334 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002335 try {
2336 request.wait(deadline - now);
2337 } catch (InterruptedException e) {
2338 // Do nothing, go back and check if request is completed or timeout
2339 } finally {
2340 now = SystemClock.elapsedRealtime();
2341 }
2342 }
2343 } else {
2344 // Wait for the request to complete
2345 while (request.result == null) {
2346 try {
2347 request.wait();
2348 } catch (InterruptedException e) {
2349 // Do nothing, go back and wait until the request is complete
2350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352 }
2353 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002354 if (request.result == null) {
2355 Log.wtf(LOG_TAG,
2356 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 return request.result;
2359 }
2360
2361 /**
2362 * Asynchronous ("fire and forget") version of sendRequest():
2363 * Posts the specified command to be executed on the main thread, and
2364 * returns immediately.
2365 * @see #sendRequest
2366 */
2367 private void sendRequestAsync(int command) {
2368 mMainThreadHandler.sendEmptyMessage(command);
2369 }
2370
2371 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002372 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002373 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002374 */
2375 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002376 sendRequestAsync(command, argument, null, null);
2377 }
2378
2379 /**
2380 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2381 * @see {@link #sendRequest(int,Object)}
2382 */
2383 private void sendRequestAsync(
2384 int command, Object argument, Phone phone, WorkSource workSource) {
2385 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002386 Message msg = mMainThreadHandler.obtainMessage(command, request);
2387 msg.sendToTarget();
2388 }
2389
2390 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 * Initialize the singleton PhoneInterfaceManager instance.
2392 * This is only done once, at startup, from PhoneApp.onCreate().
2393 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002394 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 synchronized (PhoneInterfaceManager.class) {
2396 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002397 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 } else {
2399 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2400 }
2401 return sInstance;
2402 }
2403 }
2404
2405 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002406 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002409 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002410 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002412 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 mMainThreadHandler = new MainThreadHandler();
Aishwarya Mallampati32336e82023-01-04 23:02:56 +00002414 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002415 mTelephonySharedPreferences =
2416 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002417 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002418 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002419 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002420 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002421 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002422 mTelephony2gUpdater = new Telephony2gUpdater(
2423 Executors.newSingleThreadExecutor(), mApp);
2424 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 publish();
2426 }
2427
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002428 @VisibleForTesting
2429 public SharedPreferences getSharedPreferences() {
2430 return mTelephonySharedPreferences;
2431 }
2432
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002433 /**
2434 * Get the default phone for this device.
2435 */
2436 @VisibleForTesting
2437 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002438 Phone thePhone = getPhone(getDefaultSubscription());
2439 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2440 }
2441
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 private void publish() {
2443 if (DBG) log("publish: " + this);
2444
Peter Wangc035ce42020-01-08 21:00:22 -08002445 TelephonyFrameworkInitializer
2446 .getTelephonyServiceManager()
2447 .getTelephonyServiceRegisterer()
2448 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
2450
Stuart Scott584921c2015-01-15 17:10:34 -08002451 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002452 if (request.phone != null) {
2453 return request.phone;
2454 } else {
2455 return getPhoneFromSubId(request.subId);
2456 }
2457 }
2458
2459 private Phone getPhoneFromSubId(int subId) {
2460 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2461 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002462 }
2463
Rambo Wange53e07d2022-05-10 13:01:13 -07002464 @Nullable
2465 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002466 Phone phone = getPhoneFromRequest(request);
2467 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002468 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002469 }
2470
Wink Saville36469e72014-06-11 15:17:00 -07002471 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002472 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002473 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475
Kai Shif70f46f2021-03-03 13:59:46 -08002476 private void sendEraseModemConfig(@NonNull Phone phone) {
2477 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2478 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2479 }
2480
2481 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2482 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2483 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002484 }
2485
Peter Wang44b186e2020-01-13 23:33:09 -08002486 private boolean isImsAvailableOnDevice() {
2487 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2488 if (pm == null) {
2489 // For some reason package manger is not available.. This will fail internally anyway,
2490 // so do not throw error and allow.
2491 return true;
2492 }
2493 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2494 }
2495
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002497 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002498 }
2499
Wink Savilleb564aae2014-10-23 10:18:09 -07002500 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 if (DBG) log("dial: " + number);
2502 // No permission check needed here: This is just a wrapper around the
2503 // ACTION_DIAL intent, which is available to any app since it puts up
2504 // the UI before it does anything.
2505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 String url = createTelUrl(number);
2509 if (url == null) {
2510 return;
2511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 // PENDING: should we just silently fail if phone is offhook or ringing?
2514 PhoneConstants.State state = mCM.getState(subId);
2515 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2516 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2517 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2518 mApp.startActivity(intent);
2519 }
2520 } finally {
2521 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523 }
2524
2525 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002526 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002527 }
2528
Wink Savilleb564aae2014-10-23 10:18:09 -07002529 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 if (DBG) log("call: " + number);
2531
2532 // This is just a wrapper around the ACTION_CALL intent, but we still
2533 // need to do a permission check since we're calling startActivity()
2534 // from the context of the phone app.
2535 enforceCallPermission();
2536
Jordan Liu1617b712019-07-10 15:06:26 -07002537 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 != AppOpsManager.MODE_ALLOWED) {
2539 return;
2540 }
2541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 String url = createTelUrl(number);
2545 if (url == null) {
2546 return;
2547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 boolean isValid = false;
2550 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2551 if (slist != null) {
2552 for (SubscriptionInfo subInfoRecord : slist) {
2553 if (subInfoRecord.getSubscriptionId() == subId) {
2554 isValid = true;
2555 break;
2556 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002557 }
Wink Saville08874612014-08-31 19:19:58 -07002558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 if (!isValid) {
2560 return;
2561 }
Wink Saville08874612014-08-31 19:19:58 -07002562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2564 intent.putExtra(SUBSCRIPTION_KEY, subId);
2565 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2566 mApp.startActivity(intent);
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
2571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002573 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002574 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2575 }
2576
Wink Savilleb564aae2014-10-23 10:18:09 -07002577 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002578 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002579 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2580 }
2581
Wink Savilleb564aae2014-10-23 10:18:09 -07002582 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584
2585 final long identity = Binder.clearCallingIdentity();
2586 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002587 Phone phone = getPhone(subId);
2588 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002589 checkSimPin.start();
2590 return checkSimPin.unlockSim(null, pin);
2591 } finally {
2592 Binder.restoreCallingIdentity(identity);
2593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 }
2595
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598
2599 final long identity = Binder.clearCallingIdentity();
2600 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002601 Phone phone = getPhone(subId);
2602 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 checkSimPuk.start();
2604 return checkSimPuk.unlockSim(puk, pin);
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
2607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
2610 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002611 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 * a synchronous one.
2613 */
2614 private static class UnlockSim extends Thread {
2615
2616 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002617 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618
2619 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002620 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2621 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622
2623 // For replies from SimCard interface
2624 private Handler mHandler;
2625
2626 // For async handler to identify request type
2627 private static final int SUPPLY_PIN_COMPLETE = 100;
2628
Michele Berionne5e411512020-11-13 02:36:59 +00002629 UnlockSim(int phoneId, IccCard simCard) {
2630 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631 mSimCard = simCard;
2632 }
2633
2634 @Override
2635 public void run() {
2636 Looper.prepare();
2637 synchronized (UnlockSim.this) {
2638 mHandler = new Handler() {
2639 @Override
2640 public void handleMessage(Message msg) {
2641 AsyncResult ar = (AsyncResult) msg.obj;
2642 switch (msg.what) {
2643 case SUPPLY_PIN_COMPLETE:
2644 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2645 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002646 mRetryCount = msg.arg1;
2647 if (ar.exception != null) {
2648 if (ar.exception instanceof CommandException &&
2649 ((CommandException)(ar.exception)).getCommandError()
2650 == CommandException.Error.PASSWORD_INCORRECT) {
2651 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002652 } //When UiccCardApp dispose,handle message and return exception
2653 else if (ar.exception instanceof CommandException &&
2654 ((CommandException) (ar.exception)).getCommandError()
2655 == CommandException.Error.ABORTED) {
2656 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002657 } else {
2658 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2659 }
2660 } else {
2661 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2662 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 mDone = true;
2664 UnlockSim.this.notifyAll();
2665 }
2666 break;
2667 }
2668 }
2669 };
2670 UnlockSim.this.notifyAll();
2671 }
2672 Looper.loop();
2673 }
2674
2675 /*
2676 * Use PIN or PUK to unlock SIM card
2677 *
2678 * If PUK is null, unlock SIM card with PIN
2679 *
2680 * If PUK is not null, unlock SIM card with PUK and set PIN code
2681 */
Wink Saville9de0f752013-10-22 19:04:03 -07002682 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683
2684 while (mHandler == null) {
2685 try {
2686 wait();
2687 } catch (InterruptedException e) {
2688 Thread.currentThread().interrupt();
2689 }
2690 }
2691 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2692
2693 if (puk == null) {
2694 mSimCard.supplyPin(pin, callback);
2695 } else {
2696 mSimCard.supplyPuk(puk, pin, callback);
2697 }
2698
2699 while (!mDone) {
2700 try {
2701 Log.d(LOG_TAG, "wait for done");
2702 wait();
2703 } catch (InterruptedException e) {
2704 // Restore the interrupted status
2705 Thread.currentThread().interrupt();
2706 }
2707 }
2708 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002709 int[] resultArray = new int[2];
2710 resultArray[0] = mResult;
2711 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002712
2713 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002714 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002715 }
2716
Wink Saville9de0f752013-10-22 19:04:03 -07002717 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719 }
2720
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002721 /**
2722 * This method has been removed due to privacy and stability concerns.
2723 */
2724 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002726 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2727 return;
Wink Saville36469e72014-06-11 15:17:00 -07002728 }
2729
Nathan Harold1f889d82020-06-04 17:05:26 -07002730 @Override
2731 public void updateServiceLocationWithPackageName(String callingPackage) {
2732 mApp.getSystemService(AppOpsManager.class)
2733 .checkPackage(Binder.getCallingUid(), callingPackage);
2734
Nathan Haroldf096d982020-11-18 17:18:06 -08002735 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002736 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2737 // Callers targeting S have no business invoking this method.
2738 return;
2739 }
2740
2741 LocationAccessPolicy.LocationPermissionResult locationResult =
2742 LocationAccessPolicy.checkLocationPermission(mApp,
2743 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2744 .setCallingPackage(callingPackage)
2745 .setCallingFeatureId(null)
2746 .setCallingPid(Binder.getCallingPid())
2747 .setCallingUid(Binder.getCallingUid())
2748 .setMethod("updateServiceLocation")
2749 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2750 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2751 .build());
2752 // Apps that lack location permission have no business calling this method;
2753 // however, because no permission was declared in the public API, denials must
2754 // all be "soft".
2755 switch (locationResult) {
2756 case DENIED_HARD: /* fall through */
2757 case DENIED_SOFT:
2758 return;
2759 }
2760
2761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762 final long identity = Binder.clearCallingIdentity();
2763 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002764 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002766 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002773 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002774 @Override
2775 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002776 return isRadioOnWithFeature(callingPackage, null);
2777 }
2778
2779
2780 @Override
2781 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2782 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2783 callingFeatureId);
2784 }
2785
2786 @Deprecated
2787 @Override
2788 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2789 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002792 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002793 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2794 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002796 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002797 return false;
2798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 return isRadioOnForSubscriber(subId);
2803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002806 }
2807
2808 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 final Phone phone = getPhone(subId);
2812 if (phone != null) {
2813 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2814 } else {
2815 return false;
2816 }
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821
2822 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002823 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
Wink Saville36469e72014-06-11 15:17:00 -07002825
Wink Savilleb564aae2014-10-23 10:18:09 -07002826 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828
2829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 final Phone phone = getPhone(subId);
2832 if (phone != null) {
2833 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 }
Wink Saville36469e72014-06-11 15:17:00 -07002838 }
2839
2840 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002841 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002842 }
2843
Wink Savilleb564aae2014-10-23 10:18:09 -07002844 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
2847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 final Phone phone = getPhone(subId);
2850 if (phone == null) {
2851 return false;
2852 }
2853 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2854 toggleRadioOnOffForSubscriber(subId);
2855 }
2856 return true;
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
Wink Saville36469e72014-06-11 15:17:00 -07002861
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002862 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002863 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002864 /*
2865 * If any of the Radios are available, it will need to be
2866 * shutdown. So return true if any Radio is available.
2867 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2871 Phone phone = PhoneFactory.getPhone(i);
2872 if (phone != null && phone.isRadioAvailable()) return true;
2873 }
2874 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2875 return false;
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002878 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002879 }
2880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002882 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 enforceModifyPermission();
2884
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2888 logv("Shutting down Phone " + i);
2889 shutdownRadioUsingPhoneId(i);
2890 }
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002893 }
2894 }
2895
2896 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002897 Phone phone = PhoneFactory.getPhone(phoneId);
2898 if (phone != null && phone.isRadioAvailable()) {
2899 phone.shutdownRadio();
2900 }
2901 }
2902
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002903 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905
2906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2909 if (defaultPhone != null) {
2910 defaultPhone.setRadioPower(turnOn);
2911 return true;
2912 } else {
2913 loge("There's no default phone.");
2914 return false;
2915 }
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002918 }
Wink Saville36469e72014-06-11 15:17:00 -07002919 }
2920
Wink Savilleb564aae2014-10-23 10:18:09 -07002921 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923
2924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 final Phone phone = getPhone(subId);
2927 if (phone != null) {
2928 phone.setRadioPower(turnOn);
2929 return true;
2930 } else {
2931 return false;
2932 }
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002936 }
2937
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002938 /**
2939 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2940 * no reason to power it off. When any of the voters want to power it off, it will be turned
2941 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2942 * powering it off, and these radio off votes will be cleared.
2943 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2944 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2945 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2946 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2947 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2948 * check its vote.
2949 *
2950 * @param subId The subscription ID.
2951 * @param reason The reason for powering off radio.
2952 * @return true on success and false on failure.
2953 */
2954 public boolean requestRadioPowerOffForReason(int subId,
2955 @TelephonyManager.RadioPowerReason int reason) {
2956 enforceModifyPermission();
2957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 final Phone phone = getPhone(subId);
2961 if (phone != null) {
2962 phone.setRadioPowerForReason(false, reason);
2963 return true;
2964 } else {
2965 return false;
2966 }
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 /**
2973 * Remove the vote on powering off the radio for a reason, as requested by
2974 * {@link requestRadioPowerOffForReason}.
2975 *
2976 * @param subId The subscription ID.
2977 * @param reason The reason for powering off radio.
2978 * @return true on success and false on failure.
2979 */
2980 public boolean clearRadioPowerOffForReason(int subId,
2981 @TelephonyManager.RadioPowerReason int reason) {
2982 enforceModifyPermission();
2983
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 final Phone phone = getPhone(subId);
2987 if (phone != null) {
2988 phone.setRadioPowerForReason(true, reason);
2989 return true;
2990 } else {
2991 return false;
2992 }
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 /**
2999 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3000 *
3001 * @param subId The subscription ID.
3002 * @param callingPackage The package making the call.
3003 * @param callingFeatureId The feature in the package.
3004 * @return List of reasons for powering off radio.
3005 */
3006 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3007 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3008
3009 final long identity = Binder.clearCallingIdentity();
3010 List result = new ArrayList();
3011 try {
3012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3013 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3014 return result;
3015 }
3016
3017 final Phone phone = getPhone(subId);
3018 if (phone != null) {
3019 result.addAll(phone.getRadioPowerOffReasons());
3020 }
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
3024 return result;
3025 }
3026
Wink Saville36469e72014-06-11 15:17:00 -07003027 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003028 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003029 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
Jack Yu285100e2022-12-02 22:48:35 -08003034 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 final Phone phone = getPhone(subId);
3036 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003037 phone.getDataSettingsManager().setDataEnabled(
3038 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 return true;
3040 } else {
3041 return false;
3042 }
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 }
3047
Wink Saville36469e72014-06-11 15:17:00 -07003048 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003049 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003050 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
Jack Yu285100e2022-12-02 22:48:35 -08003055 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 final Phone phone = getPhone(subId);
3057 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003058 phone.getDataSettingsManager().setDataEnabled(
3059 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060 return true;
3061 } else {
3062 return false;
3063 }
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 }
3068
Sanket Padawe356d7632015-06-22 14:03:32 -07003069 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003070 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 final Phone phone = getPhone(subId);
3074 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003075 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 } else {
3077 return false;
3078 }
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
3083
3084 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003085 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003086 }
3087
pkanwarae03a6b2016-11-06 20:37:09 -08003088 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 enforceCallPermission();
3090
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3094 return;
3095 }
3096 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3097 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
pkanwar32d516d2016-10-14 19:37:38 -07003101 };
3102
Wink Savilleb564aae2014-10-23 10:18:09 -07003103 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3109 return false;
3110 }
3111 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 }
3116
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003117 /**
3118 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3119 * tag on getCallState Binder call.
3120 */
3121 @Deprecated
3122 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003124 if (CompatChanges.isChangeEnabled(
3125 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3126 Binder.getCallingUid())) {
3127 // Do not allow this API to be called on API version 31+, it should only be
3128 // called on old apps using this Binder call directly.
3129 throw new SecurityException("This method can only be used for applications "
3130 + "targeting API version 30 or less.");
3131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003134 Phone phone = getPhone(getDefaultSubscription());
3135 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3136 PhoneConstantConversions.convertCallState(phone.getState());
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
3140 }
3141
3142 @Override
3143 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3144 if (CompatChanges.isChangeEnabled(
3145 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3146 Binder.getCallingUid())) {
3147 // Check READ_PHONE_STATE for API version 31+
3148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3149 featureId, "getCallStateForSubscription")) {
3150 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3151 + "targeting API level 31+.");
3152 }
3153 }
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3158 PhoneConstantConversions.convertCallState(phone.getState());
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
3161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 }
3163
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003165 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003166 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003167 }
3168
3169 @Override
3170 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003173 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003175 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 } else {
3177 return PhoneConstantConversions.convertDataState(
3178 PhoneConstants.DataState.DISCONNECTED);
3179 }
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 }
3184
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003186 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003187 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003188 }
3189
3190 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003191 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 final long identity = Binder.clearCallingIdentity();
3193 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003194 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003196 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 } else {
3198 return TelephonyManager.DATA_ACTIVITY_NONE;
3199 }
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
3205 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003206 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003208 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003209
3210 LocationAccessPolicy.LocationPermissionResult locationResult =
3211 LocationAccessPolicy.checkLocationPermission(mApp,
3212 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3213 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003214 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003215 .setCallingPid(Binder.getCallingPid())
3216 .setCallingUid(Binder.getCallingUid())
3217 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003218 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003219 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3220 .build());
3221 switch (locationResult) {
3222 case DENIED_HARD:
3223 throw new SecurityException("Not allowed to access cell location");
3224 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003225 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3226 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003227 }
3228
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003229 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003233 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003234 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
Svetoslav64fad262015-04-14 14:35:21 -07003238 }
3239
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003241 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003242 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3243 // registered cell info, so return a NULL country instead.
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003246 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3247 // Get default phone in this case.
3248 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3249 }
Jack Yu285100e2022-12-02 22:48:35 -08003250 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003252 if (phone == null) return "";
3253 ServiceStateTracker sst = phone.getServiceStateTracker();
3254 if (sst == null) return "";
3255 LocaleTracker lt = sst.getLocaleTracker();
3256 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003257 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003261 }
3262
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003263 /**
3264 * This method was removed due to potential issues caused by performing partial
3265 * updates of service state, and lack of a credible use case.
3266 *
3267 * This has the ability to break the telephony implementation by disabling notification of
3268 * changes in device connectivity. DO NOT USE THIS!
3269 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003270 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 public void enableLocationUpdates() {
3272 mApp.enforceCallingOrSelfPermission(
3273 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 }
3275
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003276 /**
3277 * This method was removed due to potential issues caused by performing partial
3278 * updates of service state, and lack of a credible use case.
3279 *
3280 * This has the ability to break the telephony implementation by disabling notification of
3281 * changes in device connectivity. DO NOT USE THIS!
3282 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 @Override
3284 public void disableLocationUpdates() {
3285 mApp.enforceCallingOrSelfPermission(
3286 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287 }
3288
3289 @Override
3290 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003291 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3292 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003293 try {
3294 mApp.getSystemService(AppOpsManager.class)
3295 .checkPackage(Binder.getCallingUid(), callingPackage);
3296 } catch (SecurityException e) {
3297 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3298 throw e;
3299 }
3300
Nathan Haroldf096d982020-11-18 17:18:06 -08003301 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003302 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3303 throw new SecurityException(
3304 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3305 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003306
Jordan Liu1617b712019-07-10 15:06:26 -07003307 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3309 return null;
3310 }
Svetoslav64fad262015-04-14 14:35:21 -07003311
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003312 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003314 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003315 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316
Nathan Haroldf180aac2018-06-01 18:43:55 -07003317 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3318 for (CellInfo ci : info) {
3319 if (ci instanceof CellInfoGsm) {
3320 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3321 } else if (ci instanceof CellInfoWcdma) {
3322 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003325 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003326 }
3327
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003328 private List<CellInfo> getCachedCellInfo() {
3329 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3330 for (Phone phone : PhoneFactory.getPhones()) {
3331 List<CellInfo> info = phone.getAllCellInfo();
3332 if (info != null) cellInfos.addAll(info);
3333 }
3334 return cellInfos;
3335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336
3337 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003338 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003339 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003340 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003341
3342 LocationAccessPolicy.LocationPermissionResult locationResult =
3343 LocationAccessPolicy.checkLocationPermission(mApp,
3344 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3345 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003346 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003347 .setCallingPid(Binder.getCallingPid())
3348 .setCallingUid(Binder.getCallingUid())
3349 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003350 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003351 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3352 .build());
3353 switch (locationResult) {
3354 case DENIED_HARD:
3355 throw new SecurityException("Not allowed to access cell info");
3356 case DENIED_SOFT:
3357 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003358 }
3359
Nathan Haroldf096d982020-11-18 17:18:06 -08003360 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003361 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3362 return getCachedCellInfo();
3363 }
3364
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003365 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003366 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3370 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003371 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003372 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373 if (info != null) cellInfos.addAll(info);
3374 }
3375 return cellInfos;
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003378 }
3379 }
3380
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003381 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003382 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3383 String callingFeatureId) {
3384 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3385 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003386 }
3387
3388 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003389 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3390 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003391 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003392 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003393 }
3394
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003395 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3396 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003397 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003398 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003399
3400 LocationAccessPolicy.LocationPermissionResult locationResult =
3401 LocationAccessPolicy.checkLocationPermission(mApp,
3402 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3403 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003404 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003405 .setCallingPid(Binder.getCallingPid())
3406 .setCallingUid(Binder.getCallingUid())
3407 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003408 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3409 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003410 .build());
3411 switch (locationResult) {
3412 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003413 if (TelephonyPermissions
3414 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003415 // Safetynet logging for b/154934934
3416 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3417 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003418 throw new SecurityException("Not allowed to access cell info");
3419 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003420 if (TelephonyPermissions
3421 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003422 // Safetynet logging for b/154934934
3423 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3424 }
Nathan Harold5320c422019-05-09 10:26:08 -07003425 try {
3426 cb.onCellInfo(new ArrayList<CellInfo>());
3427 } catch (RemoteException re) {
3428 // Drop without consequences
3429 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003430 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003431 }
3432
Nathan Harolda939a962019-05-09 10:13:47 -07003433
3434 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003435 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3436
3437 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3438 }
3439
3440 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003441 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003442 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003447 Phone phone = getPhone(subId);
3448 if (phone == null) {
3449 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3450 } else {
3451 phone.setCellInfoListRate(rateInMillis, workSource);
3452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003456 }
3457
Shishir Agrawala9f32182016-04-12 12:00:16 -07003458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003459 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003460 Phone phone = PhoneFactory.getPhone(slotIndex);
3461 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003462 return null;
3463 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003464 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003465 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003466 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003467 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003468 return null;
3469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003470
3471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 return phone.getImei();
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
3476 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003477 }
3478
3479 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003480 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3481 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3482 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3483 callingFeatureId, "getPrimaryImei")) {
3484 throw new SecurityException("Caller does not have permission");
3485 }
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 for (Phone phone : PhoneFactory.getPhones()) {
3489 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3490 return phone.getImei();
3491 }
3492 }
3493 throw new UnsupportedOperationException("Operation not supported");
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
3496 }
3497 }
3498
3499 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003500 public String getTypeAllocationCodeForSlot(int slotIndex) {
3501 Phone phone = PhoneFactory.getPhone(slotIndex);
3502 String tac = null;
3503 if (phone != null) {
3504 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003505 try {
3506 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3507 } catch (IndexOutOfBoundsException e) {
3508 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3509 return null;
3510 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003511 }
3512 return tac;
3513 }
3514
3515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003516 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003517 try {
3518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3519 } catch (SecurityException se) {
3520 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3521 throw new SecurityException("Package " + callingPackage + " does not belong to "
3522 + Binder.getCallingUid());
3523 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003524 Phone phone = PhoneFactory.getPhone(slotIndex);
3525 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003526 return null;
3527 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003528
Jeff Davidson913390f2018-02-23 17:11:49 -08003529 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003530 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003531 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003532 return null;
3533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 return phone.getMeid();
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
Jack Yu2af8d712017-03-15 17:14:14 -07003541 }
3542
3543 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003544 public String getManufacturerCodeForSlot(int slotIndex) {
3545 Phone phone = PhoneFactory.getPhone(slotIndex);
3546 String manufacturerCode = null;
3547 if (phone != null) {
3548 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003549 try {
3550 manufacturerCode =
3551 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3552 } catch (IndexOutOfBoundsException e) {
3553 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3554 return null;
3555 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003556 }
3557 return manufacturerCode;
3558 }
3559
3560 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3562 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003563 Phone phone = PhoneFactory.getPhone(slotIndex);
3564 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003565 return null;
3566 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003567 int subId = phone.getSubId();
3568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003569 mApp, subId, callingPackage, callingFeatureId,
3570 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003571 return null;
3572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 return phone.getDeviceSvn();
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003580 }
3581
fionaxu43304da2017-11-27 22:51:16 -08003582 @Override
3583 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 final Phone phone = getPhone(subId);
3587 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
fionaxu43304da2017-11-27 22:51:16 -08003591 }
3592
3593 @Override
3594 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 final Phone phone = getPhone(subId);
3598 return phone == null ? null : phone.getCarrierName();
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
fionaxu43304da2017-11-27 22:51:16 -08003602 }
3603
calvinpanffe225e2018-11-01 19:43:06 +08003604 @Override
chen xu0026ca62019-03-06 15:28:50 -08003605 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 final Phone phone = getPhone(subId);
3609 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003610 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
3614 }
3615
3616 @Override
chen xu0026ca62019-03-06 15:28:50 -08003617 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003621 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003622 } finally {
3623 Binder.restoreCallingIdentity(identity);
3624 }
3625 }
3626
chen xu651eec72018-11-11 19:03:44 -08003627 @Override
chen xu864e11c2018-12-06 22:10:03 -08003628 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3629 if (!isSubscriptionMccMnc) {
3630 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3631 }
chen xu651eec72018-11-11 19:03:44 -08003632 final Phone phone = PhoneFactory.getPhone(slotIndex);
3633 if (phone == null) {
3634 return TelephonyManager.UNKNOWN_CARRIER_ID;
3635 }
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3639 } finally {
3640 Binder.restoreCallingIdentity(identity);
3641 }
3642 }
3643
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 //
3645 // Internal helper methods.
3646 //
3647
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003648 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003649 * Make sure the caller is the calling package itself
3650 *
3651 * @throws SecurityException if the caller is not the calling package
3652 */
3653 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3654 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003655 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3656 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003657 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003658 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003659 } catch (PackageManager.NameNotFoundException e) {
3660 // packageUid is -1
3661 }
3662 if (packageUid != callingUid) {
3663 throw new SecurityException(message + ": Package " + callingPackage
3664 + " does not belong to " + callingUid);
3665 }
3666 }
3667
3668 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003669 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3670 *
3671 * @throws SecurityException if the caller does not have the required permission
3672 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003673 @VisibleForTesting
3674 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003675 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3676 }
3677
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003678 /**
3679 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3680 *
3681 * @throws SecurityException if the caller does not have the required permission
3682 */
3683 @VisibleForTesting
3684 public void enforceReadPermission() {
3685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
3686 }
3687
Shuo Qian3b6ee772019-11-13 17:43:31 -08003688 private void enforceActiveEmergencySessionPermission() {
3689 mApp.enforceCallingOrSelfPermission(
3690 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3691 }
3692
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003693 /**
3694 * Make sure the caller has the CALL_PHONE permission.
3695 *
3696 * @throws SecurityException if the caller does not have the required permission
3697 */
3698 private void enforceCallPermission() {
3699 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3700 }
3701
paulhu5a773602019-08-23 19:17:33 +08003702 private void enforceSettingsPermission() {
3703 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003704 }
3705
Michele Berionne5e411512020-11-13 02:36:59 +00003706 private void enforceRebootPermission() {
3707 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3708 }
3709
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003710 private String createTelUrl(String number) {
3711 if (TextUtils.isEmpty(number)) {
3712 return null;
3713 }
3714
Jake Hambye994d462014-02-03 13:10:13 -08003715 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003716 }
3717
Ihab Awadf9e92732013-12-05 18:02:52 -08003718 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003719 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3720 }
3721
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003722 private static void logv(String msg) {
3723 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3724 }
3725
Ihab Awadf9e92732013-12-05 18:02:52 -08003726 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003727 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3728 }
3729
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003730 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003731 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003732 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003733 }
3734
Sanket Padawe356d7632015-06-22 14:03:32 -07003735 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003736 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 final Phone phone = PhoneFactory.getPhone(slotIndex);
3740 if (phone == null) {
3741 return PhoneConstants.PHONE_TYPE_NONE;
3742 } else {
3743 return phone.getPhoneType();
3744 }
3745 } finally {
3746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003748 }
3749
3750 /**
3751 * Returns the CDMA ERI icon index to display
3752 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003754 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3755 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3756 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003757 }
3758
Sanket Padawe356d7632015-06-22 14:03:32 -07003759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3761 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 mApp, subId, callingPackage, callingFeatureId,
3764 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003765 return -1;
3766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767
3768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 final Phone phone = getPhone(subId);
3771 if (phone != null) {
3772 return phone.getCdmaEriIconIndex();
3773 } else {
3774 return -1;
3775 }
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003779 }
3780
3781 /**
3782 * Returns the CDMA ERI icon mode,
3783 * 0 - ON
3784 * 1 - FLASHING
3785 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003786 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003787 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3788 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3789 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003790 }
3791
Sanket Padawe356d7632015-06-22 14:03:32 -07003792 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003793 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3794 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003796 mApp, subId, callingPackage, callingFeatureId,
3797 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003798 return -1;
3799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800
3801 final long identity = Binder.clearCallingIdentity();
3802 try {
3803 final Phone phone = getPhone(subId);
3804 if (phone != null) {
3805 return phone.getCdmaEriIconMode();
3806 } else {
3807 return -1;
3808 }
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 }
3813
3814 /**
3815 * Returns the CDMA ERI text,
3816 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003817 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003818 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3819 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3820 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003821 }
3822
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003824 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3825 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003827 mApp, subId, callingPackage, callingFeatureId,
3828 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003829 return null;
3830 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 final Phone phone = getPhone(subId);
3835 if (phone != null) {
3836 return phone.getCdmaEriText();
3837 } else {
3838 return null;
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003843 }
3844
3845 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003846 * Returns the CDMA MDN.
3847 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003848 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003849 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3851 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852
3853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003856 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 return phone.getLine1Number();
3858 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003859 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 return null;
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003864 }
3865 }
3866
3867 /**
3868 * Returns the CDMA MIN.
3869 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003871 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3873 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874
3875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 final Phone phone = getPhone(subId);
3878 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3879 return phone.getCdmaMin();
3880 } else {
3881 return null;
3882 }
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003885 }
3886 }
3887
Hall Liud892bec2018-11-30 14:51:45 -08003888 @Override
3889 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3890 INumberVerificationCallback callback, String callingPackage) {
3891 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3892 != PERMISSION_GRANTED) {
3893 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3894 }
3895 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3896
3897 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3898 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003899 throw new SecurityException("Calling package must be configured in the device config: "
3900 + "calling package: " + callingPackage
3901 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003902 }
3903
3904 if (range == null) {
3905 throw new NullPointerException("Range must be non-null");
3906 }
3907
3908 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003909 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003910
3911 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3912 }
3913
Junda Liuca05d5d2014-08-14 22:36:34 -07003914 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003915 * Returns true if CDMA provisioning needs to run.
3916 */
3917 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918 final long identity = Binder.clearCallingIdentity();
3919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003920 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003924 }
3925
3926 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003927 * Sets the voice mail number of a given subId.
3928 */
3929 @Override
3930 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3932 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3937 new Pair<String, String>(alphaTag, number), new Integer(subId));
3938 return success;
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003942 }
3943
Ta-wei Yen87c49842016-05-13 21:19:52 -07003944 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003945 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003947 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3948 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003949 if (!TextUtils.equals(callingPackage, systemDialer)) {
3950 throw new SecurityException("caller must be system dialer");
3951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3956 if (phoneAccountHandle == null) {
3957 return null;
3958 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003959 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 } finally {
3961 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003962 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003963 }
3964
3965 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003966 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3967 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003968 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003970 mApp, subId, callingPackage, callingFeatureId,
3971 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003972 return null;
3973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003975 final long identity = Binder.clearCallingIdentity();
3976 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003981 }
3982
3983 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003984 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3985 VisualVoicemailSmsFilterSettings settings) {
3986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003995 }
3996
3997 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003998 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000
4001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004008 }
4009
4010 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004011 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4012 String callingPackage, int subId) {
4013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014
4015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004022 }
4023
4024 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004025 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004031 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032 } finally {
4033 Binder.restoreCallingIdentity(identity);
4034 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004035 }
4036
4037 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004038 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4039 String callingAttributionTag, int subId, String number, int port, String text,
4040 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004042 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004043 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004044 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004045 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4046 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004047 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004048
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004049 /**
fionaxu0152e512016-11-14 13:36:14 -08004050 * Sets the voice activation state of a given subId.
4051 */
4052 @Override
4053 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4055 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056
4057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 final Phone phone = getPhone(subId);
4060 if (phone != null) {
4061 phone.setVoiceActivationState(activationState);
4062 } else {
4063 loge("setVoiceActivationState fails with invalid subId: " + subId);
4064 }
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004067 }
4068 }
4069
4070 /**
4071 * Sets the data activation state of a given subId.
4072 */
4073 @Override
4074 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4076 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077
4078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 final Phone phone = getPhone(subId);
4081 if (phone != null) {
4082 phone.setDataActivationState(activationState);
4083 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004084 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 }
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004088 }
4089 }
4090
4091 /**
4092 * Returns the voice activation state of a given subId.
4093 */
4094 @Override
4095 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097
fionaxu0152e512016-11-14 13:36:14 -08004098 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 if (phone != null) {
4102 return phone.getVoiceActivationState();
4103 } else {
4104 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4105 }
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004108 }
4109 }
4110
4111 /**
4112 * Returns the data activation state of a given subId.
4113 */
4114 @Override
4115 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117
fionaxu0152e512016-11-14 13:36:14 -08004118 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 if (phone != null) {
4122 return phone.getDataActivationState();
4123 } else {
4124 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4125 }
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004128 }
4129 }
4130
4131 /**
Wink Saville36469e72014-06-11 15:17:00 -07004132 * Returns the unread count of voicemails for a subId
4133 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004135 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4136 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004138 mApp, subId, callingPackage, callingFeatureId,
4139 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004140 return 0;
4141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 final Phone phone = getPhone(subId);
4145 if (phone != null) {
4146 return phone.getVoiceMessageCount();
4147 } else {
4148 return 0;
4149 }
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004153 }
4154
4155 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004156 * returns true, if the device is in a state where both voice and data
4157 * are supported simultaneously. This can change based on location or network condition.
4158 */
4159 @Override
4160 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 final Phone phone = getPhone(subId);
4164 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004168 }
4169
4170 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004171 * Send the dialer code if called from the current default dialer or the caller has
4172 * carrier privilege.
4173 * @param inputCode The dialer code to send
4174 */
4175 @Override
4176 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004177 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004179 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4180 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004181 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004182 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004183 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185
4186 final long identity = Binder.clearCallingIdentity();
4187 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004188 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
fionaxu235cc5e2017-03-06 22:25:57 -08004192 }
4193
Pengquan Menga1bb6272018-09-06 09:59:22 -07004194 @Override
4195 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004196 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004197 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004198 mApp, subId, "getNetworkSelectionMode");
4199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 if (!isActiveSubscription(subId)) {
4202 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4203 }
4204 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4205 } finally {
4206 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004208 }
4209
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004211 public boolean isInEmergencySmsMode() {
4212 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 for (Phone phone : PhoneFactory.getPhones()) {
4216 if (phone.isInEmergencySmsMode()) {
4217 return true;
4218 }
4219 }
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
4223 return false;
4224 }
4225
shilu366312e2019-12-17 09:28:10 -08004226 /**
4227 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4228 * @param subId The subscription to use to check the configuration.
4229 * @param c The callback that will be used to send the result.
4230 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004231 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004232 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4233 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004234 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004235 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004236
4237 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4238 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4239 "IMS not available on device.");
4240 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 final long token = Binder.clearCallingIdentity();
4242 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004243 int slotId = getSlotIndexOrException(subId);
4244 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004245
4246 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4247 if (controller != null) {
4248 ImsManager imsManager = controller.getImsManager(subId);
4249 if (imsManager != null) {
4250 imsManager.addRegistrationCallbackForSubscription(c, subId);
4251 } else {
4252 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4253 }
4254 } else {
4255 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4256 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004257 } catch (ImsException e) {
4258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 } finally {
4260 Binder.restoreCallingIdentity(token);
4261 }
4262 }
4263
shilu366312e2019-12-17 09:28:10 -08004264 /**
4265 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4266 * @param subId The subscription to use to check the configuration.
4267 * @param c The callback that will be used to send the result.
4268 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004270 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004271 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004272 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004273 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4274 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4275 }
Meng Wangafbc5852019-09-19 17:37:13 -07004276 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004277
Meng Wangafbc5852019-09-19 17:37:13 -07004278 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004279 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4280 if (controller != null) {
4281 ImsManager imsManager = controller.getImsManager(subId);
4282 if (imsManager != null) {
4283 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4284 } else {
4285 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4286 + "is inactive, ignoring unregister.");
4287 // If the ImsManager is not valid, just return, since the callback
4288 // will already have been removed internally.
4289 }
4290 }
Meng Wangafbc5852019-09-19 17:37:13 -07004291 } finally {
4292 Binder.restoreCallingIdentity(token);
4293 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 }
4295
Brad Ebingera34a6c22019-10-22 17:36:18 -07004296 /**
4297 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4298 */
4299 @Override
4300 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4301 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4302 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4304 "IMS not available on device.");
4305 }
4306 final long token = Binder.clearCallingIdentity();
4307 try {
4308 Phone phone = getPhone(subId);
4309 if (phone == null) {
4310 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4311 + subId + "'");
4312 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4313 }
4314 phone.getImsRegistrationState(regState -> {
4315 try {
4316 consumer.accept((regState == null)
4317 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4318 } catch (RemoteException e) {
4319 // Ignore if the remote process is no longer available to call back.
4320 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4321 }
4322 });
4323 } finally {
4324 Binder.restoreCallingIdentity(token);
4325 }
4326 }
4327
4328 /**
4329 * Get the transport type for the IMS service registration state.
4330 */
4331 @Override
4332 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004333 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004334 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004335 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4336 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4337 "IMS not available on device.");
4338 }
4339 final long token = Binder.clearCallingIdentity();
4340 try {
4341 Phone phone = getPhone(subId);
4342 if (phone == null) {
4343 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4344 + subId + "'");
4345 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4346 }
4347 phone.getImsRegistrationTech(regTech -> {
4348 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4349 int regTechConverted = (regTech == null)
4350 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4351 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4352 regTechConverted);
4353 try {
4354 consumer.accept(regTechConverted);
4355 } catch (RemoteException e) {
4356 // Ignore if the remote process is no longer available to call back.
4357 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4358 }
4359 });
4360 } finally {
4361 Binder.restoreCallingIdentity(token);
4362 }
4363 }
4364
shilu366312e2019-12-17 09:28:10 -08004365 /**
4366 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4367 * @param subId The subscription to use to check the configuration.
4368 * @param c The callback that will be used to send the result.
4369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004371 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4372 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004374 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004375 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4376 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4377 "IMS not available on device.");
4378 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long token = Binder.clearCallingIdentity();
4380 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004381 int slotId = getSlotIndexOrException(subId);
4382 verifyImsMmTelConfiguredOrThrow(slotId);
4383 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
4389 }
4390
shilu366312e2019-12-17 09:28:10 -08004391 /**
4392 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4393 * @param subId The subscription to use to check the configuration.
4394 * @param c The callback that will be used to send the result.
4395 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004397 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004398 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004399 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004400 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4401 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4402 }
Meng Wangafbc5852019-09-19 17:37:13 -07004403
4404 final long token = Binder.clearCallingIdentity();
4405 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004406 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004407 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004408 } catch (ImsException e) {
4409 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4410 + "is inactive, ignoring unregister.");
4411 // If the subscription is no longer active, just return, since the callback
4412 // will already have been removed internally.
4413 } finally {
4414 Binder.restoreCallingIdentity(token);
4415 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 }
4417
4418 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004419 public boolean isCapable(int subId, int capability, int regTech) {
4420 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 final long token = Binder.clearCallingIdentity();
4422 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004423 int slotId = getSlotIndexOrException(subId);
4424 verifyImsMmTelConfiguredOrThrow(slotId);
4425 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4426 } catch (com.android.ims.ImsException e) {
4427 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4428 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004429 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004430 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4431 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 } finally {
4433 Binder.restoreCallingIdentity(token);
4434 }
4435 }
4436
4437 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004438 public boolean isAvailable(int subId, int capability, int regTech) {
4439 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 final long token = Binder.clearCallingIdentity();
4441 try {
4442 Phone phone = getPhone(subId);
4443 if (phone == null) return false;
4444 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004445 } catch (com.android.ims.ImsException e) {
4446 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4447 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(token);
4450 }
4451 }
4452
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004453 /**
4454 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4455 * subscription.
4456 * @param subId The subscription to use to check the configuration.
4457 * @param callback The callback that will be used to send the result.
4458 * @param capability The MmTelFeature capability that will be used to send the result.
4459 * @param transportType The transport type of the MmTelFeature capability.
4460 */
4461 @Override
4462 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4463 int transportType) {
4464 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004465 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4466 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4467 "IMS not available on device.");
4468 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004469 final long token = Binder.clearCallingIdentity();
4470 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004471 int slotId = getSlotIndex(subId);
4472 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4473 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4474 + subId + "'");
4475 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4476 }
4477 verifyImsMmTelConfiguredOrThrow(slotId);
4478 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4479 transportType, aBoolean -> {
4480 try {
4481 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4482 } catch (RemoteException e) {
4483 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4484 + "running. Ignore");
4485 }
4486 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 } catch (ImsException e) {
4488 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004489 } finally {
4490 Binder.restoreCallingIdentity(token);
4491 }
4492 }
4493
shilu366312e2019-12-17 09:28:10 -08004494 /**
4495 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4496 * @param subId The subscription to use to check the configuration.
4497 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 @Override
4499 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004501 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004502
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 final long token = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004506 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004508 } catch (ImsException e) {
4509 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 } finally {
4511 Binder.restoreCallingIdentity(token);
4512 }
4513 }
4514
4515 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004516 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004518 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004519 final long identity = Binder.clearCallingIdentity();
4520 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004522 // This setting doesn't require an active ImsService connection, so do not verify. The
4523 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004525 } catch (ImsException e) {
4526 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
4530 }
4531
shilu366312e2019-12-17 09:28:10 -08004532 /**
4533 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4534 * @param subId The subscription to use to check the configuration.
4535 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004537 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004538 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004539 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 final long identity = Binder.clearCallingIdentity();
4541 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004542 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004543 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
4546 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
4550 }
4551
4552 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004553 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004555 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004556 final long identity = Binder.clearCallingIdentity();
4557 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004559 // This setting doesn't require an active ImsService connection, so do not verify. The
4560 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004561 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004562 } catch (ImsException e) {
4563 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
4567 }
4568
shilu366312e2019-12-17 09:28:10 -08004569 /**
4570 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4571 * @param subId The subscription to use to check the configuration.
4572 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004573 @Override
4574 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004575 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004576 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 final long identity = Binder.clearCallingIdentity();
4578 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004580 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004581 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004582 } catch (ImsException e) {
4583 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
4587 }
4588
4589 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004590 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004592 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004593 final long identity = Binder.clearCallingIdentity();
4594 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004595 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004596 // This setting doesn't require an active ImsService connection, so do not verify. The
4597 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004598 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004599 } catch (ImsException e) {
4600 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
4604 }
4605
shilu366312e2019-12-17 09:28:10 -08004606 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004607 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4608 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4609 * @param subId The subscription to use to check the configuration.
4610 */
4611 @Override
4612 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004613 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004614 mApp, subId, "isCrossSimCallingEnabledByUser");
4615 final long identity = Binder.clearCallingIdentity();
4616 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004618 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004619 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004620 } catch (ImsException e) {
4621 throw new ServiceSpecificException(e.getCode());
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
4625 }
4626
4627 /**
4628 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4629 * Requires MODIFY_PHONE_STATE permission.
4630 * @param subId The subscription to use to check the configuration.
4631 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4632 * false otherwise
4633 */
4634 @Override
4635 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4637 "setCrossSimCallingEnabled");
4638 final long identity = Binder.clearCallingIdentity();
4639 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004640 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004641 // This setting doesn't require an active ImsService connection, so do not verify. The
4642 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004643 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004644 } catch (ImsException e) {
4645 throw new ServiceSpecificException(e.getCode());
4646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
4649 }
4650
4651 /**
shilu366312e2019-12-17 09:28:10 -08004652 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4653 * @param subId The subscription to use to check the configuration.
4654 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004655 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004656
Brad Ebinger35c841c2018-10-01 10:40:55 -07004657 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004658 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004659 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 final long identity = Binder.clearCallingIdentity();
4661 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004662 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004663 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004664 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 } catch (ImsException e) {
4666 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
4670 }
4671
4672 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004673 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004675 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004676 final long identity = Binder.clearCallingIdentity();
4677 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004678 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004679 // This setting doesn't require an active ImsService connection, so do not verify. The
4680 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004681 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004682 } catch (ImsException e) {
4683 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004684 } finally {
4685 Binder.restoreCallingIdentity(identity);
4686 }
4687 }
4688
4689 @Override
4690 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4692 "setVoWiFiNonPersistent");
4693 final long identity = Binder.clearCallingIdentity();
4694 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004695 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004696 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004697 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004698 } catch (ImsException e) {
4699 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004700 } finally {
4701 Binder.restoreCallingIdentity(identity);
4702 }
4703 }
4704
shilu366312e2019-12-17 09:28:10 -08004705 /**
4706 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4707 * @param subId The subscription to use to check the configuration.
4708 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004709 @Override
4710 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004711 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004712 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004713 final long identity = Binder.clearCallingIdentity();
4714 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004715 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004716 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004717 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004718 } catch (ImsException e) {
4719 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
4723 }
4724
4725 @Override
4726 public void setVoWiFiModeSetting(int subId, int mode) {
4727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4728 "setVoWiFiModeSetting");
4729 final long identity = Binder.clearCallingIdentity();
4730 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004731 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004732 // This setting doesn't require an active ImsService connection, so do not verify. The
4733 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004734 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004735 } catch (ImsException e) {
4736 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
4740 }
4741
4742 @Override
4743 public int getVoWiFiRoamingModeSetting(int subId) {
4744 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4745 final long identity = Binder.clearCallingIdentity();
4746 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004747 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004748 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004749 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004750 } catch (ImsException e) {
4751 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
4755 }
4756
4757 @Override
4758 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4760 "setVoWiFiRoamingModeSetting");
4761 final long identity = Binder.clearCallingIdentity();
4762 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004763 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004764 // This setting doesn't require an active ImsService connection, so do not verify. The
4765 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004766 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004767 } catch (ImsException e) {
4768 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
4772 }
4773
4774 @Override
4775 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4777 "setRttCapabilityEnabled");
4778 final long identity = Binder.clearCallingIdentity();
4779 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004780 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004781 // This setting doesn't require an active ImsService connection, so do not verify. The
4782 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004783 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004784 } catch (ImsException e) {
4785 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 } finally {
4787 Binder.restoreCallingIdentity(identity);
4788 }
4789 }
4790
shilu366312e2019-12-17 09:28:10 -08004791 /**
4792 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4793 * @param subId The subscription to use to check the configuration.
4794 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004795 @Override
4796 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004797 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004798 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004799 final long identity = Binder.clearCallingIdentity();
4800 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004801 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004802 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004803 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004804 } catch (ImsException e) {
4805 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
4809 }
4810
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004811 @Override
4812 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4813 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004814
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004815 final long identity = Binder.clearCallingIdentity();
4816 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004817 if (!isImsAvailableOnDevice()) {
4818 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4819 "IMS not available on device.");
4820 }
4821 int slotId = getSlotIndexOrException(subId);
4822 verifyImsMmTelConfiguredOrThrow(slotId);
4823 ImsManager.getInstance(mApp, slotId)
4824 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004825 } catch (ImsException e) {
4826 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
4830 }
4831
4832 @Override
4833 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4834 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004835
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004836 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4838 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4839 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004840 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004841 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004842 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004843 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004844 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4845 + "is inactive, ignoring unregister.");
4846 // If the subscription is no longer active, just return, since the callback will already
4847 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
joonhunshincffb7fc2021-11-28 07:32:01 +00004853 @Override
4854 public void registerFeatureProvisioningChangedCallback(int subId,
4855 IFeatureProvisioningCallback callback) {
4856 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4857 mApp, subId, "registerFeatureProvisioningChangedCallback");
4858
4859 final long identity = Binder.clearCallingIdentity();
4860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4861 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4862 }
4863
joonhunshin91bc1952022-04-29 08:47:15 +00004864 try {
4865 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4866 if (controller == null) {
4867 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4868 "Device does not support IMS");
4869 }
4870 controller.addFeatureProvisioningChangedCallback(subId, callback);
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004874 }
4875
4876 @Override
4877 public void unregisterFeatureProvisioningChangedCallback(int subId,
4878 IFeatureProvisioningCallback callback) {
4879 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4880 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4881
4882 final long identity = Binder.clearCallingIdentity();
4883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4884 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4885 }
4886
joonhunshin91bc1952022-04-29 08:47:15 +00004887 try {
4888 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4889 if (controller == null) {
4890 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4891 return;
4892 }
4893 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004897 }
allenwtsu99c623b2020-01-03 18:24:23 +08004898
4899 private void checkModifyPhoneStatePermission(int subId, String message) {
4900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4901 message);
4902 }
4903
allenwtsu99c623b2020-01-03 18:24:23 +08004904 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004905 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004906 boolean isProvisioned) {
4907 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4908
4909 final long identity = Binder.clearCallingIdentity();
4910 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004911 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4912 if (controller == null) {
4913 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4914 return;
4915 }
4916 controller.setRcsProvisioningStatusForCapability(
4917 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
allenwtsu99c623b2020-01-03 18:24:23 +08004921 }
4922
4923
4924 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004925 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4926 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4927 mApp, subId, "getRcsProvisioningStatusForCapability");
4928
allenwtsu99c623b2020-01-03 18:24:23 +08004929 final long identity = Binder.clearCallingIdentity();
4930 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004931 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4932 if (controller == null) {
4933 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4934
4935 // device does not support IMS, this method will return true always.
4936 return true;
4937 }
4938 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
4942 }
4943
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4946 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004947 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004948
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 final long identity = Binder.clearCallingIdentity();
4950 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004951 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4952 if (controller == null) {
4953 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4954 return;
4955 }
4956 controller.setImsProvisioningStatusForCapability(
4957 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
4961 }
4962
4963 @Override
4964 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004965 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4966 mApp, subId, "getProvisioningStatusForCapability");
4967
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 final long identity = Binder.clearCallingIdentity();
4969 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004970 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4971 if (controller == null) {
4972 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973
joonhunshin91bc1952022-04-29 08:47:15 +00004974 // device does not support IMS, this method will return true always.
4975 return true;
4976 }
4977 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
4981 }
4982
4983 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004984 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4985 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4986 mApp, subId, "isProvisioningRequiredForCapability");
4987
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004990 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4991 if (controller == null) {
4992 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4993
4994 // device does not support IMS, this method will return false
4995 return false;
4996 }
4997 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004998 } finally {
4999 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005000 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005001 }
5002
5003 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005004 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5005 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5006 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005007
joonhunshincffb7fc2021-11-28 07:32:01 +00005008 final long identity = Binder.clearCallingIdentity();
5009 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005010 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5011 if (controller == null) {
5012 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5013
5014 // device does not support IMS, this method will return false
5015 return false;
5016 }
5017 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005021 }
5022
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005023 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005024 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5026 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5027 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005028 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5029 mApp, subId, "getImsProvisioningInt");
5030
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005031 final long identity = Binder.clearCallingIdentity();
5032 try {
5033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005034 int slotId = getSlotIndex(subId);
5035 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5036 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5037 + subId + "' for key:" + key);
5038 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5039 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005040
joonhunshin91bc1952022-04-29 08:47:15 +00005041 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5042 if (controller == null) {
5043 loge("getImsProvisioningInt: Device does not support IMS");
5044
5045 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5046 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5047 }
5048 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005049 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5050 return retVal;
5051 }
5052
calvinpanb5a34062021-02-08 19:59:36 +08005053 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005054 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005055 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5056 + subId + "' for key:" + key);
5057 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
5061 }
5062
5063 @Override
5064 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005065 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5066 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5067 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005068 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5069 mApp, subId, "getImsProvisioningString");
5070
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005074 int slotId = getSlotIndex(subId);
5075 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5076 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5077 + subId + "' for key:" + key);
5078 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5079 }
calvinpanb5a34062021-02-08 19:59:36 +08005080 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005081 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005082 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5083 + subId + "' for key:" + key);
5084 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
5088 }
5089
5090 @Override
5091 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005092 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5093 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5094 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5096 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005097
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005098 final long identity = Binder.clearCallingIdentity();
5099 try {
5100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005101 int slotId = getSlotIndex(subId);
5102 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5103 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5104 + subId + "' for key:" + key);
5105 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5106 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005107
joonhunshin91bc1952022-04-29 08:47:15 +00005108 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5109 if (controller == null) {
5110 loge("setImsProvisioningInt: Device does not support IMS");
5111
5112 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5113 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5114 }
5115 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005116 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5117 return retVal;
5118 }
5119
calvinpanb5a34062021-02-08 19:59:36 +08005120 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5121 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005122 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005123 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005124 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
5128 }
5129
5130 @Override
5131 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005132 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5133 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5134 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5136 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005137 final long identity = Binder.clearCallingIdentity();
5138 try {
5139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005140 int slotId = getSlotIndex(subId);
5141 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5142 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5143 + subId + "' for key:" + key);
5144 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5145 }
calvinpanb5a34062021-02-08 19:59:36 +08005146 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5147 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005148 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005149 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005150 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
5154 }
5155
Brad Ebinger919631e2021-06-02 17:46:35 -07005156 /**
5157 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5158 * for the given slot ID or no ImsResolver instance has been created.
5159 * @param slotId The slot ID that the IMS service is created for.
5160 * @throws ImsException If there is no ImsService configured for this slot.
5161 */
5162 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5163 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5164 ImsFeature.FEATURE_MMTEL)) {
5165 throw new ImsException("This subscription does not support MMTEL over IMS",
5166 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5167 }
5168 }
5169
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005170 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005171 int slotId = SubscriptionManager.getSlotIndex(subId);
5172 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005173 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5174 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 }
5176 return slotId;
5177 }
5178
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005179 private int getSlotIndex(int subId) {
5180 int slotId = SubscriptionManager.getSlotIndex(subId);
5181 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5182 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5183 }
5184 return slotId;
5185 }
5186
Wink Saville36469e72014-06-11 15:17:00 -07005187 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005188 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005189 */
5190 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005191 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5192 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005193 try {
5194 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5195 } catch (SecurityException se) {
5196 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5197 throw new SecurityException("Package " + callingPackage + " does not belong to "
5198 + Binder.getCallingUid());
5199 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005200 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005201 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005202 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005203 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005204 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005205 mApp, subId, callingPackage, callingFeatureId,
5206 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005207 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5208 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 final long identity = Binder.clearCallingIdentity();
5211 try {
5212 final Phone phone = getPhone(subId);
5213 if (phone != null) {
5214 return phone.getServiceState().getDataNetworkType();
5215 } else {
5216 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5217 }
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005221 }
5222
5223 /**
5224 * Returns the data network type
5225 */
5226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005227 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005228 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005229 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005230 }
5231
5232 /**
5233 * Returns the data network type for a subId
5234 */
5235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005236 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5237 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005238 String functionName = "getDataNetworkTypeForSubscriber";
5239 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5240 mApp, functionName)) {
5241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5242 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5244 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005245 }
5246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 final Phone phone = getPhone(subId);
5250 if (phone != null) {
5251 return phone.getServiceState().getDataNetworkType();
5252 } else {
5253 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5254 }
5255 } finally {
5256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005258 }
5259
5260 /**
Wink Saville36469e72014-06-11 15:17:00 -07005261 * Returns the Voice network type for a subId
5262 */
5263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005264 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5265 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005266 String functionName = "getVoiceNetworkTypeForSubscriber";
5267 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5268 mApp, functionName)) {
5269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5270 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5271 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5272 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005273 }
5274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 final Phone phone = getPhone(subId);
5278 if (phone != null) {
5279 return phone.getServiceState().getVoiceNetworkType();
5280 } else {
5281 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5282 }
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005286 }
5287
5288 /**
5289 * @return true if a ICC card is present
5290 */
5291 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005292 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005293 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005294 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005295 }
5296
5297 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005298 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005299 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005300 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005301 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 final Phone phone = PhoneFactory.getPhone(slotIndex);
5305 if (phone != null) {
5306 return phone.getIccCard().hasIccCard();
5307 } else {
5308 return false;
5309 }
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005313 }
5314
5315 /**
5316 * Return if the current radio is LTE on CDMA. This
5317 * is a tri-state return value as for a period of time
5318 * the mode may be unknown.
5319 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005320 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005321 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005322 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005323 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005325 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5326 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5327 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005328 }
5329
Sanket Padawe356d7632015-06-22 14:03:32 -07005330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005331 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5332 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005333 try {
5334 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5335 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005336 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5337 }
5338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 final Phone phone = getPhone(subId);
5342 if (phone == null) {
5343 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5344 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005345 return TelephonyProperties.lte_on_cdma_device()
5346 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 }
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005350 }
Wink Saville36469e72014-06-11 15:17:00 -07005351 }
5352
Wink Saville36469e72014-06-11 15:17:00 -07005353 /**
5354 * {@hide}
5355 * Returns Default subId, 0 in the case of single standby.
5356 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005357 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005358 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005359 }
5360
Shishir Agrawala9f32182016-04-12 12:00:16 -07005361 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005362 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005363 }
5364
Wink Savilleb564aae2014-10-23 10:18:09 -07005365 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005366 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005367 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005368
Pengquan Menge92a50d2018-09-21 15:54:48 -07005369 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005370 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5371 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5372 mApp.getOpPackageName(), mApp.getFeatureId());
5373 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005374 return mSubscriptionController.isActiveSubId(subId);
5375 }
5376
Ihab Awadf2177b72013-11-25 13:33:23 -08005377 /**
5378 * @see android.telephony.TelephonyManager.WifiCallingChoices
5379 */
5380 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005381 final long identity = Binder.clearCallingIdentity();
5382 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005383 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5385 getWhenToMakeWifiCallsDefaultPreference());
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005389 }
5390
5391 /**
5392 * @see android.telephony.TelephonyManager.WifiCallingChoices
5393 */
5394 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005398 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005403 }
5404
Sailesh Nepald1e68152013-12-12 19:08:02 -08005405 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005406 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005407 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005408 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005409
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005410 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5411 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5412 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005413 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005414 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5415 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005416 }
5417 return PhoneFactory.getPhone(phoneId);
5418 }
5419
Shishir Agrawal566b7612013-10-28 14:41:00 -07005420 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005421 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005422 @NonNull IccLogicalChannelRequest request) {
5423 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5424 /*message=*/ "iccOpenLogicalChannel");
5425
5426 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5427 // Verify that the callingPackage in the request belongs to the calling UID
5428 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5429
5430 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005432
Rambo Wanga1782702021-11-10 20:15:19 -08005433 private Phone getPhoneFromValidIccLogicalChannelRequest(
5434 @NonNull IccLogicalChannelRequest request, String message) {
5435 Phone phone;
5436 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5438 mApp, request.subId, message);
5439 phone = getPhoneFromSubId(request.subId);
5440 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5441 enforceModifyPermission();
5442 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5443 } else {
5444 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005445 }
Rambo Wanga1782702021-11-10 20:15:19 -08005446 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005447 }
5448
5449 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005450 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 final long identity = Binder.clearCallingIdentity();
5452 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005453 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005455 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5456 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005457 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5458 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 loge("The calling package is not allowed to access ISD-R.");
5460 throw new SecurityException(
5461 "The calling package is not allowed to access ISD-R.");
5462 }
Derek Tan740e1672017-06-27 14:56:27 -07005463 }
Derek Tan740e1672017-06-27 14:56:27 -07005464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005466 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5467 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 return response;
5469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005472 }
5473
5474 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005475 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5476 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5477 /*message=*/"iccCloseLogicalChannel");
5478
5479 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5480
5481 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005482 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005483
Rambo Wanga1782702021-11-10 20:15:19 -08005484 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5485 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005486 // before this feature is enabled, this API should only return false if
5487 // the operation fails instead of throwing runtime exception for
5488 // backward-compatibility.
5489 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5490 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 final long identity = Binder.clearCallingIdentity();
5492 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005493 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005494 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 }
Chen Xue9d737e2022-01-01 23:41:31 -08005496 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005497 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005498 Boolean success = false;
5499 if (result instanceof RuntimeException) {
5500 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005501 if (shouldThrowExceptionOnFailure) {
5502 throw (RuntimeException) result;
5503 } else {
5504 return false;
5505 }
Chen Xue9d737e2022-01-01 23:41:31 -08005506 } else if (result instanceof Boolean) {
5507 success = (Boolean) result;
5508 } else {
5509 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5510 }
Rambo Wanga1782702021-11-10 20:15:19 -08005511 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 return success;
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005515 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005516 }
5517
5518 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005519 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005520 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5522 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005523 if (DBG) {
5524 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5525 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5526 + p3 + " data=" + data);
5527 }
5528 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5529 command, p1, p2, p3, data);
5530 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005531
Jordan Liu4c733742019-02-28 12:03:40 -08005532 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005533 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5534 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005535 enforceModifyPermission();
5536 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005537 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5538 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5539 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005540 }
5541 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005542 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5543 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005544 }
5545
5546 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5547 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 final long identity = Binder.clearCallingIdentity();
5549 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005550 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 return "";
5552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005555 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5556 null /* workSource */);
5557 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 // Append the returned status code to the end of the response payload.
5560 String s = Integer.toHexString(
5561 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5562 if (response.payload != null) {
5563 s = IccUtils.bytesToHexString(response.payload) + s;
5564 }
5565 return s;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005569 }
Jake Hambye994d462014-02-03 13:10:13 -08005570
Evan Charltonc66da362014-05-16 14:06:40 -07005571 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005572 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5573 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5575 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005577 if (DBG) {
5578 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5579 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5580 }
5581 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5582 cla, command, p1, p2, p3, data);
5583 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005584
Jordan Liu4c733742019-02-28 12:03:40 -08005585 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005586 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5587 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005588 enforceModifyPermission();
5589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5590 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005591 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5592 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5593 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005594 }
5595
5596 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005597 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5598 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005599 }
5600
5601 // open APDU basic channel assuming the caller has sufficient permissions
5602 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5603 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5607 && TextUtils.equals(ISDR_AID, data)) {
5608 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005609 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5610 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 if (bestComponent == null
5612 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5613 loge("The calling package is not allowed to select ISD-R.");
5614 throw new SecurityException(
5615 "The calling package is not allowed to select ISD-R.");
5616 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005617 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005620 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5621 null /* workSource */);
5622 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 // Append the returned status code to the end of the response payload.
5625 String s = Integer.toHexString(
5626 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5627 if (response.payload != null) {
5628 s = IccUtils.bytesToHexString(response.payload) + s;
5629 }
5630 return s;
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005633 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005634 }
5635
5636 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005637 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005638 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5640 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 if (DBG) {
5645 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5646 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5647 }
5648
5649 IccIoResult response =
5650 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5651 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5652 subId);
5653
5654 if (DBG) {
5655 log("Exchange SIM_IO [R]" + response);
5656 }
5657
5658 byte[] result = null;
5659 int length = 2;
5660 if (response.payload != null) {
5661 length = 2 + response.payload.length;
5662 result = new byte[length];
5663 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5664 } else {
5665 result = new byte[length];
5666 }
5667
5668 result[length - 1] = (byte) response.sw2;
5669 result[length - 2] = (byte) response.sw1;
5670 return result;
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005673 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005674 }
5675
Nathan Haroldb3014052017-01-25 15:57:32 -08005676 /**
5677 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5678 * on a particular subscription
5679 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005680 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5681 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005683 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005684 return null;
5685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 if (appType != TelephonyManager.APPTYPE_USIM
5690 && appType != TelephonyManager.APPTYPE_SIM) {
5691 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5692 return null;
5693 }
5694 Object response = sendRequest(
5695 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5696 if (response instanceof String[]) {
5697 return (String[]) response;
5698 }
yincheng zhao2737e882019-09-06 17:06:54 -07005699 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005701 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005704 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005705 }
5706
yincheng zhao2737e882019-09-06 17:06:54 -07005707 /**
5708 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5709 * subscription.
5710 *
5711 * @param subId the id of the subscription.
5712 * @param appType the uicc app type, must be USIM or SIM.
5713 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5714 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005716 * @return number of fplmns that is successfully written to the SIM.
5717 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005718 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5719 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5721 mApp, subId, "setForbiddenPlmns");
5722
yincheng zhao2737e882019-09-06 17:06:54 -07005723 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5724 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5725 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5726 }
5727 if (fplmns == null) {
5728 throw new IllegalArgumentException("Fplmn List provided is null");
5729 }
5730 for (String fplmn : fplmns) {
5731 if (!CellIdentity.isValidPlmn(fplmn)) {
5732 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5733 }
5734 }
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 Object response = sendRequest(
5738 CMD_SET_FORBIDDEN_PLMNS,
5739 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5740 subId);
5741 return (int) response;
5742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
5745 }
5746
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005747 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005748 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5750 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5755 if (response.payload == null) {
5756 return "";
5757 }
Evan Charltonc66da362014-05-16 14:06:40 -07005758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 // Append the returned status code to the end of the response payload.
5760 String s = Integer.toHexString(
5761 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5762 s = IccUtils.bytesToHexString(response.payload) + s;
5763 return s;
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
5766 }
Evan Charltonc66da362014-05-16 14:06:40 -07005767 }
5768
Jake Hambye994d462014-02-03 13:10:13 -08005769 /**
5770 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5771 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5772 *
5773 * @param itemID the ID of the item to read
5774 * @return the NV item as a String, or null on error.
5775 */
5776 @Override
5777 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005778 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5780 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005785 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5787 return value;
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Jake Hambye994d462014-02-03 13:10:13 -08005791 }
5792
5793 /**
5794 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5795 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5796 *
5797 * @param itemID the ID of the item to read
5798 * @param itemValue the value to write, as a String
5799 * @return true on success; false on any failure
5800 */
5801 @Override
5802 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005803 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5805 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5810 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005811 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5813 return success;
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
Jake Hambye994d462014-02-03 13:10:13 -08005817 }
5818
5819 /**
5820 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5821 * Used for device configuration by some CDMA operators.
5822 *
5823 * @param preferredRoamingList byte array containing the new PRL
5824 * @return true on success; false on any failure
5825 */
5826 @Override
5827 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5829 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5834 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5835 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5836 return success;
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Jake Hambye994d462014-02-03 13:10:13 -08005840 }
5841
5842 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005843 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005844 * Used for device configuration by some CDMA operators.
5845 *
chen xu6dac5ab2018-10-26 17:39:23 -07005846 * @param slotIndex - device slot.
5847 *
Jake Hambye994d462014-02-03 13:10:13 -08005848 * @return true on success; false on any failure
5849 */
5850 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005851 public boolean resetModemConfig(int slotIndex) {
5852 Phone phone = PhoneFactory.getPhone(slotIndex);
5853 if (phone != null) {
5854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5855 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
chen xu6dac5ab2018-10-26 17:39:23 -07005857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5860 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5861 return success;
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 }
chen xu6dac5ab2018-10-26 17:39:23 -07005866 return false;
5867 }
5868
5869 /**
5870 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5871 *
5872 * @param slotIndex - device slot.
5873 *
5874 * @return true on success; false on any failure
5875 */
5876 @Override
5877 public boolean rebootModem(int slotIndex) {
5878 Phone phone = PhoneFactory.getPhone(slotIndex);
5879 if (phone != null) {
5880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5881 mApp, phone.getSubId(), "rebootModem");
5882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5886 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5887 return success;
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
5891 }
5892 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005893 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005894
Brad Ebinger51f743a2017-01-23 13:50:20 -08005895 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005896 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5897 * {@link #disableIms(int)}.
5898 * @param slotIndex device slot.
5899 */
5900 public void resetIms(int slotIndex) {
5901 enforceModifyPermission();
5902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 if (mImsResolver == null) {
5906 // may happen if the does not support IMS.
5907 return;
5908 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005909 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
5913 }
5914
5915 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005916 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5917 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005918 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005919 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005920 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921
5922 final long identity = Binder.clearCallingIdentity();
5923 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005925 // may happen if the device does not support IMS.
5926 return;
5927 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005928 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005932 }
5933
5934 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005935 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5936 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005937 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005938 public void disableIms(int slotId) {
5939 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940
5941 final long identity = Binder.clearCallingIdentity();
5942 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005943 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005944 // may happen if the device does not support IMS.
5945 return;
5946 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005947 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005951 }
5952
5953 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005954 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5955 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005956 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005957 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005958 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960
5961 final long identity = Binder.clearCallingIdentity();
5962 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005963 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005964 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5965 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005966 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005967 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005971 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005972 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005973 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5974 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005975 @Override
5976 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005977 enforceModifyPermission();
5978
5979 final long identity = Binder.clearCallingIdentity();
5980 try {
5981 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005982 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
5986 }
5987
5988 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005989 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005990 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005991 */
5992 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5993 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994
5995 final long identity = Binder.clearCallingIdentity();
5996 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005997 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005998 // may happen if the device does not support IMS.
5999 return null;
6000 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006001 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 } finally {
6003 Binder.restoreCallingIdentity(identity);
6004 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006005 }
6006
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006007 /**
6008 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006009 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006010 */
6011 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6012 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006016 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006017 // may happen if the device does not support IMS.
6018 return null;
6019 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006020 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006024 }
6025
Brad Ebinger884c07b2018-02-15 16:17:40 -08006026 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006027 * Sets the ImsService Package Name that Telephony will bind to.
6028 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006029 * @param slotIndex the slot ID that the ImsService should bind for.
6030 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006031 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006032 * @param featureTypes An integer array of feature types associated with a packageName.
6033 * @param packageName The name of the package that the current configuration will be replaced
6034 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006035 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006036 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006037 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6038 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006041 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 final long identity = Binder.clearCallingIdentity();
6044 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006045 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006046 // may happen if the device does not support IMS.
6047 return false;
6048 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006049 Map<Integer, String> featureConfig = new HashMap<>();
6050 for (int featureType : featureTypes) {
6051 featureConfig.put(featureType, packageName);
6052 }
6053 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6054 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006058 }
6059
6060 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006061 * Clears any carrier ImsService overrides for the slot index specified that were previously
6062 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6063 *
6064 * This should only be used for testing.
6065 *
6066 * @param slotIndex the slot ID that the ImsService should bind for.
6067 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6068 */
6069 @Override
6070 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6072 "clearCarrierImsServiceOverride");
6073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006074 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006075
6076 final long identity = Binder.clearCallingIdentity();
6077 try {
6078 if (mImsResolver == null) {
6079 // may happen if the device does not support IMS.
6080 return false;
6081 }
6082 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
6086 }
6087
6088 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006089 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006090 *
6091 * @param slotId The slot that the ImsService is associated with.
6092 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6093 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006094 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006095 * @return the package name of the ImsService configuration.
6096 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006097 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6098 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006099 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006100 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6101 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 final long identity = Binder.clearCallingIdentity();
6104 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006105 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006106 // may happen if the device does not support IMS.
6107 return "";
6108 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006109 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006110 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6111 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006115 }
6116
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006117 /**
6118 * Get the MmTelFeature state associated with the requested subscription id.
6119 * @param subId The subscription that the MmTelFeature is associated with.
6120 * @param callback A callback with an integer containing the
6121 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6122 */
6123 @Override
6124 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6125 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006126 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6127 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6128 "IMS not available on device.");
6129 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006130 final long token = Binder.clearCallingIdentity();
6131 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006132 int slotId = getSlotIndex(subId);
6133 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6134 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6135 + subId + "'");
6136 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6137 }
6138 verifyImsMmTelConfiguredOrThrow(slotId);
6139 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6140 try {
6141 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6142 } catch (RemoteException e) {
6143 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6144 + "Ignore");
6145 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006146 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006147 } catch (ImsException e) {
6148 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006149 } finally {
6150 Binder.restoreCallingIdentity(token);
6151 }
6152 }
6153
Daniel Brightbb5840b2021-01-12 15:48:18 -08006154 /**
6155 * Sets the ims registration state on all valid {@link Phone}s.
6156 */
6157 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006158 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159
6160 final long identity = Binder.clearCallingIdentity();
6161 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006162 // NOTE: Before S, this method only set the default phone.
6163 for (final Phone phone : PhoneFactory.getPhones()) {
6164 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6165 phone.setImsRegistrationState(registered);
6166 }
6167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
Wink Saville36469e72014-06-11 15:17:00 -07006171 }
6172
6173 /**
Stuart Scott54788802015-03-30 13:18:01 -07006174 * Set the network selection mode to automatic.
6175 *
6176 */
6177 @Override
6178 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6180 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
shilufc958392020-01-20 11:36:01 -08006184 if (!isActiveSubscription(subId)) {
6185 return;
6186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006188 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6189 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 } finally {
6191 Binder.restoreCallingIdentity(identity);
6192 }
Stuart Scott54788802015-03-30 13:18:01 -07006193 }
6194
Jack Yud10cdd42020-09-28 20:28:01 -07006195 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006196 * Ask the radio to connect to the input network and change selection mode to manual.
6197 *
6198 * @param subId the id of the subscription.
6199 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6200 * the operator to attach to.
6201 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6202 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6203 * normal network selection next time.
6204 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006205 */
6206 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006207 public boolean setNetworkSelectionModeManual(
6208 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6210 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006211
Jack Yu285100e2022-12-02 22:48:35 -08006212 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006213 if (!isActiveSubscription(subId)) {
6214 return false;
6215 }
6216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006218 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006220 if (DBG) {
6221 log("setNetworkSelectionModeManual: subId: " + subId
6222 + " operator: " + operatorInfo);
6223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6225 } finally {
6226 Binder.restoreCallingIdentity(identity);
6227 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006228 }
shilu84f6e8b2019-12-19 13:58:01 -08006229 /**
6230 * Get the manual network selection
6231 *
6232 * @param subId the id of the subscription.
6233 *
6234 * @return the previously saved user selected PLMN
6235 */
6236 @Override
6237 public String getManualNetworkSelectionPlmn(int subId) {
6238 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006239 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006240 mApp, subId, "getManualNetworkSelectionPlmn");
6241
6242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006245 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006246 }
6247
6248 final Phone phone = getPhone(subId);
6249 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006250 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006251 }
6252 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6253 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6254 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
6258 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006259
6260 /**
6261 * Scans for available networks.
6262 */
6263 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006264 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6265 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6267 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006268 LocationAccessPolicy.LocationPermissionResult locationResult =
6269 LocationAccessPolicy.checkLocationPermission(mApp,
6270 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6271 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006272 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006273 .setCallingPid(Binder.getCallingPid())
6274 .setCallingUid(Binder.getCallingUid())
6275 .setMethod("getCellNetworkScanResults")
6276 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006277 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6278 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006279 .build());
6280 switch (locationResult) {
6281 case DENIED_HARD:
6282 throw new SecurityException("Not allowed to access scan results -- location");
6283 case DENIED_SOFT:
6284 return null;
6285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286
Pengquan Menga1bb6272018-09-06 09:59:22 -07006287 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 try {
6289 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006290 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 } finally {
6293 Binder.restoreCallingIdentity(identity);
6294 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006295 }
6296
6297 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006298 * Get the call forwarding info, given the call forwarding reason.
6299 */
6300 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006301 public void getCallForwarding(int subId, int callForwardingReason,
6302 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006303 enforceReadPrivilegedPermission("getCallForwarding");
6304 long identity = Binder.clearCallingIdentity();
6305 try {
6306 if (DBG) {
6307 log("getCallForwarding: subId " + subId
6308 + " callForwardingReason" + callForwardingReason);
6309 }
Hall Liu27d24262020-09-18 19:04:59 -07006310
6311 Phone phone = getPhone(subId);
6312 if (phone == null) {
6313 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006314 callback.onError(
6315 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006316 } catch (RemoteException e) {
6317 // ignore
6318 }
6319 return;
6320 }
6321
6322 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6323 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6324 @Override
6325 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6326 try {
6327 callback.onCallForwardingInfoAvailable(info);
6328 } catch (RemoteException e) {
6329 // ignore
6330 }
6331 }
6332
6333 @Override
6334 public void onError(int error) {
6335 try {
6336 callback.onError(error);
6337 } catch (RemoteException e) {
6338 // ignore
6339 }
6340 }
6341 });
6342 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
6346 }
6347
6348 /**
6349 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6350 * reason, the number to forward, and the timeout before the forwarding is attempted.
6351 */
6352 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006353 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6354 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006355 enforceModifyPermission();
6356 long identity = Binder.clearCallingIdentity();
6357 try {
6358 if (DBG) {
6359 log("setCallForwarding: subId " + subId
6360 + " callForwardingInfo" + callForwardingInfo);
6361 }
Hall Liu27d24262020-09-18 19:04:59 -07006362
6363 Phone phone = getPhone(subId);
6364 if (phone == null) {
6365 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006366 callback.accept(
6367 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006368 } catch (RemoteException e) {
6369 // ignore
6370 }
6371 return;
6372 }
6373
6374 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6375 FunctionalUtils.ignoreRemoteException(callback::accept));
6376
6377 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 }
6382
6383 /**
Hall Liu27d24262020-09-18 19:04:59 -07006384 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006385 */
6386 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006387 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006388 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006389 long identity = Binder.clearCallingIdentity();
6390 try {
Hall Liu27d24262020-09-18 19:04:59 -07006391 Phone phone = getPhone(subId);
6392 if (phone == null) {
6393 try {
6394 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6395 } catch (RemoteException e) {
6396 // ignore
6397 }
6398 return;
6399 }
SongFerngWang0e767992021-03-31 22:08:45 +08006400 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6401 PersistableBundle c = configManager.getConfigForSubId(subId);
6402 boolean requireUssd = c.getBoolean(
6403 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006404
Shuo Qian4a594052020-01-23 11:59:30 -08006405 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006406 if (requireUssd) {
6407 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6408 getSubscriptionCarrierId(subId));
6409 String newUssdCommand = "";
6410 try {
6411 newUssdCommand = carrierXmlParser.getFeature(
6412 CarrierXmlParser.FEATURE_CALL_WAITING)
6413 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6414 } catch (NullPointerException e) {
6415 loge("Failed to generate USSD number" + e);
6416 }
6417 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6418 mMainThreadHandler, callback, carrierXmlParser,
6419 CarrierXmlParser.SsEntry.SSAction.QUERY);
6420 final String ussdCommand = newUssdCommand;
6421 Executors.newSingleThreadExecutor().execute(() -> {
6422 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6423 });
6424 } else {
6425 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6426 callback::accept);
6427 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6428 }
Shuo Qian4a594052020-01-23 11:59:30 -08006429 } finally {
6430 Binder.restoreCallingIdentity(identity);
6431 }
6432 }
6433
6434 /**
Hall Liu27d24262020-09-18 19:04:59 -07006435 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006436 */
6437 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006438 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006439 enforceModifyPermission();
6440 long identity = Binder.clearCallingIdentity();
6441 try {
Hall Liu27d24262020-09-18 19:04:59 -07006442 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6443
6444 Phone phone = getPhone(subId);
6445 if (phone == null) {
6446 try {
6447 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6448 } catch (RemoteException e) {
6449 // ignore
6450 }
6451 return;
6452 }
6453
SongFerngWang0e767992021-03-31 22:08:45 +08006454 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6455 PersistableBundle c = configManager.getConfigForSubId(subId);
6456 boolean requireUssd = c.getBoolean(
6457 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006458
SongFerngWang0e767992021-03-31 22:08:45 +08006459 if (DBG) log("getCallWaitingStatus: subId " + subId);
6460 if (requireUssd) {
6461 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6462 getSubscriptionCarrierId(subId));
6463 CarrierXmlParser.SsEntry.SSAction ssAction =
6464 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6465 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6466 String newUssdCommand = "";
6467 try {
6468 newUssdCommand = carrierXmlParser.getFeature(
6469 CarrierXmlParser.FEATURE_CALL_WAITING)
6470 .makeCommand(ssAction, null);
6471 } catch (NullPointerException e) {
6472 loge("Failed to generate USSD number" + e);
6473 }
6474 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6475 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6476 final String ussdCommand = newUssdCommand;
6477 Executors.newSingleThreadExecutor().execute(() -> {
6478 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6479 });
6480 } else {
6481 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6482 FunctionalUtils.ignoreRemoteException(callback::accept));
6483
6484 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6485 }
Shuo Qian4a594052020-01-23 11:59:30 -08006486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 /**
yinxub1bed742017-04-17 11:45:04 -07006492 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006493 *
yinxub1bed742017-04-17 11:45:04 -07006494 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006495 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6496 * location related information which will be sent if the caller already possess
6497 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006498 * @param request contains the radio access networks with bands/channels to scan
6499 * @param messenger callback messenger for scan results or errors
6500 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006501 * @return the id of the requested scan which can be used to stop the scan.
6502 */
6503 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006504 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6505 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006506 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6508 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006509 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006510 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6511 if (!renounceFineLocationAccess) {
6512 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6513 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6514 .setCallingPackage(callingPackage)
6515 .setCallingFeatureId(callingFeatureId)
6516 .setCallingPid(Binder.getCallingPid())
6517 .setCallingUid(Binder.getCallingUid())
6518 .setMethod("requestNetworkScan")
6519 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6520 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6521 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6522 .build());
6523 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006524 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006525 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6526 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006527 if (e != null) {
6528 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6529 throw e;
6530 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006531 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006532 return TelephonyScanManager.INVALID_SCAN_ID;
6533 }
6534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 }
Hall Liu912dfd32019-04-25 14:02:26 -07006536 int callingUid = Binder.getCallingUid();
6537 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006541 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006542 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006543 } finally {
6544 Binder.restoreCallingIdentity(identity);
6545 }
yinxu504e1392017-04-12 16:03:22 -07006546 }
6547
Hall Liub2ac8ef2019-02-28 15:56:23 -08006548 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006549 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006550 boolean hasCarrierPriv;
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6554 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6555 } finally {
6556 Binder.restoreCallingIdentity(identity);
6557 }
Hall Liu558027f2019-05-15 19:14:05 -07006558 boolean hasNetworkScanPermission =
6559 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6560 == PERMISSION_GRANTED;
6561
6562 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6563 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6564 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006565 }
6566
6567 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6568 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006569 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6570 return new SecurityException("Specific channels must not be"
6571 + " scanned without location access.");
6572 }
6573 }
6574 }
6575
Hall Liub2ac8ef2019-02-28 15:56:23 -08006576 return null;
6577 }
6578
yinxu504e1392017-04-12 16:03:22 -07006579 /**
6580 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006581 *
6582 * @param subId id of the subscription
6583 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006584 */
6585 @Override
6586 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6588 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589
Hall Liu912dfd32019-04-25 14:02:26 -07006590 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 final long identity = Binder.clearCallingIdentity();
6592 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006593 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
yinxu504e1392017-04-12 16:03:22 -07006597 }
6598
6599 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006600 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006601 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006602 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006603 */
6604 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006605 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006606 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006607 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006608 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609
6610 final long identity = Binder.clearCallingIdentity();
6611 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006612 if (DBG) log("getAllowedNetworkTypesBitmask");
6613 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6614 int networkTypesBitmask = (result != null ? result[0] : -1);
6615 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6616 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006620 }
6621
6622 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006623 * Get the allowed network types for certain reason.
6624 *
6625 * @param subId the id of the subscription.
6626 * @param reason the reason the allowed network type change is taking place
6627 * @return the allowed network types.
6628 */
6629 @Override
6630 public long getAllowedNetworkTypesForReason(int subId,
6631 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006632 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006633 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
6640 }
6641
6642 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006643 * Enable/Disable E-UTRA-NR Dual Connectivity
6644 * @param subId subscription id of the sim card
6645 * @param nrDualConnectivityState expected NR dual connectivity state
6646 * This can be passed following states
6647 * <ol>
6648 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6649 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6650 * <li>Disable NR dual connectivity and force secondary cell to be released
6651 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6652 * </ol>
6653 * @return operation result.
6654 */
6655 @Override
6656 public int setNrDualConnectivityState(int subId,
6657 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6659 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006660 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006661 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6662 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6663 }
6664
Sooraj Sasindran37444802020-08-11 10:40:43 -07006665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6669 nrDualConnectivityState, subId,
6670 workSource);
6671 if (DBG) log("enableNRDualConnectivity result: " + result);
6672 return result;
6673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
6676 }
6677
6678 /**
6679 * Is E-UTRA-NR Dual Connectivity enabled
6680 * @return true if dual connectivity is enabled else false
6681 */
6682 @Override
6683 public boolean isNrDualConnectivityEnabled(int subId) {
6684 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006685 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006686 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006687 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006688 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6689 return false;
6690 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006691 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6695 null, subId, workSource);
6696 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6697 return isEnabled;
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
6700 }
6701 }
6702
6703 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006704 * Set the allowed network types of the device and
6705 * provide the reason triggering the allowed network change.
6706 *
6707 * @param subId the id of the subscription.
6708 * @param reason the reason the allowed network type change is taking place
6709 * @param allowedNetworkTypes the allowed network types.
6710 * @return true on success; false on any failure.
6711 */
6712 @Override
6713 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006714 @TelephonyManager.AllowedNetworkTypesReason int reason,
6715 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6717 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006718 // If the caller only has carrier privileges, then they should not be able to override
6719 // any network types which were set for security reasons.
6720 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6721 != PERMISSION_GRANTED
6722 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6723 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6724 throw new SecurityException(
6725 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6726 + " reason "
6727 + reason);
6728 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006729 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006730 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6731 return false;
6732 }
6733 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6734 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006735 return false;
6736 }
6737
Aishwarya Mallampati32336e82023-01-04 23:02:56 +00006738 log("setAllowedNetworkTypesForReason: " + reason + " value: "
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006739 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6740
6741
Aishwarya Mallampati32336e82023-01-04 23:02:56 +00006742 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006743 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6744 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006745 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006746
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006747 final long identity = Binder.clearCallingIdentity();
6748 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006749 Boolean success = (Boolean) sendRequest(
6750 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6751 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6752
6753 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6754 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
6758 }
6759
6760 /**
Miaoa84611c2019-03-15 09:21:10 +08006761 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006762 *
Miaoa84611c2019-03-15 09:21:10 +08006763 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006764 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006765 * @hide
6766 */
6767 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006768 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006771 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 try {
Miaoa84611c2019-03-15 09:21:10 +08006773 if (phone != null) {
6774 return phone.hasMatchedTetherApnSetting();
6775 } else {
6776 return false;
6777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 } finally {
6779 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006780 }
Junda Liu475951f2014-11-07 16:45:03 -08006781 }
6782
6783 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006784 * Get the user enabled state of Mobile Data.
6785 *
6786 * TODO: remove and use isUserDataEnabled.
6787 * This can't be removed now because some vendor codes
6788 * calls through ITelephony directly while they should
6789 * use TelephonyManager.
6790 *
6791 * @return true on enabled
6792 */
6793 @Override
6794 public boolean getDataEnabled(int subId) {
6795 return isUserDataEnabled(subId);
6796 }
6797
6798 /**
6799 * Get whether mobile data is enabled per user setting.
6800 *
6801 * There are other factors deciding whether mobile data is actually enabled, but they are
6802 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006803 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006804 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6805 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006806 *
6807 * @return {@code true} if data is enabled else {@code false}
6808 */
6809 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006810 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006811 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006812 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006813 try {
6814 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6815 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006816 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006817 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6818 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006819 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006821 mApp, subId, functionName);
6822
Robert Greenwalt646120a2014-05-23 11:54:03 -07006823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824
6825 final long identity = Binder.clearCallingIdentity();
6826 try {
Jack Yu285100e2022-12-02 22:48:35 -08006827 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6829 Phone phone = PhoneFactory.getPhone(phoneId);
6830 if (phone != null) {
6831 boolean retVal = phone.isUserDataEnabled();
6832 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6833 return retVal;
6834 } else {
6835 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6836 return false;
6837 }
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006840 }
6841 }
6842
6843 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006844 * Checks if the device is capable of mobile data by considering whether whether the
6845 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6846 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006847 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006848 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006849 */
6850 @Override
6851 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006852 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006853 try {
6854 try {
6855 mApp.enforceCallingOrSelfPermission(
6856 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006857 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006858 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006859 try {
6860 mApp.enforceCallingOrSelfPermission(
6861 android.Manifest.permission.READ_PHONE_STATE,
6862 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006863 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006864 mApp.enforceCallingOrSelfPermission(
6865 permission.READ_BASIC_PHONE_STATE, functionName);
6866 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006867 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006868 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006869 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871
6872 final long identity = Binder.clearCallingIdentity();
6873 try {
Jack Yu285100e2022-12-02 22:48:35 -08006874 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875 Phone phone = PhoneFactory.getPhone(phoneId);
6876 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006877 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006878 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 return retVal;
6880 } else {
6881 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6882 return false;
6883 }
6884 } finally {
6885 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006886 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006887 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006888
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006889 /**
6890 * Check if data is enabled for a specific reason
6891 * @param subId Subscription index
6892 * @param reason the reason the data enable change is taking place
6893 * @return {@code true} if the overall data is enabled; {@code false} if not.
6894 */
6895 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006896 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006897 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006898 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006899 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006900 try {
6901 mApp.enforceCallingOrSelfPermission(
6902 android.Manifest.permission.ACCESS_NETWORK_STATE,
6903 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006904 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006905 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6906 functionName);
6907 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006908 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006909 try {
6910 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006911 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006912 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006914 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006915 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006916 }
6917
6918
6919 final long identity = Binder.clearCallingIdentity();
6920 try {
Jack Yu285100e2022-12-02 22:48:35 -08006921 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006922 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006923 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006924 + " reason=" + reason);
6925 }
6926 Phone phone = PhoneFactory.getPhone(phoneId);
6927 if (phone != null) {
6928 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006929 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006930 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006931 return retVal;
6932 } else {
6933 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006934 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006935 + subId + " retVal=false");
6936 }
6937 return false;
6938 }
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
6942 }
6943
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006944 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006945 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006946 // No permission needed; this only lets the caller inspect their own status.
6947 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006948 }
Junda Liu29340342014-07-10 15:23:27 -07006949
6950 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006951 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006952 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006953 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6954 }
6955
6956 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6957 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006958 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006959 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006960 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6961 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006962 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6963 if (cpt == null) {
6964 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006965 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6966 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006967 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006968 }
6969
6970 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006971 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006972 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006973 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006974 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006975 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006976 Phone phone = getPhone(subId);
6977 if (phone == null) {
6978 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6979 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6980 }
6981 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6982 if (cpt == null) {
6983 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006984 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6985 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006986 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006987 }
6988
6989 @Override
6990 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006991 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006992 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6993 }
6994
6995 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006996 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006997 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006998 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006999 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007000 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7001 Phone phone = PhoneFactory.getPhone(phoneId);
7002 if (phone == null) {
7003 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007004 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007005 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7006 if (cpt == null) {
7007 continue;
7008 }
7009 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007010 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7011 break;
7012 }
7013 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007014 return result;
Junda Liu29340342014-07-10 15:23:27 -07007015 }
Derek Tan89e89d42014-07-08 17:00:10 -07007016
7017 @Override
Junda Liue64de782015-04-16 17:19:16 -07007018 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007019 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007020 Phone phone = PhoneFactory.getPhone(phoneId);
7021 if (phone == null) {
7022 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007023 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007024 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7025 if (cpt == null) {
7026 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007027 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007028 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007029 }
7030
Amith Yamasani6e118872016-02-19 12:53:51 -08007031 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007032 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007033 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007034 Phone phone = PhoneFactory.getPhone(phoneId);
7035 if (phone == null) {
7036 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007037 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007038 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7039 if (cpt == null) {
7040 return Collections.emptyList();
7041 }
7042 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007043 }
7044
chen xuf7e9fe82019-05-09 19:31:02 -07007045 @Override
7046 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007047 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007048 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007049 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007050 try {
7051 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7052 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7053 }
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007056 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007057 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007058 }
7059
Rambo Wang6812ffb2022-03-15 16:54:17 -07007060 @Override
7061 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7062 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7063
7064 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7065 if (phone == null) {
7066 return null;
7067 }
7068 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7069 if (cpt == null) {
7070 return null;
7071 }
7072 return cpt.getCarrierServicePackageName();
7073 }
7074
Wink Savilleb564aae2014-10-23 10:18:09 -07007075 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007076 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007077 UiccPort port = phone == null ? null : phone.getUiccPort();
7078 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007079 return null;
7080 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007081 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007082 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007083 return null;
7084 }
7085 return iccId;
7086 }
7087
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007088 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007089 public void setCallComposerStatus(int subId, int status) {
7090 enforceModifyPermission();
7091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 Phone phone = getPhone(subId);
7095 if (phone != null) {
7096 Phone defaultPhone = phone.getImsPhone();
7097 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7098 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7099 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007100 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7101 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007102 }
7103 }
Shuo Qian284ae752020-12-22 19:10:14 -08007104 } catch (ImsException e) {
7105 throw new ServiceSpecificException(e.getCode());
7106 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007107 Binder.restoreCallingIdentity(identity);
7108 }
7109 }
7110
7111 @Override
7112 public int getCallComposerStatus(int subId) {
7113 enforceReadPrivilegedPermission("getCallComposerStatus");
7114
7115 final long identity = Binder.clearCallingIdentity();
7116 try {
7117 Phone phone = getPhone(subId);
7118 if (phone != null) {
7119 Phone defaultPhone = phone.getImsPhone();
7120 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7121 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7122 return imsPhone.getCallComposerStatus();
7123 }
7124 }
7125 } finally {
7126 Binder.restoreCallingIdentity(identity);
7127 }
7128 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7129 }
7130
7131 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007132 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7133 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007134 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007135 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final long identity = Binder.clearCallingIdentity();
7138 try {
7139 final String iccId = getIccId(subId);
7140 final Phone phone = getPhone(subId);
7141 if (phone == null) {
7142 return false;
7143 }
7144 final String subscriberId = phone.getSubscriberId();
7145
7146 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007147 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148 + subscriberId + " to " + number);
7149 }
7150
7151 if (TextUtils.isEmpty(iccId)) {
7152 return false;
7153 }
7154
7155 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7156
7157 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7158 if (alphaTag == null) {
7159 editor.remove(alphaTagPrefKey);
7160 } else {
7161 editor.putString(alphaTagPrefKey, alphaTag);
7162 }
7163
7164 // Record both the line number and IMSI for this ICCID, since we need to
7165 // track all merged IMSIs based on line number
7166 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7167 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7168 if (number == null) {
7169 editor.remove(numberPrefKey);
7170 editor.remove(subscriberPrefKey);
7171 } else {
7172 editor.putString(numberPrefKey, number);
7173 editor.putString(subscriberPrefKey, subscriberId);
7174 }
7175
7176 editor.commit();
7177 return true;
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007180 }
Derek Tan7226c842014-07-02 17:42:23 -07007181 }
7182
7183 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007184 public String getLine1NumberForDisplay(int subId, String callingPackage,
7185 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007186 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007188 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007189 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007190 return null;
7191 }
Derek Tan97ebb422014-09-05 16:55:38 -07007192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 String iccId = getIccId(subId);
7196 if (iccId != null) {
7197 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7198 if (DBG_MERGE) {
7199 log("getLine1NumberForDisplay returning "
7200 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7201 }
7202 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7205 return null;
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007208 }
Derek Tan7226c842014-07-02 17:42:23 -07007209 }
7210
7211 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007212 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7213 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007215 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007216 return null;
7217 }
Derek Tan97ebb422014-09-05 16:55:38 -07007218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 final long identity = Binder.clearCallingIdentity();
7220 try {
7221 String iccId = getIccId(subId);
7222 if (iccId != null) {
7223 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7224 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7225 }
7226 return null;
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007229 }
Derek Tan7226c842014-07-02 17:42:23 -07007230 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007231
7232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007233 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7234 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007235 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7236 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007238 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007239 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007240 return null;
7241 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007242
Jordan Liub49b04b2019-05-06 14:45:15 -07007243 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7244 // the process, where TelephonyManager was instantiated.
7245 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007246 final long identity = Binder.clearCallingIdentity();
7247 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007248 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 final TelephonyManager tele = TelephonyManager.from(context);
7250 final SubscriptionManager sub = SubscriptionManager.from(context);
7251
7252 // Figure out what subscribers are currently active
7253 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254
Jordan Liub49b04b2019-05-06 14:45:15 -07007255 // Only consider subs which match the current subId
7256 // This logic can be simplified. See b/131189269 for progress.
7257 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007258 activeSubscriberIds.add(tele.getSubscriberId(subId));
7259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260
7261 // First pass, find a number override for an active subscriber
7262 String mergeNumber = null;
7263 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7264 for (String key : prefs.keySet()) {
7265 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7266 final String subscriberId = (String) prefs.get(key);
7267 if (activeSubscriberIds.contains(subscriberId)) {
7268 final String iccId = key.substring(
7269 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7270 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7271 mergeNumber = (String) prefs.get(numberKey);
7272 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007273 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 + " for active subscriber " + subscriberId);
7275 }
7276 if (!TextUtils.isEmpty(mergeNumber)) {
7277 break;
7278 }
7279 }
7280 }
7281 }
7282
7283 // Shortcut when no active merged subscribers
7284 if (TextUtils.isEmpty(mergeNumber)) {
7285 return null;
7286 }
7287
7288 // Second pass, find all subscribers under that line override
7289 final ArraySet<String> result = new ArraySet<>();
7290 for (String key : prefs.keySet()) {
7291 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7292 final String number = (String) prefs.get(key);
7293 if (mergeNumber.equals(number)) {
7294 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7295 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7296 final String subscriberId = (String) prefs.get(subscriberKey);
7297 if (!TextUtils.isEmpty(subscriberId)) {
7298 result.add(subscriberId);
7299 }
7300 }
7301 }
7302 }
7303
7304 final String[] resultArray = result.toArray(new String[result.size()]);
7305 Arrays.sort(resultArray);
7306 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007307 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7309 }
7310 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007311 } finally {
7312 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007313 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007314 }
7315
7316 @Override
zoey chen38003472019-12-13 17:16:31 +08007317 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7318 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007319
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 final TelephonyManager telephonyManager = mApp.getSystemService(
7323 TelephonyManager.class);
7324 String subscriberId = telephonyManager.getSubscriberId(subId);
7325 if (subscriberId == null) {
7326 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007327 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007328 + subId);
7329 }
7330 return null;
7331 }
7332
Jack Yu285100e2022-12-02 22:48:35 -08007333 ParcelUuid groupUuid;
7334 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7335 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7336 .getSubscriptionInfo(subId);
7337 groupUuid = info.getGroupUuid();
7338 } else {
7339 final SubscriptionInfo info = mSubscriptionController
7340 .getSubscriptionInfo(subId);
7341 groupUuid = info.getGroupUuid();
7342 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007343 // If it doesn't belong to any group, return just subscriberId of itself.
7344 if (groupUuid == null) {
7345 return new String[]{subscriberId};
7346 }
7347
7348 // Get all subscriberIds from the group.
7349 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007350 List<SubscriptionInfo> groupInfos;
7351 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7352 groupInfos = SubscriptionManagerService.getInstance()
7353 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7354 mApp.getAttributionTag());
7355 } else {
7356 groupInfos = mSubscriptionController
7357 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7358 mApp.getAttributionTag());
7359 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007360 for (SubscriptionInfo subInfo : groupInfos) {
7361 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7362 if (subscriberId != null) {
7363 mergedSubscriberIds.add(subscriberId);
7364 }
7365 }
7366
7367 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370
7371 }
7372 }
7373
7374 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007375 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007376 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007377 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378
7379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 final Phone phone = getPhone(subId);
7382 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007386 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007387
7388 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007389 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007390 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7391 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007392 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7393 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394
7395 final long identity = Binder.clearCallingIdentity();
7396 try {
7397 final Phone phone = getPhone(subId);
7398 if (phone == null) {
7399 return false;
7400 }
7401 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7402 cdmaNonRoamingList);
7403 } finally {
7404 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007405 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007406 }
7407
7408 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007409 @Deprecated
7410 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7411 enforceModifyPermission();
7412
7413 int returnValue = 0;
7414 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007415 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007416 if(result.exception == null) {
7417 if (result.result != null) {
7418 byte[] responseData = (byte[])(result.result);
7419 if(responseData.length > oemResp.length) {
7420 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7421 responseData.length + "bytes. Buffer Size is " +
7422 oemResp.length + "bytes.");
7423 }
7424 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7425 returnValue = responseData.length;
7426 }
7427 } else {
7428 CommandException ex = (CommandException) result.exception;
7429 returnValue = ex.getCommandError().ordinal();
7430 if(returnValue > 0) returnValue *= -1;
7431 }
7432 } catch (RuntimeException e) {
7433 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7434 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7435 if(returnValue > 0) returnValue *= -1;
7436 }
7437
7438 return returnValue;
7439 }
7440
7441 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007442 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007443 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007444 try {
7445 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007446 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007447 mApp, phone.getSubId(), "getRadioAccessFamily");
7448 } catch (SecurityException e) {
7449 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7450 throw e;
7451 }
chen xub97461a2018-10-26 14:17:57 -07007452 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007453 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007454 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
chen xub97461a2018-10-26 14:17:57 -07007458 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007459 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007460 mApp, phone.getSubId(), "getRadioAccessFamily");
7461 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 } finally {
7463 Binder.restoreCallingIdentity(identity);
7464 }
chen xub97461a2018-10-26 14:17:57 -07007465 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007466 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007467
7468 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007469 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007470 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007471 try {
7472 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7473 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007474 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007475 }
7476 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007477 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007478 }
7479 RoleManager rm = mApp.getSystemService(RoleManager.class);
7480 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7481 if (!dialerRoleHolders.contains(callingPackage)) {
7482 throw new SecurityException("App must be the dialer role holder to"
7483 + " upload a call composer pic");
7484 }
7485
7486 Executors.newSingleThreadExecutor().execute(() -> {
7487 ByteArrayOutputStream output = new ByteArrayOutputStream(
7488 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7489 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7490 boolean readUntilEnd = false;
7491 int totalBytesRead = 0;
7492 byte[] buffer = new byte[16 * 1024];
7493 while (true) {
7494 int numRead;
7495 try {
7496 numRead = input.read(buffer);
7497 } catch (IOException e) {
7498 try {
7499 fd.checkError();
7500 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7501 null);
7502 } catch (IOException e1) {
7503 // This means that the other side closed explicitly with an error. If this
7504 // happens, log and ignore.
7505 loge("Remote end of call composer picture pipe closed: " + e1);
7506 }
7507 break;
7508 }
7509 if (numRead == -1) {
7510 readUntilEnd = true;
7511 break;
7512 }
7513 totalBytesRead += numRead;
7514 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7515 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7516 try {
7517 input.close();
7518 } catch (IOException e) {
7519 // ignore
7520 }
7521 break;
7522 }
7523 output.write(buffer, 0, numRead);
7524 }
7525 // Generally, the remote end will close the file descriptors. The only case where we
7526 // close is above, where the picture size is too big.
7527
7528 try {
7529 fd.checkError();
7530 } catch (IOException e) {
7531 loge("Remote end for call composer closed with an error: " + e);
7532 return;
7533 }
7534
Hall Liuaa4211e2021-01-20 15:43:39 -08007535 if (!readUntilEnd) {
7536 loge("Did not finish reading entire image; aborting");
7537 return;
7538 }
Hall Liu82694d52020-12-11 18:22:04 -08007539
Hall Liuaa4211e2021-01-20 15:43:39 -08007540 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7541 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7542 new CallComposerPictureTransfer.Factory() {},
7543 imageData,
7544 (result) -> {
7545 if (result.first != null) {
7546 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7547 Bundle outputResult = new Bundle();
7548 outputResult.putParcelable(
7549 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7550 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7551 outputResult);
7552 } else {
7553 callback.send(result.second, null);
7554 }
7555 }
7556 );
Hall Liu82694d52020-12-11 18:22:04 -08007557 });
7558 }
7559
7560 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007561 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 ImsManager.getInstance(defaultPhone.getContext(),
7568 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007572 }
7573
7574 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007576 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7578 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007579 return false;
7580 }
Svet Ganovb320e182015-04-16 12:30:10 -07007581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 final long identity = Binder.clearCallingIdentity();
7583 try {
7584 // Check the user preference and the system-level IMS setting. Even if the user has
7585 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7586 // In the long run, we may instead need to check if there exists a connection service
7587 // which can support video calling.
7588 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007589 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590 return imsManager.isVtEnabledByPlatform()
7591 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7592 && imsManager.isVtEnabledByUser();
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007596 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007597
Andrew Leea1239f22015-03-02 17:44:07 -08007598 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007599 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7600 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007602 mApp, subId, callingPackage, callingFeatureId,
7603 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 return false;
7605 }
7606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 CarrierConfigManager configManager =
7610 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007611 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
Andrew Leea1239f22015-03-02 17:44:07 -08007616 }
7617
7618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007619 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007621 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 return false;
7623 }
7624
7625 final long identity = Binder.clearCallingIdentity();
7626 try {
7627 CarrierConfigManager configManager =
7628 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007629 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7631 } finally {
7632 Binder.restoreCallingIdentity(identity);
7633 }
Andrew Leea1239f22015-03-02 17:44:07 -08007634 }
7635
Andrew Lee9431b832015-03-09 18:46:45 -07007636 @Override
7637 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007638 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007639 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007640 }
7641
7642 @Override
7643 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 final long identity = Binder.clearCallingIdentity();
7645 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007646 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647 } finally {
7648 Binder.restoreCallingIdentity(identity);
7649 }
Andrew Lee9431b832015-03-09 18:46:45 -07007650 }
7651
Hall Liuf6668912018-10-31 17:05:23 -07007652 /**
7653 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7654 * support for the feature and device firmware support.
7655 *
7656 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7657 */
7658 @Override
7659 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007661 final Phone phone = getPhone(subscriptionId);
7662 if (phone == null) {
7663 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7664 return false;
7665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007667 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7669 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007670 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 return isCarrierSupported && isDeviceSupported;
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
Hall Liu98187582018-01-22 19:15:32 -08007675 }
7676
Hall Liuf6668912018-10-31 17:05:23 -07007677 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007678 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7679 * RTT setting, will return true if the device and carrier both support RTT.
7680 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007681 */
7682 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 final long identity = Binder.clearCallingIdentity();
7684 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007685 boolean isRttSupported = isRttSupported(subscriptionId);
7686 boolean isUserRttSettingOn = Settings.Secure.getInt(
7687 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7688 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7689 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7690 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007694 }
7695
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007696 @Deprecated
7697 @Override
7698 public String getDeviceId(String callingPackage) {
7699 return getDeviceIdWithFeature(callingPackage, null);
7700 }
7701
Sanket Padawe7310cc72015-01-14 09:53:20 -08007702 /**
7703 * Returns the unique device ID of phone, for example, the IMEI for
7704 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7705 *
7706 * <p>Requires Permission:
7707 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7708 */
7709 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007710 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007711 try {
7712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7713 } catch (SecurityException se) {
7714 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7715 throw new SecurityException("Package " + callingPackage + " does not belong to "
7716 + Binder.getCallingUid());
7717 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007718 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007719 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007720 return null;
7721 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007722 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007723 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007724 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007725 return null;
7726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727
7728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 return phone.getDeviceId();
7731 } finally {
7732 Binder.restoreCallingIdentity(identity);
7733 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007734 }
7735
Ping Sunc67b7c22016-03-02 19:16:45 +08007736 /**
7737 * {@hide}
7738 * Returns the IMS Registration Status on a particular subid
7739 *
7740 * @param subId
7741 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007742 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007743 Phone phone = getPhone(subId);
7744 if (phone != null) {
7745 return phone.isImsRegistered();
7746 } else {
7747 return false;
7748 }
7749 }
7750
Santos Cordon7a1885b2015-02-03 11:15:19 -08007751 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007752 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007753 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007755 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007756 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7757 }
7758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
7764 }
7765
7766 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007767 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007768 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007769 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007770 mApp,
7771 subscriptionId,
7772 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007773 final long identity = Binder.clearCallingIdentity();
7774 try {
7775 Phone phone = getPhone(subscriptionId);
7776 if (phone == null) {
7777 return null;
7778 }
7779 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7780 } finally {
7781 Binder.restoreCallingIdentity(identity);
7782 }
7783 }
7784
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007785 /**
7786 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007787 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007788 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 Phone phone = getPhone(subId);
7792 if (phone != null) {
7793 return phone.isWifiCallingEnabled();
7794 } else {
7795 return false;
7796 }
7797 } finally {
7798 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007799 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007800 }
7801
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007802 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007803 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007804 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007805 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 final long identity = Binder.clearCallingIdentity();
7807 try {
7808 Phone phone = getPhone(subId);
7809 if (phone != null) {
7810 return phone.isVideoEnabled();
7811 } else {
7812 return false;
7813 }
7814 } finally {
7815 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007816 }
7817 }
7818
7819 /**
7820 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7821 * defined in {@link ImsRegistrationImplBase}.
7822 */
7823 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 final long identity = Binder.clearCallingIdentity();
7825 try {
7826 Phone phone = getPhone(subId);
7827 if (phone != null) {
7828 return phone.getImsRegistrationTech();
7829 } else {
7830 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7831 }
7832 } finally {
7833 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007834 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007835 }
7836
Stuart Scott8eef64f2015-04-08 15:13:54 -07007837 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007838 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007839 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007840 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7841 return;
7842 }
Kai Shif70f46f2021-03-03 13:59:46 -08007843 Phone defaultPhone = getDefaultPhone();
7844 if (defaultPhone != null) {
7845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7846 mApp, getDefaultPhone().getSubId(), "factoryReset");
7847 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007848 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007849
Svet Ganovcc087f82015-05-12 20:35:54 -07007850 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007851 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7852 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007853 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007854 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007855 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007856 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007857 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007858 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007859 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007860 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007861 // There has been issues when Sms raw table somehow stores orphan
7862 // fragments. They lead to garbled message when new fragments come
7863 // in and combined with those stale ones. In case this happens again,
7864 // user can reset all network settings which will clean up this table.
7865 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007866 // Clean up IMS settings as well here.
7867 int slotId = getSlotIndex(subId);
7868 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7869 ImsManager.getInstance(mApp, slotId).factoryReset();
7870 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007871
Kai Shif70f46f2021-03-03 13:59:46 -08007872 if (defaultPhone == null) {
7873 return;
7874 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007875 // Erase modem config if erase modem on network setting is enabled.
7876 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7877 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7878 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007879 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007880 }
Kai Shif70f46f2021-03-03 13:59:46 -08007881
7882 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007883 } finally {
7884 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007885 }
7886 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007887
SongFerngWangfd89b102021-05-27 22:44:54 +08007888 @VisibleForTesting
7889 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7890 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7891 return;
7892 }
7893 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7894 RILConstants.PREFERRED_NETWORK_MODE);
7895 SubscriptionManager.setSubscriptionProperty(subId,
7896 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7897 "user=" + defaultNetworkType);
7898 phone.loadAllowedNetworksFromSubscriptionDatabase();
7899 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7900 defaultNetworkType, null);
7901 }
7902
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007903 private void cleanUpSmsRawTable(Context context) {
7904 ContentResolver resolver = context.getContentResolver();
7905 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7906 resolver.delete(uri, null, null);
7907 }
7908
Narayan Kamath1c496c22015-04-16 14:40:19 +01007909 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007910 public String getSimLocaleForSubscriber(int subId) {
7911 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7912 final Phone phone = getPhone(subId);
7913 if (phone == null) {
7914 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007915 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 final long identity = Binder.clearCallingIdentity();
7918 try {
Jack Yu285100e2022-12-02 22:48:35 -08007919 SubscriptionInfo info;
7920 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7921 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7922 phone.getContext().getOpPackageName(),
7923 phone.getContext().getAttributionTag());
7924 if (info == null) {
7925 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7926 return null;
7927 }
7928 } else {
7929 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7930 phone.getContext().getOpPackageName(),
7931 phone.getContext().getAttributionTag());
7932 if (info == null) {
7933 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7934 return null;
7935 }
chen xu6291c472019-02-04 12:55:53 -08007936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 // Try and fetch the locale from the carrier properties or from the SIM language
7938 // preferences (EF-PL and EF-LI)...
7939 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007941 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7942 if (localeFromDefaultSim != null) {
7943 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7944 if (DBG) log("Using locale from subId: " + subId + " locale: "
7945 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007946 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007947 } else {
7948 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949 }
7950 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 // The SIM language preferences only store a language (e.g. fr = French), not an
7953 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7954 // the SIM and carrier preferences does not include a country we add the country
7955 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007956 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007958 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007959 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007960 }
7961
7962 if (DBG) log("No locale found - returning null");
7963 return null;
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
7966 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007967 }
7968
tom hsu0b59d292022-09-29 23:49:21 +08007969 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007970 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007971 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007972 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007973 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007974 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7975 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007976 Locale.forLanguageTag(localeTag).getCountry())) {
7977 return localeTag;
7978 }
7979 }
7980 return inputLocale.toLanguageTag();
7981 }
7982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 /**
7984 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7985 */
7986 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007987 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7988 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7989 mApp.getOpPackageName(), mApp.getAttributionTag());
7990 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007991 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007992 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007993 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007994
Gary Jian3aa9a762022-01-24 16:41:19 +08007995 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7996 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007997
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007998 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007999 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8000 * representing the state of the modem.
8001 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008002 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8003 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008004 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008005 */
8006 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008007 public void requestModemActivityInfo(ResultReceiver result) {
8008 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010
8011 final long identity = Binder.clearCallingIdentity();
8012 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008013 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 } finally {
8015 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008016 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008017 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008018
Siddharth Rayb8114062018-06-17 15:02:38 -07008019 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
8020 // less than total activity duration.
8021 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8022 if (info == null) {
8023 return false;
8024 }
8025 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008026 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
8027 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8028
Siddharth Rayb8114062018-06-17 15:02:38 -07008029 return (info.isValid()
8030 && (info.getSleepTimeMillis() <= activityDurationMs)
8031 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07008032 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07008033 && (totalTxTimeMs <= activityDurationMs));
8034 }
8035
Gary Jian3aa9a762022-01-24 16:41:19 +08008036 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8037 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8038 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8039 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8040
8041 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8042 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8043 }
8044
8045 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8046 mLastModemActivityInfo.setReceiveTimeMillis(
8047 rat,
8048 freq,
8049 info.getReceiveTimeMillis(rat, freq)
8050 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8051 }
8052
8053 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8054 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8055 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8056 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8057
8058 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8059 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8060 }
8061 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8062 mLastModemActivityInfo.setReceiveTimeMillis(
8063 rat,
8064 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8065 }
8066
8067 /**
8068 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8069 * @param info recent ModemActivityInfo
8070 */
8071 private void mergeModemActivityInfo(ModemActivityInfo info) {
8072 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008073 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008074 boolean matched;
8075 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8076 matched = false;
8077 int rat = info.getSpecificInfoRat(i);
8078 int freq = info.getSpecificInfoFrequencyRange(i);
8079 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8080 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8081 //if it already exists
8082 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8083 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8084 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8085 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8086 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8087 updateLastModemActivityInfo(info, rat, freq);
8088 matched = true;
8089 }
8090 } else {
8091 updateLastModemActivityInfo(info, rat);
8092 matched = true;
8093 }
8094 }
8095 }
8096
8097 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008098 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008099 new ActivityStatsTechSpecificInfo(
8100 rat,
8101 freq,
8102 info.getTransmitTimeMillis(rat, freq),
8103 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008104 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008105 }
8106 }
8107 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8108 mLastModemActivitySpecificInfo =
8109 new ActivityStatsTechSpecificInfo[merged.size()];
8110 merged.toArray(mLastModemActivitySpecificInfo);
8111
8112 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8113 mLastModemActivityInfo.setSleepTimeMillis(
8114 info.getSleepTimeMillis()
8115 + mLastModemActivityInfo.getSleepTimeMillis());
8116 mLastModemActivityInfo.setIdleTimeMillis(
8117 info.getIdleTimeMillis()
8118 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008119
8120 mLastModemActivityInfo =
8121 new ModemActivityInfo(
8122 mLastModemActivityInfo.getTimestampMillis(),
8123 mLastModemActivityInfo.getSleepTimeMillis(),
8124 mLastModemActivityInfo.getIdleTimeMillis(),
8125 mLastModemActivitySpecificInfo);
8126 }
8127
8128 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8129 ActivityStatsTechSpecificInfo[] info) {
8130 int infoSize = info.length;
8131 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8132 for (int i = 0; i < infoSize; i++) {
8133 ret[i] = new ActivityStatsTechSpecificInfo(
8134 info[i].getRat(), info[i].getFrequencyRange(),
8135 info[i].getTransmitTimeMillis(),
8136 (int) info[i].getReceiveTimeMillis());
8137 }
8138 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008139 }
8140
Jack Yu85bd38a2015-11-09 11:34:32 -08008141 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008142 * Returns the service state information on specified subscription.
8143 */
8144 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008145 public ServiceState getServiceStateForSubscriber(int subId,
8146 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8147 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008149 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008150 return null;
8151 }
8152
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008153 boolean hasFinePermission = false;
8154 boolean hasCoarsePermission = false;
8155 if (!renounceFineLocationAccess) {
8156 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8157 LocationAccessPolicy.checkLocationPermission(mApp,
8158 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8159 .setCallingPackage(callingPackage)
8160 .setCallingFeatureId(callingFeatureId)
8161 .setCallingPid(Binder.getCallingPid())
8162 .setCallingUid(Binder.getCallingUid())
8163 .setMethod("getServiceStateForSubscriber")
8164 .setLogAsInfo(true)
8165 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8166 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8167 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8168 .build());
8169 hasFinePermission =
8170 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8171 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008172
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008173 if (!renounceCoarseLocationAccess) {
8174 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8175 LocationAccessPolicy.checkLocationPermission(mApp,
8176 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8177 .setCallingPackage(callingPackage)
8178 .setCallingFeatureId(callingFeatureId)
8179 .setCallingPid(Binder.getCallingPid())
8180 .setCallingUid(Binder.getCallingUid())
8181 .setMethod("getServiceStateForSubscriber")
8182 .setLogAsInfo(true)
8183 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8184 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8185 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8186 .build());
8187 hasCoarsePermission =
8188 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8189 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008190
Jack Yu479f40e2020-10-27 21:29:25 -07008191 final Phone phone = getPhone(subId);
8192 if (phone == null) {
8193 return null;
8194 }
8195
Jordan Liu0f2bc442020-11-18 16:47:37 -08008196 final long identity = Binder.clearCallingIdentity();
8197
Jack Yu479f40e2020-10-27 21:29:25 -07008198 boolean isCallingPackageDataService = phone.getDataServicePackages()
8199 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008201 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008202 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8203 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8204 .getSubscriptionInfoInternal(subId);
8205 if (subInfo == null || !subInfo.isActive()) {
8206 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8207 + "subId=" + subId);
8208 return null;
8209 }
8210 } else {
8211 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8212 callingFeatureId)) {
8213 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8214 + "subId=" + subId);
8215 return null;
8216 }
Jordan Liuc437b192020-08-17 10:59:12 -07008217 }
8218
Hall Liuf19c44f2018-11-27 14:38:17 -08008219 ServiceState ss = phone.getServiceState();
8220
8221 // Scrub out the location info in ServiceState depending on what level of access
8222 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008223 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008224 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8225 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 } finally {
8227 Binder.restoreCallingIdentity(identity);
8228 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008229 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008230
8231 /**
8232 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8233 *
8234 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8235 * voicemail ringtone.
8236 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8237 * PhoneAccount.
8238 */
8239 @Override
8240 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8244 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008245 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008252 }
8253
8254 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008255 * Sets the per-account voicemail ringtone.
8256 *
8257 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8258 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8259 *
8260 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8261 * voicemail ringtone.
8262 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8263 * PhoneAccount.
8264 */
8265 @Override
8266 public void setVoicemailRingtoneUri(String callingPackage,
8267 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008268 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008270 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8271 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8273 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8274 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276
8277 final long identity = Binder.clearCallingIdentity();
8278 try {
8279 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8280 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008281 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 }
8283 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8284 } finally {
8285 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008286 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008287 }
8288
8289 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008290 * Returns whether vibration is set for voicemail notification in Phone settings.
8291 *
8292 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8293 * voicemail vibration setting.
8294 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8295 */
8296 @Override
8297 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8301 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008302 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008309 }
8310
Youhan Wange64578a2016-05-02 15:32:42 -07008311 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008312 * Sets the per-account voicemail vibration.
8313 *
8314 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8315 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8316 *
8317 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8318 * voicemail vibration setting.
8319 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8320 * specific PhoneAccount.
8321 */
8322 @Override
8323 public void setVoicemailVibrationEnabled(String callingPackage,
8324 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008325 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008327 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8328 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8330 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8331 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008332 }
8333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8337 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 }
8340 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008343 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008344 }
8345
8346 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008347 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8348 *
8349 * @throws SecurityException if the caller does not have the required permission
8350 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008351 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008352 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008353 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008354 }
8355
8356 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008357 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8358 * permission.
8359 *
8360 * @throws SecurityException if the caller does not have the required permission
8361 */
8362 private void enforceSendSmsPermission() {
8363 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8364 }
8365
8366 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008367 * Make sure either called from same process as self (phone) or IPC caller has interact across
8368 * users permission.
8369 *
8370 * @throws SecurityException if the caller does not have the required permission
8371 */
8372 private void enforceInteractAcrossUsersPermission(String message) {
8373 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8374 }
8375
8376 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008377 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008378 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008379 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008380 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008381 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008385 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 if (componentName == null) {
8387 throw new SecurityException(
8388 "Caller not current active visual voicemail package[null]");
8389 }
8390 String vvmPackage = componentName.getPackageName();
8391 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008392 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 }
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008396 }
8397 }
8398
8399 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008400 * Return the application ID for the app type.
8401 *
8402 * @param subId the subscription ID that this request applies to.
8403 * @param appType the uicc app type.
8404 * @return Application ID for specificied app type, or null if no uicc.
8405 */
8406 @Override
8407 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008408 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008409 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410
8411 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008412 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008413 if (phone == null) {
8414 return null;
8415 }
8416 String aid = null;
8417 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008418 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008419 .getApplicationByType(appType).getAid();
8420 } catch (Exception e) {
8421 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8422 }
8423 return aid;
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008426 }
Youhan Wange64578a2016-05-02 15:32:42 -07008427 }
8428
Youhan Wang4001d252016-05-11 10:29:41 -07008429 /**
8430 * Return the Electronic Serial Number.
8431 *
8432 * @param subId the subscription ID that this request applies to.
8433 * @return ESN or null if error.
8434 */
8435 @Override
8436 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008437 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008438 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439
8440 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008441 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442 if (phone == null) {
8443 return null;
8444 }
8445 String esn = null;
8446 try {
8447 esn = phone.getEsn();
8448 } catch (Exception e) {
8449 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8450 }
8451 return esn;
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008454 }
Youhan Wang4001d252016-05-11 10:29:41 -07008455 }
8456
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008457 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008458 * Return the Preferred Roaming List Version.
8459 *
8460 * @param subId the subscription ID that this request applies to.
8461 * @return PRLVersion or null if error.
8462 */
8463 @Override
8464 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008465 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008466 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467
8468 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008469 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 if (phone == null) {
8471 return null;
8472 }
8473 String cdmaPrlVersion = null;
8474 try {
8475 cdmaPrlVersion = phone.getCdmaPrlVersion();
8476 } catch (Exception e) {
8477 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8478 }
8479 return cdmaPrlVersion;
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008482 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008483 }
8484
8485 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008486 * Get snapshot of Telephony histograms
8487 * @return List of Telephony histograms
8488 * @hide
8489 */
8490 @Override
8491 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8493 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494
8495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 return RIL.getTelephonyRILTimingHistograms();
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
8500 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008501 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008502
8503 /**
8504 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008505 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8506 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008507 * Require system privileges. In the future we may add this to carrier APIs.
8508 *
Michele Berionne482f8202018-11-27 18:57:59 -08008509 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008510 */
8511 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008512 @TelephonyManager.SetCarrierRestrictionResult
8513 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008514 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008516
Michele Berionne482f8202018-11-27 18:57:59 -08008517 if (carrierRestrictionRules == null) {
8518 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008519 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521 final long identity = Binder.clearCallingIdentity();
8522 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008523 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008524 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 } finally {
8526 Binder.restoreCallingIdentity(identity);
8527 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008528 }
8529
8530 /**
8531 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008532 * Get the allowed carrier list and the excluded carrier list, including the priority between
8533 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008534 * Require system privileges. In the future we may add this to carrier APIs.
8535 *
Michele Berionne482f8202018-11-27 18:57:59 -08008536 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008537 */
8538 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008539 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008540 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008541 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008545 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8546 if (response instanceof CarrierRestrictionRules) {
8547 return (CarrierRestrictionRules) response;
8548 }
8549 // Response is an Exception of some kind,
8550 // which is signalled to the user as a NULL retval
8551 return null;
8552 } catch (Exception e) {
8553 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8554 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008558 }
8559
fionaxu59545b42016-05-25 15:53:37 -07008560 /**
fionaxu59545b42016-05-25 15:53:37 -07008561 * Action set from carrier signalling broadcast receivers to enable/disable radio
8562 * @param subId the subscription ID that this action applies to.
8563 * @param enabled control enable or disable radio.
8564 * {@hide}
8565 */
8566 @Override
8567 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8568 enforceModifyPermission();
8569 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570
8571 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008572 if (phone == null) {
8573 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8574 return;
8575 }
8576 try {
8577 phone.carrierActionSetRadioEnabled(enabled);
8578 } catch (Exception e) {
8579 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008580 } finally {
8581 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008582 }
8583 }
8584
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008585 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008586 * Enable or disable Voice over NR (VoNR)
8587 * @param subId the subscription ID that this action applies to.
8588 * @param enabled enable or disable VoNR.
8589 * @return operation result.
8590 */
8591 @Override
8592 public int setVoNrEnabled(int subId, boolean enabled) {
8593 enforceModifyPermission();
8594 final Phone phone = getPhone(subId);
8595
8596 final long identity = Binder.clearCallingIdentity();
8597 if (phone == null) {
8598 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8599 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8600 }
8601
8602 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8603 try {
8604 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8605 workSource);
8606 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008607
8608 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8609 if (DBG) {
8610 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8611 }
8612 SubscriptionManager.setSubscriptionProperty(
8613 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8614 (enabled ? "1" : "0"));
8615 }
8616
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008617 return result;
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
8621 }
8622
8623 /**
8624 * Is voice over NR enabled
8625 * @return true if VoNR is enabled else false
8626 */
8627 @Override
8628 public boolean isVoNrEnabled(int subId) {
8629 enforceReadPrivilegedPermission("isVoNrEnabled");
8630 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8634 null, subId, workSource);
8635 if (DBG) log("isVoNrEnabled: " + isEnabled);
8636 return isEnabled;
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
8640 }
8641
8642 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008643 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8644 * network status based on which carrier apps could apply actions accordingly,
8645 * enable/disable default url handler for example.
8646 *
8647 * @param subId the subscription ID that this action applies to.
8648 * @param report control start/stop reporting the default network status.
8649 * {@hide}
8650 */
8651 @Override
8652 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8653 enforceModifyPermission();
8654 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655
8656 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008657 if (phone == null) {
8658 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8659 return;
8660 }
8661 try {
8662 phone.carrierActionReportDefaultNetworkStatus(report);
8663 } catch (Exception e) {
8664 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008665 } finally {
8666 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008667 }
8668 }
8669
8670 /**
fionaxud9622282017-07-17 17:51:30 -07008671 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8672 * @param subId the subscription ID that this action applies to.
8673 * {@hide}
8674 */
8675 @Override
8676 public void carrierActionResetAll(int subId) {
8677 enforceModifyPermission();
8678 final Phone phone = getPhone(subId);
8679 if (phone == null) {
8680 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8681 return;
8682 }
8683 try {
8684 phone.carrierActionResetAll();
8685 } catch (Exception e) {
8686 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8687 }
8688 }
8689
8690 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008691 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8692 * bug report is being generated.
8693 */
8694 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008695 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008696 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8697 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008698 writer.println("Permission Denial: can't dump Phone from pid="
8699 + Binder.getCallingPid()
8700 + ", uid=" + Binder.getCallingUid()
8701 + "without permission "
8702 + android.Manifest.permission.DUMP);
8703 return;
8704 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008705 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008706 }
Jack Yueb89b242016-06-22 13:27:47 -07008707
Brad Ebingerdac2f002018-04-03 15:17:52 -07008708 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008709 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8710 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8711 @NonNull String[] args) {
8712 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8713 this, in.getFileDescriptor(), out.getFileDescriptor(),
8714 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008715 }
8716
Jack Yueb89b242016-06-22 13:27:47 -07008717 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008718 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008719 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008720 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008721 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008722 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008723 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008724 */
8725 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008726 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008727 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008728 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8729 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8730 try {
8731 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008732 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008733 } catch (SecurityException se) {
8734 enforceModifyPermission();
8735 }
8736 } else {
8737 enforceModifyPermission();
8738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008739
8740 final long identity = Binder.clearCallingIdentity();
8741 try {
8742 Phone phone = getPhone(subId);
8743 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008744 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8745 phone.carrierActionSetMeteredApnsEnabled(enabled);
8746 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008747 phone.getDataSettingsManager().setDataEnabled(
8748 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750 }
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008753 }
8754 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008755
8756 /**
8757 * Get Client request stats
8758 * @return List of Client Request Stats
8759 * @hide
8760 */
8761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008762 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8763 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008765 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008766 return null;
8767 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008768 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008770 final long identity = Binder.clearCallingIdentity();
8771 try {
8772 if (phone != null) {
8773 return phone.getClientRequestStats();
8774 }
8775
8776 return null;
8777 } finally {
8778 Binder.restoreCallingIdentity(identity);
8779 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008780 }
8781
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008782 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008783 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008784 if (uid == Process.ROOT_UID && packageName == null) {
8785 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8786 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8787 // exception. ROOT_UID seems not to have a valid package name returned by
8788 // PackageManager, so just fake it here to avoid issues when running telephony shell
8789 // commands that plumb through the RIL as root, like so:
8790 // $ adb root
8791 // $ adb shell cmd phone ...
8792 packageName = "root";
8793 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008794 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008795 }
Jack Yueb4124c2017-02-16 15:32:43 -08008796
8797 /**
Grace Chen70990072017-03-24 17:21:30 -07008798 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008799 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008800 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008801 * @param state State of SIM (power down, power up, pass through)
8802 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8803 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8804 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008805 *
8806 **/
8807 @Override
Grace Chen70990072017-03-24 17:21:30 -07008808 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008809 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008810 Phone phone = PhoneFactory.getPhone(slotIndex);
8811
vagdeviaf9a5b92018-08-15 16:01:53 -07008812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008817 phone.setSimPowerState(state, null, workSource);
8818 }
8819 } finally {
8820 Binder.restoreCallingIdentity(identity);
8821 }
8822 }
8823
8824 /**
8825 * Set SIM card power state.
8826 *
8827 * @param slotIndex SIM slot id.
8828 * @param state State of SIM (power down, power up, pass through)
8829 * @param callback callback to trigger after success or failure
8830 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8831 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8832 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8833 *
8834 **/
8835 @Override
8836 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8837 IIntegerConsumer callback) {
8838 enforceModifyPermission();
8839 Phone phone = PhoneFactory.getPhone(slotIndex);
8840
8841 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8842
8843 final long identity = Binder.clearCallingIdentity();
8844 try {
8845 if (phone != null) {
8846 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8847 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 }
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008851 }
8852 }
Shuo Qiandd210312017-04-12 22:11:33 +00008853
Tyler Gunn65d45c22017-06-05 11:22:26 -07008854 private boolean isUssdApiAllowed(int subId) {
8855 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008856 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008857 if (configManager == null) {
8858 return false;
8859 }
8860 PersistableBundle pb = configManager.getConfigForSubId(subId);
8861 if (pb == null) {
8862 return false;
8863 }
8864 return pb.getBoolean(
8865 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8866 }
8867
Shuo Qiandd210312017-04-12 22:11:33 +00008868 /**
8869 * Check if phone is in emergency callback mode
8870 * @return true if phone is in emergency callback mode
8871 * @param subId sub id
8872 */
goneil9c5f4872017-12-05 14:07:56 -08008873 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008874 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008875 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008876 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877
8878 final long identity = Binder.clearCallingIdentity();
8879 try {
8880 if (phone != null) {
8881 return phone.isInEcm();
8882 } else {
8883 return false;
8884 }
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008887 }
8888 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008889
8890 /**
8891 * Get the current signal strength information for the given subscription.
8892 * Because this information is not updated when the device is in a low power state
8893 * it should not be relied-upon to be current.
8894 * @param subId Subscription index
8895 * @return the most recent cached signal strength info from the modem
8896 */
8897 @Override
8898 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 final long identity = Binder.clearCallingIdentity();
8900 try {
8901 Phone p = getPhone(subId);
8902 if (p == null) {
8903 return null;
8904 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906 return p.getSignalStrength();
8907 } finally {
8908 Binder.restoreCallingIdentity(identity);
8909 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008910 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008911
Pengquan Meng77b7f132018-08-22 14:49:57 -07008912 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008913 * Get the current modem radio state for the given slot.
8914 * @param slotIndex slot index.
8915 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008916 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008917 * @return the current radio power state from the modem
8918 */
8919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008920 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008921 Phone phone = PhoneFactory.getPhone(slotIndex);
8922 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8924 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008925 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8926 }
8927
8928 final long identity = Binder.clearCallingIdentity();
8929 try {
8930 return phone.getRadioPowerState();
8931 } finally {
8932 Binder.restoreCallingIdentity(identity);
8933 }
8934 }
8935 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8936 }
8937
8938 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008939 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8940 *
8941 * <p>Requires one of the following permissions:
8942 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008943 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008944 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8945 * privileges.
8946 *
8947 * @param subId subscription id
8948 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8949 * {@code false}.
8950 */
8951 @Override
8952 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008953 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008954 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008955 try {
8956 mApp.enforceCallingOrSelfPermission(
8957 android.Manifest.permission.ACCESS_NETWORK_STATE,
8958 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008959 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008960 mApp.enforceCallingOrSelfPermission(
8961 permission.READ_BASIC_PHONE_STATE, functionName);
8962 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008963 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008964 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008965 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008966 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008967
Pengquan Menga1bb6272018-09-06 09:59:22 -07008968 boolean isEnabled = false;
8969 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008970 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008971 Phone phone = getPhone(subId);
8972 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008973 } finally {
8974 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008975 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008976 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008977 }
8978
8979
8980 /**
8981 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8982 *
8983 * <p> Requires permission:
8984 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8985 * privileges.
8986 *
8987 * @param subId subscription id
8988 * @param isEnabled {@code true} means enable, {@code false} means disable.
8989 */
8990 @Override
8991 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8993 mApp, subId, "setDataRoamingEnabled");
8994
Pengquan Menga1bb6272018-09-06 09:59:22 -07008995 final long identity = Binder.clearCallingIdentity();
8996 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008997 Phone phone = getPhone(subId);
8998 if (phone != null) {
8999 phone.setDataRoamingEnabled(isEnabled);
9000 }
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009003 }
9004 }
9005
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009006 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009007 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009008 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009009 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009010 mApp, subId, "isManualNetworkSelectionAllowed");
9011
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009012 boolean isAllowed = true;
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009015 Phone phone = getPhone(subId);
9016 if (phone != null) {
9017 isAllowed = phone.isCspPlmnEnabled();
9018 }
9019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
9022 return isAllowed;
9023 }
9024
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009025 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9026 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009027 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009028 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009029 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009030 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9031 if (phone == null) {
9032 return false;
9033 }
9034 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9035 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9036 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009037 }
9038
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009039 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009040 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009041 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009042 mApp.getSystemService(AppOpsManager.class)
9043 .checkPackage(Binder.getCallingUid(), callingPackage);
9044
Jordan Liu1e142fc2019-04-22 15:10:43 -07009045 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009046 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009047 try {
9048 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009049 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009050 } catch (SecurityException e) {
9051 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9052 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009053 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009054 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009055 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009056 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009057 }
sandeepjsb6c87872021-09-27 15:34:44 +00009058 // checking compatibility, if calling app's target SDK is T and beyond.
9059 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9060 Binder.getCallingUid())) {
9061 isIccIdAccessRestricted = true;
9062 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009063 final long identity = Binder.clearCallingIdentity();
9064 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009065 UiccController uiccController = UiccController.getInstance();
9066 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009067 if (hasReadPermission) {
9068 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009069 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009070
9071 // Remove private info if the caller doesn't have access
9072 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9073 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009074 //setting the value after compatibility check
9075 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009076 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9077 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009078 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009079 if (card == null) {
9080 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009081 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009082 continue;
9083 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009084 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9085 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009086 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009087 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009088 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009089 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9090 for (UiccPortInfo portInfo : portInfos) {
9091 UiccPort port = uiccController.getUiccPortForSlot(
9092 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9093 if (port == null) {
9094 // assume no access if port is null
9095 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9096 continue;
9097 }
9098 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9099 uiccPortInfos.add(portInfo);
9100 } else {
9101 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9102 }
9103 }
9104 filteredInfos.add(new UiccCardInfo(
9105 cardInfo.isEuicc(),
9106 cardInfo.getCardId(),
9107 null,
9108 cardInfo.getPhysicalSlotIndex(),
9109 cardInfo.isRemovable(),
9110 cardInfo.isMultipleEnabledProfilesSupported(),
9111 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009112 }
9113 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
sandeepjsb6c87872021-09-27 15:34:44 +00009119 /**
9120 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9121 * generally private and require carrier privileges to view.
9122 *
9123 * @hide
9124 */
9125 @NonNull
9126 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9127 List<UiccPortInfo> portinfo = new ArrayList<>();
9128 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9129 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9130 }
9131 return new UiccCardInfo(
9132 cardInfo.isEuicc(),
9133 cardInfo.getCardId(),
9134 null,
9135 cardInfo.getPhysicalSlotIndex(),
9136 cardInfo.isRemovable(),
9137 cardInfo.isMultipleEnabledProfilesSupported(),
9138 portinfo
9139 );
9140 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009141
sandeepjsb6c87872021-09-27 15:34:44 +00009142 /**
9143 * @hide
9144 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9145 * These values are generally private and require carrier privileges to view.
9146 */
9147 @NonNull
9148 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9149 return new UiccPortInfo(
9150 UiccPortInfo.ICCID_REDACTED,
9151 portInfo.getPortIndex(),
9152 portInfo.getLogicalSlotIndex(),
9153 portInfo.isActive()
9154 );
9155 }
9156 @Override
9157 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009158 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009159 mApp.getSystemService(AppOpsManager.class)
9160 .checkPackage(Binder.getCallingUid(), callingPackage);
9161
sandeepjsb6c87872021-09-27 15:34:44 +00009162 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009163
Aman Guptaf3c90b32022-03-17 04:54:16 +00009164 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9165 // we are reading iccId which is PII data.
9166 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009167
9168 // checking compatibility, if calling app's target SDK is T and beyond.
9169 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9170 Binder.getCallingUid())) {
9171 isLogicalSlotAccessRestricted = true;
9172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009173 final long identity = Binder.clearCallingIdentity();
9174 try {
9175 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009176 if (slots == null || slots.length == 0) {
9177 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009178 return null;
9179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009180 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9181 for (int i = 0; i < slots.length; i++) {
9182 UiccSlot slot = slots[i];
9183 if (slot == null) {
9184 continue;
9185 }
9186
Jordan Liu7be7e652019-05-06 18:55:02 +00009187 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009188 UiccCard card = slot.getUiccCard();
9189 if (card != null) {
9190 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009191 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009192 cardId = slot.getEid();
9193 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009194 // If cardId is null, use iccId of default port as cardId.
9195 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009197 }
9198
Jordan Liu857451f2019-05-09 16:35:35 -07009199 if (cardId != null) {
9200 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9201 // if cardId is an EID, it's all digits so this is fine
9202 cardId = IccUtils.stripTrailingFs(cardId);
9203 }
9204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009205 int cardState = 0;
9206 switch (slot.getCardState()) {
9207 case CARDSTATE_ABSENT:
9208 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9209 break;
9210 case CARDSTATE_PRESENT:
9211 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9212 break;
9213 case CARDSTATE_ERROR:
9214 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9215 break;
9216 case CARDSTATE_RESTRICTED:
9217 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9218 break;
9219 default:
9220 break;
9221
9222 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009223 List<UiccPortInfo> portInfos = new ArrayList<>();
9224 int[] portIndexes = slot.getPortList();
9225 for (int portIdx : portIndexes) {
9226 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009227 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009228 portInfos.add(new UiccPortInfo(iccId, portIdx,
9229 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009231 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009232 slot.isEuicc(),
9233 cardId,
9234 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009235 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009236 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009237 //setting the value after compatibility check
9238 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009239 }
9240 return infos;
9241 } finally {
9242 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009243 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009244 }
9245
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009246 /* Returns null if doesn't have read permission or carrier privilege access. */
9247 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9248 boolean hasReadPermission) {
9249 String iccId = slot.getIccId(portIndex);
9250 if (hasReadPermission) { // if has read permission
9251 return iccId;
9252 } else {
9253 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9254 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9255 // if no read permission, checking carrier privilege access
9256 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9257 return iccId;
9258 }
9259 }
9260 }
9261 // No read permission or carrier privilege access.
9262 return UiccPortInfo.ICCID_REDACTED;
9263 }
9264
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009265 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009266 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009267 public boolean switchSlots(int[] physicalSlots) {
9268 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009269
9270 final long identity = Binder.clearCallingIdentity();
9271 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009272 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9273 for (int i = 0; i < physicalSlots.length; i++) {
9274 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9275 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9276 physicalSlots[i], i));
9277 }
9278 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009282 }
Jack Yu4c988042018-02-27 15:30:01 -08009283
9284 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009285 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9286 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9287 enforceModifyPermission();
9288
9289 final long identity = Binder.clearCallingIdentity();
9290 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009291 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009292 } finally {
9293 Binder.restoreCallingIdentity(identity);
9294 }
9295 }
9296
9297 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009298 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009299 final long identity = Binder.clearCallingIdentity();
9300 try {
9301 return UiccController.getInstance().getCardIdForDefaultEuicc();
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
Pengquan Meng85728fb2018-03-12 16:31:21 -07009307 /**
goneil47ffb6e2018-04-06 15:40:58 -07009308 * A test API to reload the UICC profile.
9309 *
9310 * <p>Requires that the calling app has permission
9311 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9312 * @hide
9313 */
9314 @Override
9315 public void refreshUiccProfile(int subId) {
9316 enforceModifyPermission();
9317
9318 final long identity = Binder.clearCallingIdentity();
9319 try {
9320 Phone phone = getPhone(subId);
9321 if (phone == null) {
9322 return;
9323 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009324 UiccPort uiccPort = phone.getUiccPort();
9325 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009326 return;
9327 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009328 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009329 if (uiccProfile == null) {
9330 return;
9331 }
9332 uiccProfile.refresh();
9333 } finally {
9334 Binder.restoreCallingIdentity(identity);
9335 }
9336 }
9337
9338 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009339 * Returns false if the mobile data is disabled by default, otherwise return true.
9340 */
9341 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009342 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009343 }
9344
9345 /**
9346 * Returns true if the data roaming is enabled by default, i.e the system property
9347 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9348 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9349 */
9350 private boolean getDefaultDataRoamingEnabled(int subId) {
9351 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009352 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009353 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009354 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9355 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9356 return isDataRoamingEnabled;
9357 }
9358
9359 /**
9360 * Returns the default network type for the given {@code subId}, if the default network type is
9361 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9362 */
9363 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009364 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009365 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009366 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9367 return list.get(phoneId);
9368 }
9369 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009370 }
fionaxua13278b2018-03-21 00:08:13 -07009371
9372 @Override
9373 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009374 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009375 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009376
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 final Phone phone = getPhone(subId);
9380 if (phone == null) {
9381 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9382 return;
9383 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009384 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9385 if (cpt != null) {
9386 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9387 }
9388 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009389 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9390 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009391 if (carrierPrivilegeRules == null) {
9392 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9393 } else {
9394 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009396 } finally {
9397 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009398 }
fionaxua13278b2018-03-21 00:08:13 -07009399 }
9400
9401 @Override
9402 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009403 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009404
9405 final long identity = Binder.clearCallingIdentity();
9406 try {
9407 final Phone phone = getPhone(subId);
9408 if (phone == null) {
9409 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9410 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9411 }
9412 return phone.getCarrierIdListVersion();
9413 } finally {
9414 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009415 }
fionaxua13278b2018-03-21 00:08:13 -07009416 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009417
9418 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009419 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9420 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009422 mApp, subId, callingPackage, callingFeatureId,
9423 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009424 return -1;
9425 }
9426
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009434
9435 @Override
9436 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009437 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009438 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009439 mApp, subId, "getCdmaRoamingMode");
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9444 } finally {
9445 Binder.restoreCallingIdentity(identity);
9446 }
9447 }
9448
9449 @Override
9450 public boolean setCdmaRoamingMode(int subId, int mode) {
9451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9452 mApp, subId, "setCdmaRoamingMode");
9453
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
9456 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9457 } finally {
9458 Binder.restoreCallingIdentity(identity);
9459 }
9460 }
9461
9462 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009463 public int getCdmaSubscriptionMode(int subId) {
9464 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009465 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009466 mApp, subId, "getCdmaSubscriptionMode");
9467
9468 final long identity = Binder.clearCallingIdentity();
9469 try {
9470 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
9475
9476 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009477 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9479 mApp, subId, "setCdmaSubscriptionMode");
9480
9481 final long identity = Binder.clearCallingIdentity();
9482 try {
9483 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9484 } finally {
9485 Binder.restoreCallingIdentity(identity);
9486 }
9487 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009488
sqianc5eccab2018-10-19 18:46:41 -07009489 @Override
sqian8c685422019-02-22 15:55:18 -08009490 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009491 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009493 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9494 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009495 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9496 }
9497 final long identity = Binder.clearCallingIdentity();
9498 try {
sqian854d44b2018-12-12 16:48:18 -08009499 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9500 for (Phone phone: PhoneFactory.getPhones()) {
9501 if (phone.getEmergencyNumberTracker() != null
9502 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9503 emergencyNumberListInternal.put(
9504 phone.getSubId(),
9505 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9506 }
sqian11b7a0e2018-12-05 18:48:28 -08009507 }
sqian854d44b2018-12-12 16:48:18 -08009508 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009509 } finally {
9510 Binder.restoreCallingIdentity(identity);
9511 }
sqianc5eccab2018-10-19 18:46:41 -07009512 }
9513
9514 @Override
sqian8c685422019-02-22 15:55:18 -08009515 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009516 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009517 if (!exactMatch) {
9518 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009519 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009520 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009521 }
9522 final long identity = Binder.clearCallingIdentity();
9523 try {
sqian854d44b2018-12-12 16:48:18 -08009524 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009525 //Note: we ignore passed in param exactMatch. We can remove it once
9526 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009527 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009528 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009529 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009530 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009531 }
sqian11b7a0e2018-12-05 18:48:28 -08009532 }
9533 return false;
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537 }
9538
sqianf4ca7ed2019-01-15 18:32:07 -08009539 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009540 * Start emergency callback mode for GsmCdmaPhone for testing.
9541 */
9542 @Override
9543 public void startEmergencyCallbackMode() {
9544 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9545 "startEmergencyCallbackMode");
9546 enforceModifyPermission();
9547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 for (Phone phone : PhoneFactory.getPhones()) {
9550 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9551 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9552 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9553 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9554 gsmCdmaPhone.obtainMessage(
9555 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9556 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9557 }
9558 }
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
9564 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009565 * Update emergency number list for test mode.
9566 */
9567 @Override
9568 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9569 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9570 "updateEmergencyNumberListTestMode");
9571
9572 final long identity = Binder.clearCallingIdentity();
9573 try {
9574 for (Phone phone: PhoneFactory.getPhones()) {
9575 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9576 if (tracker != null) {
9577 tracker.executeEmergencyNumberTestModeCommand(action, num);
9578 }
9579 }
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
9584
9585 /**
9586 * Get the full emergency number list for test mode.
9587 */
9588 @Override
9589 public List<String> getEmergencyNumberListTestMode() {
9590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9591 "getEmergencyNumberListTestMode");
9592
9593 final long identity = Binder.clearCallingIdentity();
9594 try {
9595 Set<String> emergencyNumbers = new HashSet<>();
9596 for (Phone phone: PhoneFactory.getPhones()) {
9597 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9598 if (tracker != null) {
9599 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9600 emergencyNumbers.add(num.getNumber());
9601 }
9602 }
9603 }
9604 return new ArrayList<>(emergencyNumbers);
9605 } finally {
9606 Binder.restoreCallingIdentity(identity);
9607 }
9608 }
9609
chen xud6b45bd2018-10-30 22:27:10 -07009610 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009611 public int getEmergencyNumberDbVersion(int subId) {
9612 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9613
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
9616 final Phone phone = getPhone(subId);
9617 if (phone == null) {
9618 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9619 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9620 }
9621 return phone.getEmergencyNumberDbVersion();
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
9627 @Override
9628 public void notifyOtaEmergencyNumberDbInstalled() {
9629 enforceModifyPermission();
9630
9631 final long identity = Binder.clearCallingIdentity();
9632 try {
9633 for (Phone phone: PhoneFactory.getPhones()) {
9634 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9635 if (tracker != null) {
9636 tracker.updateOtaEmergencyNumberDatabase();
9637 }
9638 }
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
9644 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009645 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009646 enforceActiveEmergencySessionPermission();
9647
9648 final long identity = Binder.clearCallingIdentity();
9649 try {
9650 for (Phone phone: PhoneFactory.getPhones()) {
9651 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9652 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009653 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9654 }
9655 }
9656 } finally {
9657 Binder.restoreCallingIdentity(identity);
9658 }
9659 }
9660
9661 @Override
9662 public void resetOtaEmergencyNumberDbFilePath() {
9663 enforceActiveEmergencySessionPermission();
9664
9665 final long identity = Binder.clearCallingIdentity();
9666 try {
9667 for (Phone phone: PhoneFactory.getPhones()) {
9668 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9669 if (tracker != null) {
9670 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009671 }
9672 }
9673 } finally {
9674 Binder.restoreCallingIdentity(identity);
9675 }
9676 }
9677
9678 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009679 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9680 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9681 Phone phone = getPhone(subId);
9682 if (phone == null) {
9683 return null;
9684 }
9685 final long identity = Binder.clearCallingIdentity();
9686 try {
9687 UiccProfile profile = UiccController.getInstance()
9688 .getUiccProfileForPhone(phone.getPhoneId());
9689 if (profile != null) {
9690 return profile.getCertsFromCarrierPrivilegeAccessRules();
9691 }
9692 } finally {
9693 Binder.restoreCallingIdentity(identity);
9694 }
9695 return null;
9696 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009697
9698 /**
9699 * Enable or disable a modem stack.
9700 */
9701 @Override
9702 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9703 enforceModifyPermission();
9704
9705 final long identity = Binder.clearCallingIdentity();
9706 try {
9707 Phone phone = PhoneFactory.getPhone(slotIndex);
9708 if (phone == null) {
9709 return false;
9710 } else {
9711 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9712 }
9713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
Michelecea4cf22018-12-21 15:00:11 -08009717
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009718 /**
9719 * Whether a modem stack is enabled or not.
9720 */
9721 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009722 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9723 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009724 Phone phone = PhoneFactory.getPhone(slotIndex);
9725 if (phone == null) return false;
9726
9727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009728 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9729 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009730 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9731 }
9732
9733 final long identity = Binder.clearCallingIdentity();
9734 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009735 try {
9736 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9737 } catch (NoSuchElementException ex) {
9738 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9739 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009740 } finally {
9741 Binder.restoreCallingIdentity(identity);
9742 }
9743 }
9744
Michelecea4cf22018-12-21 15:00:11 -08009745 @Override
Michele0ea7d782019-03-19 14:58:42 -07009746 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009747 enforceModifyPermission();
9748
9749 final long identity = Binder.clearCallingIdentity();
9750 try {
9751 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009752 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009753 .commit();
9754 } finally {
9755 Binder.restoreCallingIdentity(identity);
9756 }
9757 }
9758
9759 @Override
Michele0ea7d782019-03-19 14:58:42 -07009760 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009761 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009763 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9764 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009765 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009766 }
Michelecea4cf22018-12-21 15:00:11 -08009767
9768 final long identity = Binder.clearCallingIdentity();
9769 try {
Michele0ea7d782019-03-19 14:58:42 -07009770 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009771 } finally {
9772 Binder.restoreCallingIdentity(identity);
9773 }
9774 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009775
Michele0ea7d782019-03-19 14:58:42 -07009776 @TelephonyManager.IsMultiSimSupportedResult
9777 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009778 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9779 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9780 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009781 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9782 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009783 }
9784 // Check if the hardware supports multisim functionality. If usage of multisim is not
9785 // supported by the modem, indicate that it is restricted.
9786 PhoneCapability staticCapability =
9787 mPhoneConfigurationManager.getStaticPhoneCapability();
9788 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009789 loge("isMultiSimSupportedInternal: no static configuration available");
9790 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009791 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009792 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009793 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9794 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009795 }
9796 // Check if support of multiple SIMs is restricted by carrier
9797 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009798 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009799 }
9800
Michele0ea7d782019-03-19 14:58:42 -07009801 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009802 }
9803
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009804 /**
9805 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009806 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9807 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9808 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009809 * @param numOfSims number of active sims we want to switch to
9810 */
9811 @Override
9812 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009813 if (numOfSims == 1) {
9814 enforceModifyPermission();
9815 } else {
9816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9817 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9818 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009819 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009820
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009821 try {
Michele30b57b22019-03-01 12:01:14 -08009822 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009823 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009824 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9825 return;
9826 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009827 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009833 @Override
9834 public boolean isApplicationOnUicc(int subId, int appType) {
9835 enforceReadPrivilegedPermission("isApplicationOnUicc");
9836 Phone phone = getPhone(subId);
9837 if (phone == null) {
9838 return false;
9839 }
9840 final long identity = Binder.clearCallingIdentity();
9841 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009842 UiccPort uiccPort = phone.getUiccPort();
9843 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009844 return false;
9845 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009846 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009847 if (uiccProfile == null) {
9848 return false;
9849 }
9850 if (TelephonyManager.APPTYPE_SIM <= appType
9851 && appType <= TelephonyManager.APPTYPE_ISIM) {
9852 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9853 }
9854 return false;
9855 } finally {
9856 Binder.restoreCallingIdentity(identity);
9857 }
9858 }
9859
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009860 /**
chen xub4baa772019-04-03 10:23:41 -07009861 * Get whether making changes to modem configurations will trigger reboot.
9862 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009863 */
9864 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009865 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9866 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009868 mApp, subId, callingPackage, callingFeatureId,
9869 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009870 return false;
9871 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 }
9879
Nathan Harold29f5f052019-02-15 13:41:57 -08009880 private void updateModemStateMetrics() {
9881 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9882 // TODO: check the state for each modem if the api is ready.
9883 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9884 }
9885
Pengquan Meng3889a572019-01-23 11:16:29 -08009886 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009887 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009888 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009889 // Verify that the callingPackage belongs to the calling UID
9890 mApp.getSystemService(AppOpsManager.class)
9891 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009892 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009893 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009894 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009895 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9896 if (slotInfos != null) {
9897 for (int i = 0; i < slotInfos.length; i++) {
9898 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9899 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9900 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9901 portInfo.getLogicalSlotIndex()));
9902 }
9903 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009904 }
9905 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009906 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009911
9912 /**
9913 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009914 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009915 */
jimsunf9ec1622022-09-13 21:18:43 +08009916 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009917 @Override
9918 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009919 return getHalVersion(HAL_SERVICE_RADIO);
9920 }
9921
9922 /**
9923 * Get the HAL Version of a specific service
9924 */
9925 @Override
9926 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009927 Phone phone = getDefaultPhone();
9928 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009929 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009930 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9931 return hv.major * 100 + hv.minor;
9932 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009933
9934 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009935 * Get the current calling package name.
9936 * @return the current calling package name
9937 */
9938 @Override
9939 public String getCurrentPackageName() {
9940 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9941 }
9942
9943 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009944 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9945 * corresponding network requests on a subId.
9946 *
9947 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009948 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009949 * 2) APN is un-metered for this subscription, or
9950 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009951 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009952 *
9953 * @return whether data is allowed for a apn type.
9954 *
9955 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009956 */
9957 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009958 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009959 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9960 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009961
9962 // Now that all security checks passes, perform the operation as ourselves.
9963 final long identity = Binder.clearCallingIdentity();
9964 try {
9965 Phone phone = getPhone(subId);
9966 if (phone == null) return false;
9967
Jack Yu27422a52022-03-21 10:38:05 -07009968 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009969 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009970 isMetered = phone.getDataNetworkController().getDataConfigManager()
9971 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9972 phone.getServiceState().getDataRoaming());
9973 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009974 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009975 } finally {
9976 Binder.restoreCallingIdentity(identity);
9977 }
9978 }
9979
9980 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009981 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009982 enforceReadPrivilegedPermission("isApnMetered");
9983
9984 // Now that all security checks passes, perform the operation as ourselves.
9985 final long identity = Binder.clearCallingIdentity();
9986 try {
9987 Phone phone = getPhone(subId);
9988 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009989 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9990 DataUtils.apnTypeToNetworkCapability(apnType),
9991 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009992 } finally {
9993 Binder.restoreCallingIdentity(identity);
9994 }
9995 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009996
9997 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009998 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9999 int subscriptionId, IBooleanConsumer resultCallback) {
10000 enforceModifyPermission();
10001 long token = Binder.clearCallingIdentity();
10002 try {
10003 Phone phone = getPhone(subscriptionId);
10004 if (phone == null) {
10005 try {
10006 if (resultCallback != null) {
10007 resultCallback.accept(false);
10008 }
10009 } catch (RemoteException e) {
10010 // ignore
10011 }
10012 return;
10013 }
10014 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10015 Pair.create(specifiers, (x) -> {
10016 try {
10017 if (resultCallback != null) {
10018 resultCallback.accept(x);
10019 }
10020 } catch (RemoteException e) {
10021 // ignore
10022 }
10023 });
10024 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10025 } finally {
10026 Binder.restoreCallingIdentity(token);
10027 }
10028 }
10029
10030 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010031 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10032 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010033 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010034 mApp, subId, "getSystemSelectionChannels");
10035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10036 final long identity = Binder.clearCallingIdentity();
10037 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010038 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10039 if (result instanceof IllegalStateException) {
10040 throw (IllegalStateException) result;
10041 }
10042 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010043 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10044 return specifiers;
10045 } finally {
10046 Binder.restoreCallingIdentity(identity);
10047 }
10048 }
10049
10050 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010051 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010052 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010053 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010054 }
10055
10056 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010057 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10058 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010059 if (callingPackage == null) {
10060 callingPackage = getCurrentPackageName();
10061 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010062 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10063 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010064 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10065 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010066 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10067 }
10068 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10069 Intent intent = new Intent();
10070 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10071 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10072 // Bring up choose default SMS subscription dialog right now
10073 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10074 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10075 mApp.startActivity(intent);
10076 }
chen xud5ca2d52019-05-28 15:20:57 -070010077
10078 @Override
10079 public String getMmsUAProfUrl(int subId) {
10080 //TODO investigate if this API should require proper permission check in R b/133791609
10081 final long identity = Binder.clearCallingIdentity();
10082 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010083 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10084 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10085 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10086 return carrierUAProfUrl;
10087 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010088 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10089 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010090 } finally {
10091 Binder.restoreCallingIdentity(identity);
10092 }
10093 }
10094
10095 @Override
10096 public String getMmsUserAgent(int subId) {
10097 //TODO investigate if this API should require proper permission check in R b/133791609
10098 final long identity = Binder.clearCallingIdentity();
10099 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010100 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10101 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10102 if (!TextUtils.isEmpty(carrierUserAgent)) {
10103 return carrierUserAgent;
10104 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010105 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10106 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010107 } finally {
10108 Binder.restoreCallingIdentity(identity);
10109 }
10110 }
Jack Yub07d4972019-05-28 16:12:25 -070010111
10112 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010113 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10114 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010115
Jack Yub07d4972019-05-28 16:12:25 -070010116 final long identity = Binder.clearCallingIdentity();
10117 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010118 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010119 if (phone == null) return false;
10120
Ling Maf188d502022-09-16 15:22:36 -070010121 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010122 } finally {
10123 Binder.restoreCallingIdentity(identity);
10124 }
10125 }
10126
10127 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010128 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010129 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010130 enforceModifyPermission();
10131
changbettyd5c246e2019-12-24 15:40:37 +080010132 final long identity = Binder.clearCallingIdentity();
10133 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010134 Phone phone = getPhone(subscriptionId);
10135 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010136
Ling Maf188d502022-09-16 15:22:36 -070010137 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010138 } finally {
10139 Binder.restoreCallingIdentity(identity);
10140 }
10141 }
10142
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010143 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010144 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010145 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10146 * otherwise.
10147 */
10148 @Override
10149 public void setCepEnabled(boolean isCepEnabled) {
10150 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10151
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
10154 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10155 for (Phone phone : PhoneFactory.getPhones()) {
10156 Phone defaultPhone = phone.getImsPhone();
10157 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10158 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10159 ImsPhoneCallTracker imsPhoneCallTracker =
10160 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10161 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10162 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10163 + imsPhone.getMsisdn());
10164 }
10165 }
10166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
allenwtsu46dcc572020-01-08 18:24:03 +080010170
10171 /**
10172 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10173 *
10174 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10175 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10176 * before being read.
10177 */
10178 @Override
10179 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10180 isCompressed) {
10181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10182 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010183 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10184 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10185 }
10186 if (!isImsAvailableOnDevice()) {
10187 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10188 "IMS not available on device.");
10189 }
10190
10191 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010192 try {
Hui Wang761a6682020-10-31 05:12:53 +000010193 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10194 } finally {
10195 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010196 }
10197 }
zoey chene02881a2019-12-30 16:11:23 +080010198
10199 @Override
10200 public boolean isIccLockEnabled(int subId) {
10201 enforceReadPrivilegedPermission("isIccLockEnabled");
10202
10203 // Now that all security checks passes, perform the operation as ourselves.
10204 final long identity = Binder.clearCallingIdentity();
10205 try {
10206 Phone phone = getPhone(subId);
10207 if (phone != null && phone.getIccCard() != null) {
10208 return phone.getIccCard().getIccLockEnabled();
10209 } else {
10210 return false;
10211 }
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 /**
10218 * Set the ICC pin lock enabled or disabled.
10219 *
10220 * @return an integer representing the status of IccLock enabled or disabled in the following
10221 * three cases:
10222 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10223 * successfully.
10224 * - Positive number and zero for remaining password attempts.
10225 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10226 *
10227 */
10228 @Override
10229 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10230 enforceModifyPermission();
10231
10232 Phone phone = getPhone(subId);
10233 if (phone == null) {
10234 return 0;
10235 }
10236 // Now that all security checks passes, perform the operation as ourselves.
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10240 new Pair<Boolean, String>(enabled, password), phone, null);
10241 return attemptsRemaining;
10242
10243 } catch (Exception e) {
10244 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10245 } finally {
10246 Binder.restoreCallingIdentity(identity);
10247 }
10248 return 0;
10249 }
10250
10251 /**
10252 * Change the ICC password used in ICC pin lock.
10253 *
10254 * @return an integer representing the status of IccLock changed in the following three cases:
10255 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10256 * - Positive number and zero for remaining password attempts.
10257 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10258 *
10259 */
10260 @Override
10261 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10262 enforceModifyPermission();
10263
10264 Phone phone = getPhone(subId);
10265 if (phone == null) {
10266 return 0;
10267 }
10268 // Now that all security checks passes, perform the operation as ourselves.
10269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10272 new Pair<String, String>(oldPassword, newPassword), phone, null);
10273 return attemptsRemaining;
10274
10275 } catch (Exception e) {
10276 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280 return 0;
10281 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010282
10283 /**
10284 * Request for receiving user activity notification
10285 */
10286 @Override
10287 public void requestUserActivityNotification() {
10288 if (!mNotifyUserActivity.get()
10289 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10290 mNotifyUserActivity.set(true);
10291 }
10292 }
10293
10294 /**
10295 * Called when userActivity is signalled in the power manager.
10296 * This is safe to call from any thread, with any window manager locks held or not.
10297 */
10298 @Override
10299 public void userActivity() {
10300 // ***************************************
10301 // * Inherited from PhoneWindowManager *
10302 // ***************************************
10303 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10304 // WITH ITS LOCKS HELD.
10305 //
10306 // This code must be VERY careful about the locks
10307 // it acquires.
10308 // In fact, the current code acquires way too many,
10309 // and probably has lurking deadlocks.
10310
10311 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10312 throw new SecurityException("Only the OS may call notifyUserActivity()");
10313 }
10314
10315 if (mNotifyUserActivity.getAndSet(false)) {
10316 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10317 USER_ACTIVITY_NOTIFICATION_DELAY);
10318 }
10319 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010320
10321 @Override
10322 public boolean canConnectTo5GInDsdsMode() {
10323 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10324 }
Jack Yud10cdd42020-09-28 20:28:01 -070010325
10326 @Override
10327 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10328 String callingFeatureId) {
10329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10330 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10331 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10332 }
10333
10334 Phone phone = getPhone(subId);
10335 if (phone == null) {
10336 throw new RuntimeException("phone is not available");
10337 }
10338 // Now that all security checks passes, perform the operation as ourselves.
10339 final long identity = Binder.clearCallingIdentity();
10340 try {
10341 return phone.getEquivalentHomePlmns();
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
Daniel Bright59e67312020-11-13 11:49:37 -080010346
10347 @Override
10348 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010349 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10350 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010351 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010352 if (radioInterfaceCapabilities == null) {
10353 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010354 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010355 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010356 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010357
Hui Wang641e81c2020-10-12 12:14:23 -070010358 @Override
10359 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10360 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010361 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10362 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10363 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10364 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10365 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010366 if (DBG) {
10367 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10368 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10369 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10370 }
10371
10372 if (!SubscriptionManager.isValidSubscriptionId(subId)
10373 || appType < TelephonyManager.APPTYPE_UNKNOWN
10374 || appType > TelephonyManager.APPTYPE_ISIM
10375 || nafUrl == null || securityProtocol == null || callback == null) {
10376 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10377 if (callback != null) {
10378 try {
10379 callback.onAuthenticationFailure(
10380 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10381 } catch (RemoteException exception) {
10382 log("Fail to notify onAuthenticationFailure due to " + exception);
10383 }
10384 return;
10385 }
10386 }
10387
10388 final long token = Binder.clearCallingIdentity();
10389 try {
10390 getGbaManager(subId).bootstrapAuthenticationRequest(
10391 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10392 forceBootStrapping, callback));
10393 } finally {
10394 Binder.restoreCallingIdentity(token);
10395 }
10396 }
10397
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010398 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010399 * Attempts to set the radio power state for all phones for thermal reason.
10400 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010401 * requested radio power state will actually be set. See {@link
10402 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10403 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010404 * @param enable {@code true} if trying to turn radio on.
10405 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10406 * false}.
10407 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010408 private boolean setRadioPowerForThermal(boolean enable) {
10409 boolean isPhoneAvailable = false;
10410 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10411 Phone phone = PhoneFactory.getPhone(i);
10412 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010413 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010414 isPhoneAvailable = true;
10415 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010416 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010417
10418 // return true if successfully informed the phone object about the thermal radio power
10419 // request.
10420 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010421 }
10422
10423 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010424 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010425 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10426 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10427 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10428 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10429 throw new IllegalArgumentException("modem does not support data throttling");
10430 }
10431
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010432 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10433 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010434 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010435 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10436 }
10437
Sarah Chinecc78c42022-03-31 21:16:48 -070010438 setDataEnabledForReason(
10439 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010440
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010441 if (isDataThrottlingSupported) {
10442 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010443 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010444 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10445 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10446 } else if (thermalMitigationResult
10447 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010448 log("Modem likely does not support data throttling on secondary carrier. Data " +
10449 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10450 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010451 }
10452 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010453 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010454
10455 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010456 }
10457
Jack Nudelman644b91a2021-03-12 14:09:48 -080010458 private static List<String> getThermalMitigationAllowlist(Context context) {
10459 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10460 for (String pckg : context.getResources()
10461 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10462 sThermalMitigationAllowlistedPackages.add(pckg);
10463 }
10464 }
10465
10466 return sThermalMitigationAllowlistedPackages;
10467 }
10468
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010469 private boolean isAnyPhoneInEmergencyState() {
10470 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10471 if (tm.isInEmergencyCall()) {
10472 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10473 return true;
10474 }
10475 for (Phone phone : PhoneFactory.getPhones()) {
10476 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10477 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10478 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10479 + phone.isInEcm());
10480 return true;
10481 }
10482 }
10483
10484 return false;
10485 }
10486
Jack Nudelman644b91a2021-03-12 14:09:48 -080010487 /**
10488 * Used by shell commands to add an authorized package name for thermal mitigation.
10489 * @param packageName name of package to be allowlisted
10490 * @param context
10491 */
10492 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10493 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10494 sThermalMitigationAllowlistedPackages.add(packageName);
10495 }
10496
10497 /**
10498 * Used by shell commands to remove an authorized package name for thermal mitigation.
10499 * @param packageName name of package to remove from allowlist
10500 * @param context
10501 */
10502 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10503 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10504 sThermalMitigationAllowlistedPackages.remove(packageName);
10505 }
10506
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010507 /**
10508 * Thermal mitigation request to control functionalities at modem.
10509 *
10510 * @param subId the id of the subscription.
10511 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010512 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010513 *
10514 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10515 */
10516 @Override
10517 @ThermalMitigationResult
10518 public int sendThermalMitigationRequest(
10519 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010520 ThermalMitigationRequest thermalMitigationRequest,
10521 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010522 enforceModifyPermission();
10523
Jack Nudelman644b91a2021-03-12 14:09:48 -080010524 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10525 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10526 .contains(callingPackage)) {
10527 throw new SecurityException("Calling package must be configured in the device config. "
10528 + "calling package: " + callingPackage);
10529 }
10530
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10532 final long identity = Binder.clearCallingIdentity();
10533
10534 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10535 try {
10536 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10537 switch (thermalMitigationAction) {
10538 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10539 thermalMitigationResult =
10540 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010541 thermalMitigationRequest.getDataThrottlingRequest(),
10542 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010543 break;
10544 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10545 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10546 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10547 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10548 }
10549
10550 // Ensure that radio is on. If not able to power on due to phone being
10551 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010552 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010553 thermalMitigationResult =
10554 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10555 break;
10556 }
10557
10558 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010559 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010560 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10561 break;
10562 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10563 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10564 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10565 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10566 }
10567
10568 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10569 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010570 Phone phone = getPhone(subId);
10571 if (phone == null) {
10572 thermalMitigationResult =
10573 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10574 break;
10575 }
10576
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010577 TelephonyConnectionService service =
10578 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010579 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010580 Log.e(LOG_TAG, "An emergency call is pending");
10581 thermalMitigationResult =
10582 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10583 break;
10584 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010585 thermalMitigationResult =
10586 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10587 break;
10588 }
10589 } else {
10590 thermalMitigationResult =
10591 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10592 break;
10593 }
10594
10595 // Turn radio off. If not able to power off due to phone being unavailable,
10596 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010597 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010598 thermalMitigationResult =
10599 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10600 break;
10601 }
10602 thermalMitigationResult =
10603 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10604 break;
10605 default:
10606 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10607 + "not exist. Requested action: " + thermalMitigationAction);
10608 }
10609 } catch (IllegalArgumentException e) {
10610 throw e;
10611 } catch (Exception e) {
10612 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10613 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10614 } finally {
10615 Binder.restoreCallingIdentity(identity);
10616 }
10617
10618 if (DBG) {
10619 log("thermalMitigationRequest returning with thermalMitigationResult: "
10620 + thermalMitigationResult);
10621 }
10622
10623 return thermalMitigationResult;
10624 }
Hui Wang641e81c2020-10-12 12:14:23 -070010625
10626 /**
10627 * Set the GbaService Package Name that Telephony will bind to.
10628 *
10629 * @param subId The sim that the GbaService is associated with.
10630 * @param packageName The name of the package to be replaced with.
10631 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10632 */
10633 @Override
10634 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10635 enforceModifyPermission();
10636
10637 final long identity = Binder.clearCallingIdentity();
10638 try {
10639 return getGbaManager(subId).overrideServicePackage(packageName);
10640 } finally {
10641 Binder.restoreCallingIdentity(identity);
10642 }
10643 }
10644
10645 /**
10646 * Return the package name of the currently bound GbaService.
10647 *
10648 * @param subId The sim that the GbaService is associated with.
10649 * @return the package name of the GbaService configuration, null if GBA is not supported.
10650 */
10651 @Override
10652 public String getBoundGbaService(int subId) {
10653 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10654
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 return getGbaManager(subId).getServicePackage();
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
10663 /**
10664 * Set the release time for telephony to unbind GbaService.
10665 *
10666 * @param subId The sim that the GbaService is associated with.
10667 * @param interval The release time to unbind GbaService by millisecond.
10668 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10669 */
10670 @Override
10671 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10672 enforceModifyPermission();
10673
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
10676 return getGbaManager(subId).overrideReleaseTime(interval);
10677 } finally {
10678 Binder.restoreCallingIdentity(identity);
10679 }
10680 }
10681
10682 /**
10683 * Return the release time for telephony to unbind GbaService.
10684 *
10685 * @param subId The sim that the GbaService is associated with.
10686 * @return The release time to unbind GbaService by millisecond.
10687 */
10688 @Override
10689 public int getGbaReleaseTime(int subId) {
10690 enforceReadPrivilegedPermission("getGbaReleaseTime");
10691
10692 final long identity = Binder.clearCallingIdentity();
10693 try {
10694 return getGbaManager(subId).getReleaseTime();
10695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
10699
10700 private GbaManager getGbaManager(int subId) {
10701 GbaManager instance = GbaManager.getInstance(subId);
10702 if (instance == null) {
10703 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10704 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10705 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10706 }
10707 return instance;
10708 }
Hui Wang761a6682020-10-31 05:12:53 +000010709
10710 /**
10711 * indicate whether the device and the carrier can support
10712 * RCS VoLTE single registration.
10713 */
10714 @Override
10715 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010716 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10717 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10718 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10719 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010720
10721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10722 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10723 }
10724
10725 final long identity = Binder.clearCallingIdentity();
10726 try {
10727 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10728 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010729 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10730 if (isCapable != null) {
10731 return isCapable;
10732 }
Hui Wang761a6682020-10-31 05:12:53 +000010733 }
Hui Wang67af90e2021-06-04 16:57:15 -070010734 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10735 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010736 } finally {
10737 Binder.restoreCallingIdentity(identity);
10738 }
10739 }
10740
10741 /**
10742 * Register RCS provisioning callback.
10743 */
10744 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010745 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010746 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010747 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010748 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010749 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10750 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010751
10752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10753 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10754 }
10755 if (!isImsAvailableOnDevice()) {
10756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10757 "IMS not available on device.");
10758 }
10759
10760 final long identity = Binder.clearCallingIdentity();
10761 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010762 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010763 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010764 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10765 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010766 }
Hui Wang761a6682020-10-31 05:12:53 +000010767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
10772 /**
10773 * Unregister RCS provisioning callback.
10774 */
10775 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010776 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010777 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010778 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010779 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010780 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10781 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010782
10783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10785 }
10786 if (!isImsAvailableOnDevice()) {
10787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10788 "IMS not available on device.");
10789 }
10790
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010793 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010794 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010795 } finally {
10796 Binder.restoreCallingIdentity(identity);
10797 }
10798 }
10799
10800 /**
10801 * trigger RCS reconfiguration.
10802 */
10803 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010804 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10805 "triggerRcsReconfiguration",
10806 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010807
10808 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10809 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10810 }
10811 if (!isImsAvailableOnDevice()) {
10812 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10813 "IMS not available on device.");
10814 }
10815
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10819 } finally {
10820 Binder.restoreCallingIdentity(identity);
10821 }
10822 }
10823
10824 /**
10825 * Provide the client configuration parameters of the RCS application.
10826 */
10827 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010828 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10829 "setRcsClientConfiguration",
10830 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010831
10832 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10833 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10834 }
10835 if (!isImsAvailableOnDevice()) {
10836 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10837 "IMS not available on device.");
10838 }
10839
10840 final long identity = Binder.clearCallingIdentity();
10841
10842 try {
10843 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10844 if (configBinder == null) {
10845 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010846 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10847 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010848 } else {
10849 configBinder.setRcsClientConfiguration(rcc);
10850 }
joonhunshin3e154242021-09-17 06:33:39 +000010851
10852 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10853 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010854 } catch (RemoteException e) {
10855 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010856 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10857 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010858 } finally {
10859 Binder.restoreCallingIdentity(identity);
10860 }
10861 }
10862
10863 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010864 * Enables or disables the test mode for RCS VoLTE single registration.
10865 */
10866 @Override
10867 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10868 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10869 "setRcsSingleRegistrationTestModeEnabled");
10870
10871 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10872 }
10873
10874 /**
10875 * Gets the test mode for RCS VoLTE single registration.
10876 */
10877 @Override
10878 public boolean getRcsSingleRegistrationTestModeEnabled() {
10879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10880 "getRcsSingleRegistrationTestModeEnabled");
10881
10882 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10883 }
10884
10885 /**
Hui Wang761a6682020-10-31 05:12:53 +000010886 * Overrides the config of RCS VoLTE single registration enabled for the device.
10887 */
10888 @Override
10889 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10890 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10891 "setDeviceSingleRegistrationEnabledOverride");
10892 enforceModifyPermission();
10893
10894 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10895 : Boolean.parseBoolean(enabledStr);
10896 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010897 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010898 }
10899
10900 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010901 * Sends a device to device communication message. Only usable via shell.
10902 * @param message message to send.
10903 * @param value message value.
10904 */
10905 @Override
10906 public void sendDeviceToDeviceMessage(int message, int value) {
10907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010908 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010909 enforceModifyPermission();
10910
10911 final long identity = Binder.clearCallingIdentity();
10912 try {
10913 TelephonyConnectionService service =
10914 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10915 if (service == null) {
10916 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10917 return;
10918 }
10919 service.sendTestDeviceToDeviceMessage(message, value);
10920 } finally {
10921 Binder.restoreCallingIdentity(identity);
10922 }
10923 }
10924
Tyler Gunnbabbda02021-02-10 11:05:02 -080010925 /**
10926 * Sets the specified device to device transport active.
10927 * @param transport The transport to set active.
10928 */
10929 @Override
10930 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10932 "setActiveDeviceToDeviceTransport");
10933 enforceModifyPermission();
10934
10935 final long identity = Binder.clearCallingIdentity();
10936 try {
10937 TelephonyConnectionService service =
10938 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10939 if (service == null) {
10940 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10941 return;
10942 }
10943 service.setActiveDeviceToDeviceTransport(transport);
10944 } finally {
10945 Binder.restoreCallingIdentity(identity);
10946 }
10947 }
Tyler Gunn92479152021-01-20 16:30:10 -080010948
Tyler Gunnd4339262021-05-03 14:46:49 -070010949 @Override
10950 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10952 "setDeviceToDeviceForceEnabled");
10953
10954 final long identity = Binder.clearCallingIdentity();
10955 try {
10956 Arrays.stream(PhoneFactory.getPhones()).forEach(
10957 p -> {
10958 Phone thePhone = p.getImsPhone();
10959 if (thePhone != null && thePhone instanceof ImsPhone) {
10960 ImsPhone imsPhone = (ImsPhone) thePhone;
10961 CallTracker tracker = imsPhone.getCallTracker();
10962 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10963 ImsPhoneCallTracker imsPhoneCallTracker =
10964 (ImsPhoneCallTracker) tracker;
10965 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10966 }
10967 }
10968 }
10969 );
10970 } finally {
10971 Binder.restoreCallingIdentity(identity);
10972 }
10973 }
10974
Tyler Gunn92479152021-01-20 16:30:10 -080010975 /**
Hui Wang761a6682020-10-31 05:12:53 +000010976 * Gets the config of RCS VoLTE single registration enabled for the device.
10977 */
10978 @Override
10979 public boolean getDeviceSingleRegistrationEnabled() {
10980 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10981 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10982 }
10983
10984 /**
10985 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10986 */
10987 @Override
10988 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10990 "setCarrierSingleRegistrationEnabledOverride");
10991 enforceModifyPermission();
10992
10993 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10994 : Boolean.parseBoolean(enabledStr);
10995 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10996 subId, enabled);
10997 }
10998
10999 /**
11000 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11001 */
11002 @Override
11003 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11004 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11005 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11006 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011007
11008 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011009 * Overrides the ims feature validation result
11010 */
11011 @Override
11012 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11014 "setImsFeatureValidationOverride");
11015
11016 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11017 : Boolean.parseBoolean(enabledStr);
11018 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11019 subId, enabled);
11020 }
11021
11022 /**
11023 * Gets the ims feature validation override value
11024 */
11025 @Override
11026 public boolean getImsFeatureValidationOverride(int subId) {
11027 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11028 "getImsFeatureValidationOverride");
11029 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11030 }
11031
11032 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011033 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11034 * their mobile plan.
11035 */
11036 @Override
11037 public String getMobileProvisioningUrl() {
11038 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11039 final long identity = Binder.clearCallingIdentity();
11040 try {
11041 return getDefaultPhone().getMobileProvisioningUrl();
11042 } finally {
11043 Binder.restoreCallingIdentity(identity);
11044 }
11045 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011046
James.cf Linbcdf8b32021-01-14 16:44:13 +080011047 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011048 * Get the EAB contact from the EAB database.
11049 */
11050 @Override
11051 public String getContactFromEab(String contact) {
11052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11053 enforceModifyPermission();
11054 final long identity = Binder.clearCallingIdentity();
11055 try {
11056 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11057 } finally {
11058 Binder.restoreCallingIdentity(identity);
11059 }
11060 }
11061
11062 /**
Calvin Pana1434322021-07-01 19:27:01 +080011063 * Get the EAB capability from the EAB database.
11064 */
11065 @Override
11066 public String getCapabilityFromEab(String contact) {
11067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11068 enforceModifyPermission();
11069 final long identity = Binder.clearCallingIdentity();
11070 try {
11071 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11072 } finally {
11073 Binder.restoreCallingIdentity(identity);
11074 }
11075 }
11076
11077 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011078 * Remove the EAB contacts from the EAB database.
11079 */
11080 @Override
11081 public int removeContactFromEab(int subId, String contacts) {
11082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11083 enforceModifyPermission();
11084 final long identity = Binder.clearCallingIdentity();
11085 try {
11086 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11087 } finally {
11088 Binder.restoreCallingIdentity(identity);
11089 }
11090 }
11091
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011092 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011093 public boolean getDeviceUceEnabled() {
11094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11095 final long identity = Binder.clearCallingIdentity();
11096 try {
11097 return mApp.getDeviceUceEnabled();
11098 } finally {
11099 Binder.restoreCallingIdentity(identity);
11100 }
11101 }
11102
11103 @Override
11104 public void setDeviceUceEnabled(boolean isEnabled) {
11105 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11106 final long identity = Binder.clearCallingIdentity();
11107 try {
11108 mApp.setDeviceUceEnabled(isEnabled);
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
11113
Brad Ebinger14d467f2021-02-12 06:18:28 +000011114 /**
11115 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11116 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11117 */
11118 // Used for SHELL command only right now.
11119 @Override
11120 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11121 List<String> featureTags) {
11122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11123 "addUceRegistrationOverrideShell");
11124 final long identity = Binder.clearCallingIdentity();
11125 try {
11126 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11127 new ArraySet<>(featureTags));
11128 } catch (ImsException e) {
11129 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
11134
11135 /**
11136 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11137 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11138 */
11139 // Used for SHELL command only right now.
11140 @Override
11141 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11142 List<String> featureTags) {
11143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11144 "removeUceRegistrationOverrideShell");
11145 final long identity = Binder.clearCallingIdentity();
11146 try {
11147 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11148 new ArraySet<>(featureTags));
11149 } catch (ImsException e) {
11150 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11151 } finally {
11152 Binder.restoreCallingIdentity(identity);
11153 }
11154 }
11155
11156 /**
11157 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11158 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11159 */
11160 // Used for SHELL command only right now.
11161 @Override
11162 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11163 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11164 "clearUceRegistrationOverrideShell");
11165 final long identity = Binder.clearCallingIdentity();
11166 try {
11167 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11168 } catch (ImsException e) {
11169 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11170 } finally {
11171 Binder.restoreCallingIdentity(identity);
11172 }
11173 }
11174
11175 /**
11176 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11177 */
11178 // Used for SHELL command only right now.
11179 @Override
11180 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11182 "getLatestRcsContactUceCapabilityShell");
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11186 } catch (ImsException e) {
11187 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11188 } finally {
11189 Binder.restoreCallingIdentity(identity);
11190 }
11191 }
11192
11193 /**
11194 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11195 * device does not have an active PUBLISH.
11196 */
11197 // Used for SHELL command only right now.
11198 @Override
11199 public String getLastUcePidfXmlShell(int subId) {
11200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11201 final long identity = Binder.clearCallingIdentity();
11202 try {
11203 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11204 } catch (ImsException e) {
11205 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11206 } finally {
11207 Binder.restoreCallingIdentity(identity);
11208 }
11209 }
11210
James.cf Line8713a42021-04-29 16:04:26 +080011211 /**
11212 * Remove UCE requests cannot be sent to the network status.
11213 */
11214 // Used for SHELL command only right now.
11215 @Override
11216 public boolean removeUceRequestDisallowedStatus(int subId) {
11217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11218 final long identity = Binder.clearCallingIdentity();
11219 try {
11220 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11221 } catch (ImsException e) {
11222 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11223 } finally {
11224 Binder.restoreCallingIdentity(identity);
11225 }
11226 }
11227
James.cf Lin18bb9002021-05-25 01:37:38 +080011228 /**
11229 * Remove UCE requests cannot be sent to the network status.
11230 */
11231 // Used for SHELL command only.
11232 @Override
11233 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11234 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11235 final long identity = Binder.clearCallingIdentity();
11236 try {
11237 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11238 } catch (ImsException e) {
11239 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11240 } finally {
11241 Binder.restoreCallingIdentity(identity);
11242 }
11243 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011244
James.cf Lin4b784aa2021-01-31 03:25:15 +080011245 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011246 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11247 String callingPackage) {
11248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11249 mApp, subId, "setSignalStrengthUpdateRequest");
11250
11251 final int callingUid = Binder.getCallingUid();
11252 // Verify that tha callingPackage belongs to the calling UID
11253 mApp.getSystemService(AppOpsManager.class)
11254 .checkPackage(callingUid, callingPackage);
11255
Rambo Wang3607f502021-02-01 21:51:40 -080011256 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011257
11258 final long identity = Binder.clearCallingIdentity();
11259 try {
11260 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11261 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11262
11263 if (result instanceof IllegalStateException) {
11264 throw (IllegalStateException) result;
11265 }
11266 } finally {
11267 Binder.restoreCallingIdentity(identity);
11268 }
11269 }
11270
11271 @Override
11272 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11273 String callingPackage) {
11274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11275 mApp, subId, "clearSignalStrengthUpdateRequest");
11276
11277 final int callingUid = Binder.getCallingUid();
11278 // Verify that tha callingPackage belongs to the calling UID
11279 mApp.getSystemService(AppOpsManager.class)
11280 .checkPackage(callingUid, callingPackage);
11281
11282 final long identity = Binder.clearCallingIdentity();
11283 try {
11284 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11285 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11286
11287 if (result instanceof IllegalStateException) {
11288 throw (IllegalStateException) result;
11289 }
11290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 }
11294
Rambo Wang3607f502021-02-01 21:51:40 -080011295 private static void validateSignalStrengthUpdateRequest(Context context,
11296 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011297 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11298 // phone/system process do not have further restriction on request
11299 return;
11300 }
11301
11302 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011303 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011304 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011305 context.enforceCallingOrSelfPermission(
11306 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11307 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011308 }
11309
11310 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011311 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011312 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011313 || info.isEnabled()) {
11314 throw new IllegalArgumentException(
11315 "Only system can set hide fields in SignalThresholdInfo");
11316 }
11317
11318 // Thresholds length for each RAN need in range. This has been validated in
11319 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11320 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11321 final int[] thresholds = info.getThresholds();
11322 Objects.requireNonNull(thresholds);
11323 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11324 || thresholds.length
11325 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11326 throw new IllegalArgumentException(
11327 "thresholds length is out of range: " + thresholds.length);
11328 }
11329 }
11330 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011331
11332 /**
11333 * Gets the current phone capability.
11334 *
11335 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11336 * @return the PhoneCapability which describes the data connection capability of modem.
11337 * It's used to evaluate possible phone config change, for example from single
11338 * SIM device to multi-SIM device.
11339 */
11340 @Override
11341 public PhoneCapability getPhoneCapability() {
11342 enforceReadPrivilegedPermission("getPhoneCapability");
11343 final long identity = Binder.clearCallingIdentity();
11344 try {
11345 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11346 } finally {
11347 Binder.restoreCallingIdentity(identity);
11348 }
11349 }
Michele Berionne5e411512020-11-13 02:36:59 +000011350
11351 /**
11352 * Prepare TelephonyManager for an unattended reboot. The reboot is
11353 * required to be done shortly after the API is invoked.
11354 */
11355 @Override
11356 @TelephonyManager.PrepareUnattendedRebootResult
11357 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011358 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011359 enforceRebootPermission();
11360
11361 final long identity = Binder.clearCallingIdentity();
11362 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011363 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011364 } finally {
11365 Binder.restoreCallingIdentity(identity);
11366 }
11367 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011368
11369 /**
11370 * Request to get the current slicing configuration including URSP rules and
11371 * NSSAIs (configured, allowed and rejected).
11372 *
11373 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11374 */
11375 @Override
11376 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011377 TelephonyPermissions
11378 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11379 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011380
11381 final long identity = Binder.clearCallingIdentity();
11382 try {
11383 Phone phone = getDefaultPhone();
11384 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11385 } finally {
11386 Binder.restoreCallingIdentity(identity);
11387 }
11388 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011389
11390 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011391 * Check whether the given premium capability is available for purchase from the carrier.
11392 *
11393 * @param capability The premium capability to check.
11394 * @param subId The subId to check the premium capability for.
11395 *
11396 * @return Whether the given premium capability is available to purchase.
11397 */
11398 @Override
11399 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11400 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11401 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11402 log("Premium capability "
11403 + TelephonyManager.convertPremiumCapabilityToString(capability)
11404 + " is not available for purchase due to missing permissions.");
11405 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11406 + "permission READ_BASIC_PHONE_STATE.");
11407 }
11408
11409 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011410 if (phone == null) {
11411 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11412 return false;
11413 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011414 final long identity = Binder.clearCallingIdentity();
11415 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011416 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011417 .isPremiumCapabilityAvailableForPurchase(capability);
11418 } finally {
11419 Binder.restoreCallingIdentity(identity);
11420 }
11421 }
11422
11423 /**
11424 * Purchase the given premium capability from the carrier.
11425 *
11426 * @param capability The premium capability to purchase.
11427 * @param callback The result of the purchase request.
11428 * @param subId The subId to purchase the premium capability for.
11429 */
11430 @Override
11431 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11432 log("purchasePremiumCapability: capability="
11433 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11434 + getCurrentPackageName());
11435
11436 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11437 mApp, "purchasePremiumCapability")) {
11438 log("purchasePremiumCapability "
11439 + TelephonyManager.convertPremiumCapabilityToString(capability)
11440 + " failed due to missing permissions.");
11441 throw new SecurityException("purchasePremiumCapability requires permission "
11442 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011443 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11444 mApp, "purchasePremiumCapability")) {
11445 log("purchasePremiumCapability "
11446 + TelephonyManager.convertPremiumCapabilityToString(capability)
11447 + " failed due to missing permissions.");
11448 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011449 }
11450
11451 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011452 if (phone == null) {
11453 try {
11454 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11455 callback.accept(result);
11456 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11457 } catch (RemoteException e) {
11458 String logStr = "Purchase premium capability "
11459 + TelephonyManager.convertPremiumCapabilityToString(capability)
11460 + " failed due to RemoteException handling null phone: " + e;
11461 if (DBG) log(logStr);
11462 AnomalyReporter.reportAnomaly(
11463 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11464 }
11465 return;
11466 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011467
11468 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011469 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011470 callingProcess = mApp.getPackageManager().getApplicationInfo(
11471 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011472 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011473 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011474 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011475
11476 boolean isVisible = false;
11477 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11478 if (am != null) {
11479 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11480 if (processes != null) {
11481 for (ActivityManager.RunningAppProcessInfo process : processes) {
11482 log("purchasePremiumCapability: process " + process.processName
11483 + "has importance " + process.importance);
11484 if (process.processName.equals(callingProcess) && process.importance
11485 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11486 isVisible = true;
11487 break;
11488 }
11489 }
11490 }
11491 }
11492
11493 if (!isVisible) {
11494 try {
11495 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11496 callback.accept(result);
11497 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11498 } catch (RemoteException e) {
11499 String logStr = "Purchase premium capability "
11500 + TelephonyManager.convertPremiumCapabilityToString(capability)
11501 + " failed due to RemoteException handling background application: " + e;
11502 if (DBG) log(logStr);
11503 AnomalyReporter.reportAnomaly(
11504 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11505 }
11506 return;
11507 }
11508
Sarah Chin71b3a852022-09-28 15:54:19 -070011509 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chin532d6bb2022-12-28 22:50:43 -080011510 new PurchasePremiumCapabilityArgument(capability, callingProcess, callback), phone,
11511 null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011512 }
11513
11514 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011515 * Register an IMS connection state callback
11516 */
11517 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011518 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11519 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011520 if (feature == ImsFeature.FEATURE_MMTEL) {
11521 // ImsMmTelManager
11522 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11523 TelephonyPermissions
11524 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11525 mApp, subId, "registerImsStateCallback");
11526 } else if (feature == ImsFeature.FEATURE_RCS) {
11527 // ImsRcsManager or SipDelegateManager
11528 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11529 Binder.getCallingUid(), "registerImsStateCallback",
11530 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11531 Manifest.permission.READ_PRECISE_PHONE_STATE,
11532 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11533 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11534 }
11535
11536 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11537 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11538 "IMS not available on device.");
11539 }
11540
11541 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11542 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11543 }
11544
11545 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11546 if (controller == null) {
11547 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11548 "IMS not available on device.");
11549 }
11550
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011551 if (callingPackage == null) {
11552 callingPackage = getCurrentPackageName();
11553 }
11554
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011555 final long token = Binder.clearCallingIdentity();
11556 try {
11557 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011558 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011559 } catch (ImsException e) {
11560 throw new ServiceSpecificException(e.getCode());
11561 } finally {
11562 Binder.restoreCallingIdentity(token);
11563 }
11564 }
11565
11566 /**
11567 * Unregister an IMS connection state callback
11568 */
11569 @Override
11570 public void unregisterImsStateCallback(IImsStateCallback cb) {
11571 final long token = Binder.clearCallingIdentity();
11572 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11573 if (controller == null) {
11574 return;
11575 }
11576 try {
11577 controller.unregisterImsStateCallback(cb);
11578 } finally {
11579 Binder.restoreCallingIdentity(token);
11580 }
11581 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011582
11583 /**
11584 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11585 *
11586 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11587 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11588 * SecurityException.
11589 * If there is current registered network this value will be same as the registered cell
11590 * identity. If the device goes out of service the previous cell identity is cached and
11591 * will be returned. If the cache age of the Cell identity is more than 24 hours
11592 * it will be cleared and null will be returned.
11593 *
11594 */
11595 @Override
11596 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11597 String callingFeatureId) {
11598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11599 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11600 LocationAccessPolicy.checkLocationPermission(mApp,
11601 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11602 .setCallingPackage(callingPackage)
11603 .setCallingFeatureId(callingFeatureId)
11604 .setCallingPid(Binder.getCallingPid())
11605 .setCallingUid(Binder.getCallingUid())
11606 .setMethod("getLastKnownCellIdentity")
11607 .setLogAsInfo(true)
11608 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11609 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11610 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11611 .build());
11612
11613 boolean hasFinePermission =
11614 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11615 if (!hasFinePermission
11616 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11617 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011618 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011619 }
11620
11621 final long identity = Binder.clearCallingIdentity();
11622 try {
11623 Phone phone = getPhone(subId);
11624 if (phone == null) return null;
11625 ServiceStateTracker sst = phone.getServiceStateTracker();
11626 if (sst == null) return null;
11627 return sst.getLastKnownCellIdentity();
11628 } finally {
11629 Binder.restoreCallingIdentity(identity);
11630 }
11631 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011632
jimsun3b9ccac2021-10-26 15:01:23 +080011633 /**
11634 * Sets the modem service class Name that Telephony will bind to.
11635 *
11636 * @param serviceName The class name of the modem service.
11637 * @return true if the operation is succeed, otherwise false.
11638 */
11639 public boolean setModemService(String serviceName) {
11640 Log.d(LOG_TAG, "setModemService - " + serviceName);
11641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11643 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11644 "setModemService");
11645 return mPhoneConfigurationManager.setModemService(serviceName);
11646 }
11647
11648 /**
11649 * Return the class name of the currently bounded modem service.
11650 *
11651 * @return the class name of the modem service.
11652 */
11653 public String getModemService() {
11654 String result;
11655 Log.d(LOG_TAG, "getModemService");
11656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11657 TelephonyPermissions
11658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11659 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11660 "getModemService");
11661 result = mPhoneConfigurationManager.getModemService();
11662 Log.d(LOG_TAG, "result = " + result);
11663 return result;
11664 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011665
11666 @Override
11667 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11668 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11669 mApp.enforceCallingOrSelfPermission(
11670 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11671 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11672
11673 final long identity = Binder.clearCallingIdentity();
11674 try {
11675 Phone phone = getPhone(subId);
11676 if (phone == null) return;
11677 phone.setVoiceServiceStateOverride(hasService);
11678 } finally {
11679 Binder.restoreCallingIdentity(identity);
11680 }
11681 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011682
11683 /**
11684 * set removable eSIM as default eUICC.
11685 *
11686 * @hide
11687 */
11688 @Override
11689 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11690 enforceModifyPermission();
11691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11692
11693 final long identity = Binder.clearCallingIdentity();
11694 try {
11695 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11696 } finally {
11697 Binder.restoreCallingIdentity(identity);
11698 }
11699 }
11700
11701 /**
11702 * Returns whether the removable eSIM is default eUICC or not.
11703 *
11704 * @hide
11705 */
11706 @Override
11707 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11708 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11709 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11710
11711 final long identity = Binder.clearCallingIdentity();
11712 try {
11713 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11714 } finally {
11715 Binder.restoreCallingIdentity(identity);
11716 }
11717 }
11718
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011719 /**
11720 * Get the component name of the default app to direct respond-via-message intent for the
11721 * user associated with this subscription, update the cache if there is no respond-via-message
11722 * application currently configured for this user.
11723 * @return component name of the app and class to direct Respond Via Message intent to, or
11724 * {@code null} if the functionality is not supported.
11725 * @hide
11726 */
11727 @Override
11728 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11729 boolean updateIfNeeded) {
11730 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011731
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011732 Context context = getPhone(subId).getContext();
11733 UserHandle userHandle = null;
11734 final long identity = Binder.clearCallingIdentity();
11735 try {
11736 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11737 } finally {
11738 Binder.restoreCallingIdentity(identity);
11739 }
11740 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11741 updateIfNeeded, userHandle);
11742 }
Jack Yuf5badd92022-12-08 00:50:53 -080011743
11744 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011745 * Set whether the device is able to connect with null ciphering or integrity
11746 * algorithms. This is a global setting and will apply to all active subscriptions
11747 * and all new subscriptions after this.
11748 *
11749 * @param enabled when true, null cipher and integrity algorithms are allowed.
11750 * @hide
11751 */
11752 @Override
11753 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11754 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11755 enforceModifyPermission();
11756 checkForNullCipherAndIntegritySupport();
11757
11758 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11759 // for listening to these preference changes and applying them immediately.
11760 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11761 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11762 editor.apply();
11763
11764 for (Phone phone: PhoneFactory.getPhones()) {
11765 phone.handleNullCipherEnabledChange();
11766 }
11767 }
11768
11769
11770 /**
11771 * Get whether the device is able to connect with null ciphering or integrity
11772 * algorithms. Note that this retrieves the phone-global preference and not
11773 * the state of the radio.
11774 *
11775 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11776 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11777 * version for this feature.
11778 * @hide
11779 */
11780 @Override
11781 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11782 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11783 enforceReadPermission();
11784 checkForNullCipherAndIntegritySupport();
11785 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11786 }
11787
11788 private void checkForNullCipherAndIntegritySupport() {
11789 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11790 throw new UnsupportedOperationException(
11791 "Null cipher and integrity operations require HAL 2.1 or above");
11792 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011793 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11794 throw new UnsupportedOperationException(
11795 "Null cipher and integrity operations unsupported by modem");
11796 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011797 }
11798
11799 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011800 * Get the SIM state for the slot index.
11801 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11802 *
11803 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11804 */
11805 @Override
11806 @SimState
11807 public int getSimStateForSlotIndex(int slotIndex) {
11808 IccCardConstants.State simState;
11809 if (slotIndex < 0) {
11810 simState = IccCardConstants.State.UNKNOWN;
11811 } else {
11812 Phone phone = null;
11813 try {
11814 phone = PhoneFactory.getPhone(slotIndex);
11815 } catch (IllegalStateException e) {
11816 // ignore
11817 }
11818 if (phone == null) {
11819 simState = IccCardConstants.State.UNKNOWN;
11820 } else {
11821 IccCard icc = phone.getIccCard();
11822 if (icc == null) {
11823 simState = IccCardConstants.State.UNKNOWN;
11824 } else {
11825 simState = icc.getState();
11826 }
11827 }
11828 }
11829 return simState.ordinal();
11830 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011831
11832 /**
11833 * Get current cell broadcast ranges.
11834 */
11835 @Override
11836 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11837 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11838 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11839 "getCellBroadcastIdRanges");
11840 final long identity = Binder.clearCallingIdentity();
11841 try {
11842 return getPhone(subId).getCellBroadcastIdRanges();
11843 } finally {
11844 Binder.restoreCallingIdentity(identity);
11845 }
11846 }
11847
11848 /**
11849 * Set reception of cell broadcast messages with the list of the given ranges
11850 *
11851 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11852 */
11853 @Override
11854 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11855 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11856 @Nullable IIntegerConsumer callback) {
11857 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11858 "setCellBroadcastIdRanges");
11859 final long identity = Binder.clearCallingIdentity();
11860 try {
11861 Phone phone = getPhoneFromSubId(subId);
11862 if (DBG) {
11863 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11864 }
11865 phone.setCellBroadcastIdRanges(ranges, result -> {
11866 if (callback != null) {
11867 try {
11868 callback.accept(result);
11869 } catch (RemoteException e) {
11870 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
11871 }
11872 }
11873 });
11874 } finally {
11875 Binder.restoreCallingIdentity(identity);
11876 }
11877 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000011878
11879 /**
11880 * Returns whether the device supports the domain selection service.
11881 *
11882 * @return {@code true} if the device supports the domain selection service.
11883 */
11884 @Override
11885 public boolean isDomainSelectionSupported() {
11886 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11887 "isDomainSelectionSupported");
11888
11889 final long identity = Binder.clearCallingIdentity();
11890 try {
11891 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
11892 } finally {
11893 Binder.restoreCallingIdentity(identity);
11894 }
11895 }
arunvoddud5c6ce02022-12-11 06:03:12 +000011896
11897 /**
11898 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
11899 *
11900 * <p>This method behaves in one of the following ways:
11901 * <ul>
11902 * <li>return true : if the calling package has the appop permission {@link
11903 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
11904 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
11905 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
11906 * Owner device identifier access check, or the calling package has carrier privileges</>
11907 * <li>throw SecurityException: if the caller does not meet any of the requirements.
11908 * </ul>
11909 */
11910 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
11911 String callingPackage, @Nullable String callingFeatureId, String message) {
11912 for (Phone phone : PhoneFactory.getPhones()) {
11913 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
11914 phone.getSubId(), callingPackage, callingFeatureId, message)) {
11915 return true;
11916 }
11917 }
11918 return false;
11919 }
11920}