blob: 79bda6c829f92132079154f236a3d3438160ff30 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080035import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070036import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000037import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080038import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000039import android.compat.annotation.ChangeId;
40import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070041import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070042import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.content.Context;
44import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070045import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070046import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070047import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.net.Uri;
49import android.os.AsyncResult;
50import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080051import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Bundle;
53import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080055import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.Looper;
57import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070058import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080059import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070060import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070061import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080062import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080063import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070064import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070065import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080066import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070068import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070070import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070071import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080072import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070073import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000074import android.service.carrier.CarrierIdentifier;
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;
arunvoddud7401012022-12-15 16:08:12 +0000226import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700227import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800228import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700229import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700230import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800231import com.android.services.telephony.TelecomAccountRegistry;
232import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800233import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800234
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700236import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.io.IOException;
238import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700239import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800241import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000242import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800243import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800244import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800245import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800246import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100247import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800248import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700249import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800251import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700252import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800253import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800254import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800255import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256
257/**
258 * Implementation of the ITelephony interface.
259 */
Santos Cordon117fee72014-05-16 17:56:12 -0700260public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 private static final String LOG_TAG = "PhoneInterfaceManager";
262 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
263 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800264 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
266 // Message codes used with mMainThreadHandler
267 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700268 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
269 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700270 private static final int CMD_OPEN_CHANNEL = 9;
271 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
272 private static final int CMD_CLOSE_CHANNEL = 11;
273 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800274 private static final int CMD_NV_READ_ITEM = 13;
275 private static final int EVENT_NV_READ_ITEM_DONE = 14;
276 private static final int CMD_NV_WRITE_ITEM = 15;
277 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
278 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
279 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700280 private static final int CMD_RESET_MODEM_CONFIG = 19;
281 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800282 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
283 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800284 private static final int CMD_SEND_ENVELOPE = 25;
285 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000286 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
287 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700288 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
289 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
290 private static final int CMD_EXCHANGE_SIM_IO = 31;
291 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800292 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
293 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700294 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
295 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700296 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
297 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700298 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
299 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
300 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
301 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700302 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
303 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
304 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
305 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700306 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800307 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
308 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000309 private static final int CMD_SWITCH_SLOTS = 50;
310 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700311 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
312 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
313 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
314 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
315 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
316 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
317 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
318 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700319 private static final int CMD_GET_ALL_CELL_INFO = 60;
320 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
321 private static final int CMD_GET_CELL_LOCATION = 62;
322 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700323 private static final int CMD_MODEM_REBOOT = 64;
324 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700325 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
326 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800327 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
328 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700329 private static final int CMD_GET_MODEM_STATUS = 70;
330 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700331 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
332 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700333 private static final int CMD_ERASE_MODEM_CONFIG = 74;
334 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800335 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
336 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
337 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
338 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800339 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
340 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800341 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800342 private static final int CMD_GET_CALL_FORWARDING = 83;
343 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
344 private static final int CMD_SET_CALL_FORWARDING = 85;
345 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
346 private static final int CMD_GET_CALL_WAITING = 87;
347 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
348 private static final int CMD_SET_CALL_WAITING = 89;
349 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700350 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
351 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
352 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
353 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700354 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
355 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800356 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
357 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800358 private static final int CMD_SET_DATA_THROTTLING = 99;
359 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800360 private static final int CMD_SET_SIM_POWER = 101;
361 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800362 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
363 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
364 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
365 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800366 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
367 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000368 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800369 private static final int CMD_GET_SLICING_CONFIG = 110;
370 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800371 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700372 private static final int CMD_ENABLE_VONR = 113;
373 private static final int EVENT_ENABLE_VONR_DONE = 114;
374 private static final int CMD_IS_VONR_ENABLED = 115;
375 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700376 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
377 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
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;
Jack Yue37dd262022-12-16 11:53:37 -0800398 private final 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
Gary Jian76280a42022-12-07 16:18:33 +0800440 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
441
sandeepjsb6c87872021-09-27 15:34:44 +0000442 /**
443 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
444 * one ICCID active at the same time.
445 * Apps should use below API signatures if targeting SDK is T and beyond.
446 *
447 * @hide
448 */
449 @ChangeId
450 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
451 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800452
Naina Nallurid63128d2019-09-17 14:10:30 -0700453 /**
Chen Xu540470b2021-12-14 17:15:47 -0800454 * Apps targeting on Android T and beyond will get exception whenever icc close channel
455 * operation fails.
456 */
457 @ChangeId
458 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
459 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
460
461 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 * A request object to use for transmitting data to an ICC.
463 */
464 private static final class IccAPDUArgument {
465 public int channel, cla, command, p1, p2, p3;
466 public String data;
467
468 public IccAPDUArgument(int channel, int cla, int command,
469 int p1, int p2, int p3, String data) {
470 this.channel = channel;
471 this.cla = cla;
472 this.command = command;
473 this.p1 = p1;
474 this.p2 = p2;
475 this.p3 = p3;
476 this.data = data;
477 }
478 }
479
480 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700481 * A request object to use for transmitting data to an ICC.
482 */
483 private static final class ManualNetworkSelectionArgument {
484 public OperatorInfo operatorInfo;
485 public boolean persistSelection;
486
487 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
488 this.operatorInfo = operatorInfo;
489 this.persistSelection = persistSelection;
490 }
491 }
492
Sarah Chin71b3a852022-09-28 15:54:19 -0700493 private static final class PurchasePremiumCapabilityArgument {
494 public @TelephonyManager.PremiumCapability int capability;
495 public @NonNull String appName;
496 public @NonNull IIntegerConsumer callback;
497
498 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
499 @NonNull String appName, @NonNull IIntegerConsumer callback) {
500 this.capability = capability;
501 this.appName = appName;
502 this.callback = callback;
503 }
504 }
505
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700506 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
508 * request after sending. The main thread will notify the request when it is complete.
509 */
510 private static final class MainThreadRequest {
511 /** The argument to use for the request */
512 public Object argument;
513 /** The result of the request that is run on the main thread */
514 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800515 // The subscriber id that this request applies to. Defaults to
516 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
517 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518
Nathan Harold92bed182018-10-12 18:16:49 -0700519 // In cases where subId is unavailable, the caller needs to specify the phone.
520 public Phone phone;
521
vagdeviaf9a5b92018-08-15 16:01:53 -0700522 public WorkSource workSource;
523
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 public MainThreadRequest(Object argument) {
525 this.argument = argument;
526 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800527
Nathan Harold92bed182018-10-12 18:16:49 -0700528 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
529 this.argument = argument;
530 if (phone != null) {
531 this.phone = phone;
532 }
533 this.workSource = workSource;
534 }
535
vagdeviaf9a5b92018-08-15 16:01:53 -0700536 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800537 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800538 if (subId != null) {
539 this.subId = subId;
540 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700541 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 }
544
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800545 private static final class IncomingThirdPartyCallArgs {
546 public final ComponentName component;
547 public final String callId;
548 public final String callerDisplayName;
549
550 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
551 String callerDisplayName) {
552 this.component = component;
553 this.callId = callId;
554 this.callerDisplayName = callerDisplayName;
555 }
556 }
557
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700558 /**
559 * A handler that processes messages on the main thread in the phone process. Since many
560 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
561 * inbound binder threads to the main thread in the phone process. The Binder thread
562 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
563 * on, which will be notified when the operation completes and will contain the result of the
564 * request.
565 *
566 * <p>If a MainThreadRequest object is provided in the msg.obj field,
567 * note that request.result must be set to something non-null for the calling thread to
568 * unblock.
569 */
570 private final class MainThreadHandler extends Handler {
571 @Override
572 public void handleMessage(Message msg) {
573 MainThreadRequest request;
574 Message onCompleted;
575 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000576 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800578 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579
580 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 case CMD_HANDLE_USSD_REQUEST: {
582 request = (MainThreadRequest) msg.obj;
583 final Phone phone = getPhoneFromRequest(request);
584 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800585 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700587
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 if (!isUssdApiAllowed(request.subId)) {
589 // Carrier does not support use of this API, return failure.
590 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
591 UssdResponse response = new UssdResponse(ussdRequest, null);
592 Bundle returnData = new Bundle();
593 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
594 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700595
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 request.result = true;
597 notifyRequester(request);
598 return;
599 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700600
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 try {
602 request.result = phone != null
603 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
604 } catch (CallStateException cse) {
605 request.result = false;
606 }
607 // Wake up the requesting thread
608 notifyRequester(request);
609 break;
pkanwar32d516d2016-10-14 19:37:38 -0700610 }
611
Yorke Lee716f67e2015-06-17 15:39:16 -0700612 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700614 final Phone phone = getPhoneFromRequest(request);
615 request.result = phone != null ?
616 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
617 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000626 uiccPort = getUiccPortFromRequest(request);
627 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800629 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800635 iccArgument.channel, iccArgument.cla, iccArgument.command,
636 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
637 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 break;
640
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
646 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 if (ar.result == null) {
649 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800650 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800652 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 } else {
654 loge("iccTransmitApduLogicalChannel: Unknown exception");
655 }
656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 break;
659
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
661 request = (MainThreadRequest) msg.obj;
662 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000663 uiccPort = getUiccPortFromRequest(request);
664 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800670 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000671 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800672 iccArgument.cla, iccArgument.command, iccArgument.p1,
673 iccArgument.p2,
674 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 }
676 break;
677
678 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
681 if (ar.exception == null && ar.result != null) {
682 request.result = ar.result;
683 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800684 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 if (ar.result == null) {
686 loge("iccTransmitApduBasicChannel: Empty response");
687 } else if (ar.exception instanceof CommandException) {
688 loge("iccTransmitApduBasicChannel: CommandException: " +
689 ar.exception);
690 } else {
691 loge("iccTransmitApduBasicChannel: Unknown exception");
692 }
693 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 break;
696
697 case CMD_EXCHANGE_SIM_IO:
698 request = (MainThreadRequest) msg.obj;
699 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000700 uiccPort = getUiccPortFromRequest(request);
701 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800703 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 } else {
706 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
707 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000708 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
710 iccArgument.data, onCompleted);
711 }
712 break;
713
714 case EVENT_EXCHANGE_SIM_IO_DONE:
715 ar = (AsyncResult) msg.obj;
716 request = (MainThreadRequest) ar.userObj;
717 if (ar.exception == null && ar.result != null) {
718 request.result = ar.result;
719 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800720 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 break;
724
Derek Tan4d5e5c12014-02-04 11:54:58 -0800725 case CMD_SEND_ENVELOPE:
726 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000727 uiccPort = getUiccPortFromRequest(request);
728 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800730 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 } else {
733 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800734 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700735 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800736 break;
737
738 case EVENT_SEND_ENVELOPE_DONE:
739 ar = (AsyncResult) msg.obj;
740 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700741 if (ar.exception == null && ar.result != null) {
742 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800743 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800744 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700745 if (ar.result == null) {
746 loge("sendEnvelopeWithStatus: Empty response");
747 } else if (ar.exception instanceof CommandException) {
748 loge("sendEnvelopeWithStatus: CommandException: " +
749 ar.exception);
750 } else {
751 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
752 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800753 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700754 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800755 break;
756
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 case CMD_OPEN_CHANNEL:
758 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000759 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800760 IccLogicalChannelRequest openChannelRequest =
761 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000762 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700763 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800764 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800765 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 } else {
768 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800769 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
770 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 break;
773
774 case EVENT_OPEN_CHANNEL_DONE:
775 ar = (AsyncResult) msg.obj;
776 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700777 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700779 int[] result = (int[]) ar.result;
780 int channelId = result[0];
781 byte[] selectResponse = null;
782 if (result.length > 1) {
783 selectResponse = new byte[result.length - 1];
784 for (int i = 1; i < result.length; ++i) {
785 selectResponse[i - 1] = (byte) result[i];
786 }
787 }
788 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800789 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800790
791 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700792 if (uiccPort == null) {
793 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
794 } else {
795 IccLogicalChannelRequest channelRequest =
796 (IccLogicalChannelRequest) request.argument;
797 channelRequest.channel = channelId;
798 uiccPort.onLogicalChannelOpened(channelRequest);
799 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 if (ar.result == null) {
802 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700804 if (ar.exception != null) {
805 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
806 }
807
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700808 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700809 if (ar.exception instanceof CommandException) {
810 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800811 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700812 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700813 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700814 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700815 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 }
817 }
818 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800819 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700820 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700821 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700822 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700823 break;
824
825 case CMD_CLOSE_CHANNEL:
826 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000827 uiccPort = getUiccPortFromRequest(request);
828 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700829 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800830 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800831 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800832 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700833 } else {
834 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000835 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700836 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 break;
838
839 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null) {
843 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800844 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700845 if (uiccPort == null) {
846 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
847 } else {
848 final int channelId = (Integer) request.argument;
849 uiccPort.onLogicalChannelClosed(channelId);
850 }
Chen Xu540470b2021-12-14 17:15:47 -0800851 } else {
852 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800853 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800854 if (ar.exception instanceof CommandException) {
855 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
856 CommandException.Error error =
857 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800858 if (error == CommandException.Error.INVALID_ARGUMENTS) {
859 // should only throw exceptions from the binder threads.
860 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800861 "iccCloseLogicalChannel: invalid argument ");
862 }
863 } else {
864 loge("iccCloseLogicalChannel: Unknown exception");
865 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800866 request.result = (exception != null) ? exception :
867 new IllegalStateException(
868 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800869 }
870 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800871 break;
872
873 case CMD_NV_READ_ITEM:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
877 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800878 break;
879
880 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700885 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800886 request.result = "";
887 if (ar.result == null) {
888 loge("nvReadItem: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("nvReadItem: CommandException: " +
891 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700892 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800893 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700894 }
895 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700896 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 break;
898
Jake Hambye994d462014-02-03 13:10:13 -0800899 case CMD_NV_WRITE_ITEM:
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
902 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800903 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700904 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800905 break;
906
907 case EVENT_NV_WRITE_ITEM_DONE:
908 handleNullReturnEvent(msg, "nvWriteItem");
909 break;
910
911 case CMD_NV_WRITE_CDMA_PRL:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800915 break;
916
917 case EVENT_NV_WRITE_CDMA_PRL_DONE:
918 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
919 break;
920
chen xu6dac5ab2018-10-26 17:39:23 -0700921 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800922 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700923 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800924 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800925 break;
926
chen xu6dac5ab2018-10-26 17:39:23 -0700927 case EVENT_RESET_MODEM_CONFIG_DONE:
928 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800929 break;
930
Sooraj Sasindran37444802020-08-11 10:40:43 -0700931 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
932 request = (MainThreadRequest) msg.obj;
933 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
934 request);
935 Phone phone = getPhoneFromRequest(request);
936 if (phone != null) {
937 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
938 } else {
939 loge("isNRDualConnectivityEnabled: No phone object");
940 request.result = false;
941 notifyRequester(request);
942 }
943 break;
944 }
945
946 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
949 if (ar.exception == null && ar.result != null) {
950 request.result = ar.result;
951 } else {
952 // request.result must be set to something non-null
953 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700954 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700955 request.result = ar.result;
956 } else {
957 request.result = false;
958 }
959 if (ar.result == null) {
960 loge("isNRDualConnectivityEnabled: Empty response");
961 } else if (ar.exception instanceof CommandException) {
962 loge("isNRDualConnectivityEnabled: CommandException: "
963 + ar.exception);
964 } else {
965 loge("isNRDualConnectivityEnabled: Unknown exception");
966 }
967 }
968 notifyRequester(request);
969 break;
970
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700971 case CMD_IS_VONR_ENABLED: {
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
974 request);
975 Phone phone = getPhoneFromRequest(request);
976 if (phone != null) {
977 phone.isVoNrEnabled(onCompleted, request.workSource);
978 } else {
979 loge("isVoNrEnabled: No phone object");
980 request.result = false;
981 notifyRequester(request);
982 }
983 break;
984 }
985
986 case EVENT_IS_VONR_ENABLED_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 if (ar.exception == null && ar.result != null) {
990 request.result = ar.result;
991 } else {
992 // request.result must be set to something non-null
993 // for the calling thread to unblock
994 if (ar.result != null) {
995 request.result = ar.result;
996 } else {
997 request.result = false;
998 }
999 if (ar.result == null) {
1000 loge("isVoNrEnabled: Empty response");
1001 } else if (ar.exception instanceof CommandException) {
1002 loge("isVoNrEnabled: CommandException: "
1003 + ar.exception);
1004 } else {
1005 loge("isVoNrEnabled: Unknown exception");
1006 }
1007 }
1008 notifyRequester(request);
1009 break;
1010
Sooraj Sasindran37444802020-08-11 10:40:43 -07001011 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1014 Phone phone = getPhoneFromRequest(request);
1015 if (phone != null) {
1016 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1017 request.workSource);
1018 } else {
1019 loge("enableNrDualConnectivity: No phone object");
1020 request.result =
1021 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1022 notifyRequester(request);
1023 }
1024 break;
1025 }
1026
1027 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception == null) {
1031 request.result =
1032 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1033 } else {
1034 request.result =
1035 TelephonyManager
1036 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1037 if (ar.exception instanceof CommandException) {
1038 CommandException.Error error =
1039 ((CommandException) (ar.exception)).getCommandError();
1040 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1041 request.result =
1042 TelephonyManager
1043 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001044 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1045 request.result =
1046 TelephonyManager
1047 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001048 }
1049 loge("enableNrDualConnectivity" + ": CommandException: "
1050 + ar.exception);
1051 } else {
1052 loge("enableNrDualConnectivity" + ": Unknown exception");
1053 }
1054 }
1055 notifyRequester(request);
1056 break;
1057 }
1058
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001059 case CMD_ENABLE_VONR: {
1060 request = (MainThreadRequest) msg.obj;
1061 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1062 Phone phone = getPhoneFromRequest(request);
1063 if (phone != null) {
1064 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1065 request.workSource);
1066 } else {
1067 loge("setVoNrEnabled: No phone object");
1068 request.result =
1069 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1070 notifyRequester(request);
1071 }
1072 break;
1073 }
1074
1075 case EVENT_ENABLE_VONR_DONE: {
1076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
1078 if (ar.exception == null) {
1079 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1080 } else {
1081 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1082 if (ar.exception instanceof CommandException) {
1083 CommandException.Error error =
1084 ((CommandException) (ar.exception)).getCommandError();
1085 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1086 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1087 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1088 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1089 } else {
1090 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1091 }
1092 loge("setVoNrEnabled" + ": CommandException: "
1093 + ar.exception);
1094 } else {
1095 loge("setVoNrEnabled" + ": Unknown exception");
1096 }
1097 }
1098 notifyRequester(request);
1099 break;
1100 }
1101
SongFerngWang3ef3e072020-12-21 16:41:52 +08001102 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1105 request);
1106 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 break;
1108
SongFerngWang3ef3e072020-12-21 16:41:52 +08001109 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null && ar.result != null) {
1113 request.result = ar.result; // Integer
1114 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301115 // request.result must be set to something non-null
1116 // for the calling thread to unblock
1117 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001118 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 loge("getAllowedNetworkTypesBitmask: CommandException: "
1122 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001124 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001125 }
1126 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001127 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 break;
1129
SongFerngWang3ef3e072020-12-21 16:41:52 +08001130 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001132 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1133 request);
1134 Pair<Integer, Long> reasonWithNetworkTypes =
1135 (Pair<Integer, Long>) request.argument;
1136 getPhoneFromRequest(request).setAllowedNetworkTypes(
1137 reasonWithNetworkTypes.first,
1138 reasonWithNetworkTypes.second,
1139 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1143 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 break;
1145
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001146 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1147 request = (MainThreadRequest)msg.obj;
1148 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001149 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001150 break;
1151
1152 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1153 ar = (AsyncResult)msg.obj;
1154 request = (MainThreadRequest)ar.userObj;
1155 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001156 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001157 break;
1158
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001159 case CMD_SET_VOICEMAIL_NUMBER:
1160 request = (MainThreadRequest) msg.obj;
1161 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1162 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001163 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1164 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001165 break;
1166
1167 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1168 handleNullReturnEvent(msg, "setVoicemailNumber");
1169 break;
1170
Stuart Scott54788802015-03-30 13:18:01 -07001171 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1174 request);
1175 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1176 break;
1177
1178 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1179 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1180 break;
1181
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 case CMD_PERFORM_NETWORK_SCAN:
1183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1185 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1186 break;
1187
Hall Liu27d24262020-09-18 19:04:59 -07001188 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001189 request = (MainThreadRequest) msg.obj;
1190 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001191 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1192 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1193 request.argument;
1194 int callForwardingReason = args.first;
1195 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001196 break;
Hall Liu27d24262020-09-18 19:04:59 -07001197 }
1198 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001199 ar = (AsyncResult) msg.obj;
1200 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001201 TelephonyManager.CallForwardingInfoCallback callback =
1202 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1203 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001205 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1207 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1208 // Service Class is a bit mask per 3gpp 27.007. Search for
1209 // any service for voice call.
1210 if ((callForwardInfo.serviceClass
1211 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001212 callForwardingInfo = new CallForwardingInfo(
1213 callForwardInfo.status
1214 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001215 callForwardInfo.reason,
1216 callForwardInfo.number,
1217 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001218 break;
1219 }
1220 }
1221 // Didn't find a call forward info for voice call.
1222 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001223 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1224 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 }
Hall Liu27d24262020-09-18 19:04:59 -07001226 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001227 } else {
1228 if (ar.result == null) {
1229 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1230 }
1231 if (ar.exception != null) {
1232 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1233 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001234 int errorCode = TelephonyManager
1235 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager
1241 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001242 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 errorCode = TelephonyManager
1244 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001245 }
1246 }
Hall Liu27d24262020-09-18 19:04:59 -07001247 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 }
Shuo Qian4a594052020-01-23 11:59:30 -08001249 break;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
Shuo Qian4a594052020-01-23 11:59:30 -08001251
Hall Liu27d24262020-09-18 19:04:59 -07001252 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001253 request = (MainThreadRequest) msg.obj;
1254 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001255 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001257 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1258 request.argument).first;
1259 request.phone.setCallForwardingOption(
1260 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001261 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001262 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001263 callForwardingInfoToSet.getReason(),
1264 callForwardingInfoToSet.getNumber(),
1265 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1266 break;
Hall Liu27d24262020-09-18 19:04:59 -07001267 }
Shuo Qian4a594052020-01-23 11:59:30 -08001268
Hall Liu27d24262020-09-18 19:04:59 -07001269 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001272 Consumer<Integer> callback =
1273 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1274 request.argument).second;
1275 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001276 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001277 int errorCode = TelephonyManager.CallForwardingInfoCallback
1278 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001279 if (ar.exception instanceof CommandException) {
1280 CommandException.Error error =
1281 ((CommandException) (ar.exception)).getCommandError();
1282 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001283 errorCode = TelephonyManager.CallForwardingInfoCallback
1284 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001285 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001286 errorCode = TelephonyManager.CallForwardingInfoCallback
1287 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001288 }
1289 }
1290 callback.accept(errorCode);
1291 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001292 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294 break;
Hall Liu27d24262020-09-18 19:04:59 -07001295 }
Shuo Qian4a594052020-01-23 11:59:30 -08001296
Hall Liu27d24262020-09-18 19:04:59 -07001297 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001298 request = (MainThreadRequest) msg.obj;
1299 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1300 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1301 break;
Hall Liu27d24262020-09-18 19:04:59 -07001302 }
Shuo Qian4a594052020-01-23 11:59:30 -08001303
Hall Liu27d24262020-09-18 19:04:59 -07001304 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001307 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001308 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001309 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001310 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001311 // Service Class is a bit mask per 3gpp 27.007.
1312 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001313 if (callForwardResults.length > 1
1314 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001315 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001317 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1318 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001319 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 }
1322 } else {
1323 if (ar.result == null) {
1324 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1325 }
1326 if (ar.exception != null) {
1327 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1328 }
1329 if (ar.exception instanceof CommandException) {
1330 CommandException.Error error =
1331 ((CommandException) (ar.exception)).getCommandError();
1332 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001334 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001335 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1336 callWaitingStatus =
1337 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001338 }
1339 }
1340 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001342 break;
Hall Liu27d24262020-09-18 19:04:59 -07001343 }
Shuo Qian4a594052020-01-23 11:59:30 -08001344
Hall Liu27d24262020-09-18 19:04:59 -07001345 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001346 request = (MainThreadRequest) msg.obj;
1347 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001348 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1349 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001350 break;
Hall Liu27d24262020-09-18 19:04:59 -07001351 }
Shuo Qian4a594052020-01-23 11:59:30 -08001352
Hall Liu27d24262020-09-18 19:04:59 -07001353 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001356 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1357 Consumer<Integer> callback =
1358 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1359 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001360 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001361 if (ar.exception instanceof CommandException) {
1362 CommandException.Error error =
1363 ((CommandException) (ar.exception)).getCommandError();
1364 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1365 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001366 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1367 callback.accept(
1368 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001369 } else {
1370 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1371 }
1372 } else {
1373 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1374 }
1375 } else {
1376 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1377 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001378 }
Shuo Qian4a594052020-01-23 11:59:30 -08001379 break;
Hall Liu27d24262020-09-18 19:04:59 -07001380 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001381 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1382 ar = (AsyncResult) msg.obj;
1383 request = (MainThreadRequest) ar.userObj;
1384 CellNetworkScanResult cellScanResult;
1385 if (ar.exception == null && ar.result != null) {
1386 cellScanResult = new CellNetworkScanResult(
1387 CellNetworkScanResult.STATUS_SUCCESS,
1388 (List<OperatorInfo>) ar.result);
1389 } else {
1390 if (ar.result == null) {
1391 loge("getCellNetworkScanResults: Empty response");
1392 }
1393 if (ar.exception != null) {
1394 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1395 }
1396 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1397 if (ar.exception instanceof CommandException) {
1398 CommandException.Error error =
1399 ((CommandException) (ar.exception)).getCommandError();
1400 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1401 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1402 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1403 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1404 }
1405 }
1406 cellScanResult = new CellNetworkScanResult(errorCode, null);
1407 }
1408 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001409 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001410 break;
1411
1412 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1413 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001414 ManualNetworkSelectionArgument selArg =
1415 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1417 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001418 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1419 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 break;
1421
1422 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001423 ar = (AsyncResult) msg.obj;
1424 request = (MainThreadRequest) ar.userObj;
1425 if (ar.exception == null) {
1426 request.result = true;
1427 } else {
1428 request.result = false;
1429 loge("setNetworkSelectionModeManual " + ar.exception);
1430 }
1431 notifyRequester(request);
1432 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001433 break;
1434
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 case CMD_GET_MODEM_ACTIVITY_INFO:
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001438 if (defaultPhone != null) {
1439 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001440 } else {
1441 ResultReceiver result = (ResultReceiver) request.argument;
1442 Bundle bundle = new Bundle();
1443 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001444 new ModemActivityInfo(0, 0, 0,
1445 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001446 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001447 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 break;
1449
Hall Liud0f208c2020-10-14 16:54:44 -07001450 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001454 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001455 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 if (mLastModemActivityInfo == null) {
1457 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1458 mLastModemActivitySpecificInfo[0] =
1459 new ActivityStatsTechSpecificInfo(
1460 0,
1461 0,
1462 new int[ModemActivityInfo.getNumTxPowerLevels()],
1463 0);
1464 mLastModemActivityInfo =
1465 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1466 }
1467
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001469 // Update the last modem activity info and the result of the request.
1470 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1471 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001472 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001473 } else {
1474 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001475 }
Kai Shi917fdc62022-11-28 14:01:02 -08001476 // This is needed to decouple ret from mLastModemActivityInfo
1477 // We don't want to return mLastModemActivityInfo which is updated
1478 // inside mergeModemActivityInfo()
1479 ret = new ModemActivityInfo(
1480 mLastModemActivityInfo.getTimestampMillis(),
1481 mLastModemActivityInfo.getSleepTimeMillis(),
1482 mLastModemActivityInfo.getIdleTimeMillis(),
1483 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001484
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001485 } else {
1486 if (ar.result == null) {
1487 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001488 error = TelephonyManager.ModemActivityInfoException
1489 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001491 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001492 error = TelephonyManager.ModemActivityInfoException
1493 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494 } else {
1495 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001496 error = TelephonyManager.ModemActivityInfoException
1497 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001498 }
1499 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001500 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001501 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001502 bundle.putParcelable(
1503 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001504 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001505 } else {
1506 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1507 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001508 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001509 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001511 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001512
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 case CMD_SET_ALLOWED_CARRIERS:
1514 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001515 CarrierRestrictionRules argument =
1516 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001518 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 break;
1520
1521 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1522 ar = (AsyncResult) msg.obj;
1523 request = (MainThreadRequest) ar.userObj;
1524 if (ar.exception == null && ar.result != null) {
1525 request.result = ar.result;
1526 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001527 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1528 if (ar.exception instanceof CommandException) {
1529 loge("setAllowedCarriers: CommandException: " + ar.exception);
1530 CommandException.Error error =
1531 ((CommandException) (ar.exception)).getCommandError();
1532 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1533 request.result =
1534 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1535 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 } else {
1537 loge("setAllowedCarriers: Unknown exception");
1538 }
1539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541 break;
1542
1543 case CMD_GET_ALLOWED_CARRIERS:
1544 request = (MainThreadRequest) msg.obj;
1545 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001546 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 break;
1548
1549 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception == null && ar.result != null) {
1553 request.result = ar.result;
1554 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001555 request.result = new IllegalStateException(
1556 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001557 if (ar.result == null) {
1558 loge("getAllowedCarriers: Empty response");
1559 } else if (ar.exception instanceof CommandException) {
1560 loge("getAllowedCarriers: CommandException: " +
1561 ar.exception);
1562 } else {
1563 loge("getAllowedCarriers: Unknown exception");
1564 }
1565 }
arunvoddud7401012022-12-15 16:08:12 +00001566 if (request.argument != null) {
1567 // This is for the implementation of carrierRestrictionStatus.
1568 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1569 Consumer<Integer> callback = callbackInfo.getConsumer();
1570 int callerCarrierId = callbackInfo.getCarrierId();
1571 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1572 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1573 CarrierRestrictionRules carrierRestrictionRules =
1574 (CarrierRestrictionRules) ar.result;
1575 int carrierId = -1;
1576 try {
1577 CarrierIdentifier carrierIdentifier =
1578 carrierRestrictionRules.getAllowedCarriers().get(0);
1579 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1580 carrierIdentifier);
1581 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1582 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1583 }
1584 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1585 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1586 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
1587 lockStatus =
1588 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
1589 }
1590 } else {
1591 Rlog.e(LOG_TAG,
1592 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1593 }
1594 callback.accept(lockStatus);
1595 } else {
1596 // This is for the implementation of getAllowedCarriers.
1597 notifyRequester(request);
1598 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001599 break;
1600
Nathan Haroldb3014052017-01-25 15:57:32 -08001601 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 if (ar.exception == null && ar.result != null) {
1605 request.result = ar.result;
1606 } else {
1607 request.result = new IllegalArgumentException(
1608 "Failed to retrieve Forbidden Plmns");
1609 if (ar.result == null) {
1610 loge("getForbiddenPlmns: Empty response");
1611 } else {
1612 loge("getForbiddenPlmns: Unknown exception");
1613 }
1614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001615 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001616 break;
1617
1618 case CMD_GET_FORBIDDEN_PLMNS:
1619 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001620 uiccPort = getUiccPortFromRequest(request);
1621 if (uiccPort == null) {
1622 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001623 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001624 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001625 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001626 break;
1627 }
1628 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001629 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 if (uiccApp == null) {
1631 loge("getForbiddenPlmns() no app with specified type -- "
1632 + appType);
1633 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001635 break;
1636 } else {
1637 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1638 + " specified type -- " + appType);
1639 }
1640 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1641 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1642 onCompleted);
1643 break;
1644
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001645 case CMD_SWITCH_SLOTS:
1646 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001647 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001648 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001649 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001650 break;
1651
1652 case EVENT_SWITCH_SLOTS_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
1655 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001656 notifyRequester(request);
1657 break;
1658 case CMD_GET_NETWORK_SELECTION_MODE:
1659 request = (MainThreadRequest) msg.obj;
1660 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1661 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1662 break;
1663
1664 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
1667 if (ar.exception != null) {
1668 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1669 } else {
1670 int mode = ((int[]) ar.result)[0];
1671 if (mode == 0) {
1672 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1673 } else {
1674 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1675 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001677 notifyRequester(request);
1678 break;
1679 case CMD_GET_CDMA_ROAMING_MODE:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1682 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1683 break;
1684 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 if (ar.exception != null) {
1688 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1689 } else {
1690 request.result = ((int[]) ar.result)[0];
1691 }
1692 notifyRequester(request);
1693 break;
1694 case CMD_SET_CDMA_ROAMING_MODE:
1695 request = (MainThreadRequest) msg.obj;
1696 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1697 int mode = (int) request.argument;
1698 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1699 break;
1700 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 request.result = ar.exception == null;
1704 notifyRequester(request);
1705 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001706 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1709 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1710 break;
1711 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 if (ar.exception != null) {
1715 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1716 } else {
1717 request.result = ((int[]) ar.result)[0];
1718 }
1719 notifyRequester(request);
1720 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001721 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1724 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001725 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1726 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001727 break;
1728 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = ar.exception == null;
1732 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001733 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001734 case CMD_GET_ALL_CELL_INFO:
1735 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001737 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 case EVENT_GET_ALL_CELL_INFO_DONE:
1740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001742 // If a timeout occurs, the response will be null
1743 request.result = (ar.exception == null && ar.result != null)
1744 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 synchronized (request) {
1746 request.notifyAll();
1747 }
1748 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001749 case CMD_REQUEST_CELL_INFO_UPDATE:
1750 request = (MainThreadRequest) msg.obj;
1751 request.phone.requestCellInfoUpdate(request.workSource,
1752 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1753 break;
1754 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1758 try {
1759 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001760 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001761 cb.onError(
1762 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1763 ar.exception.getClass().getName(),
1764 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001765 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001766 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001767 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001768 } else {
1769 // use the result as returned
1770 cb.onCellInfo((List<CellInfo>) ar.result);
1771 }
1772 } catch (RemoteException re) {
1773 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1774 }
1775 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001776 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001777 request = (MainThreadRequest) msg.obj;
1778 WorkSource ws = (WorkSource) request.argument;
1779 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001780 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001781 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001782 }
1783 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 if (ar.exception == null) {
1787 request.result = ar.result;
1788 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001789 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001791 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001792 }
1793
1794 synchronized (request) {
1795 request.notifyAll();
1796 }
1797 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001798 }
chen xu6dac5ab2018-10-26 17:39:23 -07001799 case CMD_MODEM_REBOOT:
1800 request = (MainThreadRequest) msg.obj;
1801 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001802 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001803 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001804 case EVENT_CMD_MODEM_REBOOT_DONE:
1805 handleNullReturnEvent(msg, "rebootModem");
1806 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001807 case CMD_REQUEST_ENABLE_MODEM:
1808 request = (MainThreadRequest) msg.obj;
1809 boolean enable = (boolean) request.argument;
1810 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001811 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001812 PhoneConfigurationManager.getInstance()
1813 .enablePhone(request.phone, enable, onCompleted);
1814 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001815 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001816 ar = (AsyncResult) msg.obj;
1817 request = (MainThreadRequest) ar.userObj;
1818 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001819 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001820 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001821 if ((boolean) request.result) {
1822 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1823 updateModemStateMetrics();
1824 } else {
1825 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1826 + ar.exception);
1827 }
1828 notifyRequester(request);
1829 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001830 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001831 case CMD_GET_MODEM_STATUS:
1832 request = (MainThreadRequest) msg.obj;
1833 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1834 PhoneConfigurationManager.getInstance()
1835 .getPhoneStatusFromModem(request.phone, onCompleted);
1836 break;
1837 case EVENT_GET_MODEM_STATUS_DONE:
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 int id = request.phone.getPhoneId();
1841 if (ar.exception == null && ar.result != null) {
1842 request.result = ar.result;
1843 //update the cache as modem status has changed
1844 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1845 (boolean) request.result);
1846 } else {
1847 // Return true if modem status cannot be retrieved. For most cases,
1848 // modem status is on. And for older version modems, GET_MODEM_STATUS
1849 // and disable modem are not supported. Modem is always on.
1850 // TODO: this should be fixed in R to support a third
1851 // status UNKNOWN b/131631629
1852 request.result = true;
1853 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1854 + ar.exception);
1855 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001856 notifyRequester(request);
1857 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001858 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1859 request = (MainThreadRequest) msg.obj;
1860 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1861 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1862 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1863 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1864 break;
1865 }
1866 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1870 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1871 args.second.accept(ar.exception == null);
1872 notifyRequester(request);
1873 break;
1874 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001875 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1876 request = (MainThreadRequest) msg.obj;
1877 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1878 Phone phone = getPhoneFromRequest(request);
1879 if (phone != null) {
1880 phone.getSystemSelectionChannels(onCompleted);
1881 } else {
1882 loge("getSystemSelectionChannels: No phone object");
1883 request.result = new ArrayList<RadioAccessSpecifier>();
1884 notifyRequester(request);
1885 }
1886 break;
1887 }
1888 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891 if (ar.exception == null && ar.result != null) {
1892 request.result = ar.result;
1893 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001894 request.result = new IllegalStateException(
1895 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001896 if (ar.result == null) {
1897 loge("getSystemSelectionChannels: Empty response");
1898 } else {
1899 loge("getSystemSelectionChannels: Unknown exception");
1900 }
1901 }
1902 notifyRequester(request);
1903 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001904 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1905 ar = (AsyncResult) msg.obj;
1906 request = (MainThreadRequest) ar.userObj;
1907 if (ar.exception == null && ar.result != null) {
1908 request.result = ar.result;
1909 } else {
1910 request.result = -1;
1911 loge("Failed to set Forbidden Plmns");
1912 if (ar.result == null) {
1913 loge("setForbidenPlmns: Empty response");
1914 } else if (ar.exception != null) {
1915 loge("setForbiddenPlmns: Exception: " + ar.exception);
1916 request.result = -1;
1917 } else {
1918 loge("setForbiddenPlmns: Unknown exception");
1919 }
1920 }
1921 notifyRequester(request);
1922 break;
1923 case CMD_SET_FORBIDDEN_PLMNS:
1924 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001925 uiccPort = getUiccPortFromRequest(request);
1926 if (uiccPort == null) {
1927 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001928 request.result = -1;
1929 notifyRequester(request);
1930 break;
1931 }
1932 Pair<Integer, List<String>> setFplmnsArgs =
1933 (Pair<Integer, List<String>>) request.argument;
1934 appType = setFplmnsArgs.first;
1935 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001936 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001937 if (uiccApp == null) {
1938 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1939 request.result = -1;
1940 loge("Failed to get UICC App");
1941 notifyRequester(request);
1942 } else {
1943 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1944 ((SIMRecords) uiccApp.getIccRecords())
1945 .setForbiddenPlmns(onCompleted, fplmns);
1946 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001947 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001948 case CMD_ERASE_MODEM_CONFIG:
1949 request = (MainThreadRequest) msg.obj;
1950 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1951 defaultPhone.eraseModemConfig(onCompleted);
1952 break;
1953 case EVENT_ERASE_MODEM_CONFIG_DONE:
1954 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001955 break;
zoey chene02881a2019-12-30 16:11:23 +08001956
Kai Shif70f46f2021-03-03 13:59:46 -08001957 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1958 request = (MainThreadRequest) msg.obj;
1959 request.result = defaultPhone.eraseDataInSharedPreferences();
1960 notifyRequester(request);
1961 break;
1962
zoey chene02881a2019-12-30 16:11:23 +08001963 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1964 request = (MainThreadRequest) msg.obj;
1965 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1966 Pair<String, String> changed = (Pair<String, String>) request.argument;
1967 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1968 changed.first, changed.second, onCompleted);
1969 break;
1970 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1971 ar = (AsyncResult) msg.obj;
1972 request = (MainThreadRequest) ar.userObj;
1973 if (ar.exception == null) {
1974 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001975 // If the operation is successful, update the PIN storage
1976 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1977 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001978 UiccController.getInstance().getPinStorage()
1979 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001980 } else {
1981 request.result = msg.arg1;
1982 }
1983 notifyRequester(request);
1984 break;
1985
Michele Berionne5e411512020-11-13 02:36:59 +00001986 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001987 request = (MainThreadRequest) msg.obj;
1988 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1989 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1990 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1991 enabled.first, enabled.second, onCompleted);
1992 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001993 }
zoey chene02881a2019-12-30 16:11:23 +08001994 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1995 ar = (AsyncResult) msg.obj;
1996 request = (MainThreadRequest) ar.userObj;
1997 if (ar.exception == null) {
1998 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001999 // If the operation is successful, update the PIN storage
2000 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2001 int phoneId = getPhoneFromRequest(request).getPhoneId();
2002 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002003 UiccController.getInstance().getPinStorage()
2004 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002005 } else {
2006 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2007 }
zoey chene02881a2019-12-30 16:11:23 +08002008 } else {
2009 request.result = msg.arg1;
2010 }
Michele Berionne5e411512020-11-13 02:36:59 +00002011
2012
zoey chene02881a2019-12-30 16:11:23 +08002013 notifyRequester(request);
2014 break;
2015
Peter Wangdafb9ac2020-01-15 14:13:38 -08002016 case MSG_NOTIFY_USER_ACTIVITY:
2017 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002018 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002019 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2020 getDefaultPhone().getContext().sendBroadcastAsUser(
2021 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2022 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002023
2024 case CMD_SET_DATA_THROTTLING: {
2025 request = (MainThreadRequest) msg.obj;
2026 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2027 DataThrottlingRequest dataThrottlingRequest =
2028 (DataThrottlingRequest) request.argument;
2029 Phone phone = getPhoneFromRequest(request);
2030 if (phone != null) {
2031 phone.setDataThrottling(onCompleted,
2032 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2033 dataThrottlingRequest.getCompletionDurationMillis());
2034 } else {
2035 loge("setDataThrottling: No phone object");
2036 request.result =
2037 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2038 notifyRequester(request);
2039 }
2040
2041 break;
2042 }
2043 case EVENT_SET_DATA_THROTTLING_DONE:
2044 ar = (AsyncResult) msg.obj;
2045 request = (MainThreadRequest) ar.userObj;
2046
2047 if (ar.exception == null) {
2048 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2049 } else if (ar.exception instanceof CommandException) {
2050 loge("setDataThrottling: CommandException: " + ar.exception);
2051 CommandException.Error error =
2052 ((CommandException) (ar.exception)).getCommandError();
2053
2054 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2055 request.result = TelephonyManager
2056 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2057 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2058 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002059 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2060 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002061 } else {
2062 request.result =
2063 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2064 }
2065 } else {
2066 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2067 }
2068 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2069 notifyRequester(request);
2070 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002071
2072 case CMD_SET_SIM_POWER: {
2073 request = (MainThreadRequest) msg.obj;
2074 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2075 request = (MainThreadRequest) msg.obj;
2076 int stateToSet =
2077 ((Pair<Integer, IIntegerConsumer>)
2078 request.argument).first;
2079 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2080 break;
2081 }
2082 case EVENT_SET_SIM_POWER_DONE: {
2083 ar = (AsyncResult) msg.obj;
2084 request = (MainThreadRequest) ar.userObj;
2085 IIntegerConsumer callback =
2086 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2087 if (ar.exception != null) {
2088 loge("setSimPower exception: " + ar.exception);
2089 int errorCode = TelephonyManager.CallForwardingInfoCallback
2090 .RESULT_ERROR_UNKNOWN;
2091 if (ar.exception instanceof CommandException) {
2092 CommandException.Error error =
2093 ((CommandException) (ar.exception)).getCommandError();
2094 if (error == CommandException.Error.SIM_ERR) {
2095 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2096 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2097 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2098 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2099 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2100 } else {
2101 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2102 }
2103 }
2104 try {
2105 callback.accept(errorCode);
2106 } catch (RemoteException e) {
2107 // Ignore if the remote process is no longer available to call back.
2108 Log.w(LOG_TAG, "setSimPower: callback not available.");
2109 }
2110 } else {
2111 try {
2112 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2113 } catch (RemoteException e) {
2114 // Ignore if the remote process is no longer available to call back.
2115 Log.w(LOG_TAG, "setSimPower: callback not available.");
2116 }
2117 }
2118 break;
2119 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002120 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2121 request = (MainThreadRequest) msg.obj;
2122
2123 final Phone phone = getPhoneFromRequest(request);
2124 if (phone == null || phone.getServiceStateTracker() == null) {
2125 request.result = new IllegalStateException("Phone or SST is null");
2126 notifyRequester(request);
2127 break;
2128 }
2129
2130 Pair<Integer, SignalStrengthUpdateRequest> pair =
2131 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2132 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2133 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002134 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002135 request.subId, pair.first /*callingUid*/,
2136 pair.second /*request*/, onCompleted);
2137 break;
2138 }
2139 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2140 ar = (AsyncResult) msg.obj;
2141 request = (MainThreadRequest) ar.userObj;
2142 // request.result will be the exception of ar if present, true otherwise.
2143 // Be cautious not to leave result null which will wait() forever
2144 request.result = ar.exception != null ? ar.exception : true;
2145 notifyRequester(request);
2146 break;
2147 }
2148 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2149 request = (MainThreadRequest) msg.obj;
2150
2151 Phone phone = getPhoneFromRequest(request);
2152 if (phone == null || phone.getServiceStateTracker() == null) {
2153 request.result = new IllegalStateException("Phone or SST is null");
2154 notifyRequester(request);
2155 break;
2156 }
2157
2158 Pair<Integer, SignalStrengthUpdateRequest> pair =
2159 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2160 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2161 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002162 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002163 request.subId, pair.first /*callingUid*/,
2164 pair.second /*request*/, onCompleted);
2165 break;
2166 }
2167 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2168 ar = (AsyncResult) msg.obj;
2169 request = (MainThreadRequest) ar.userObj;
2170 request.result = ar.exception != null ? ar.exception : true;
2171 notifyRequester(request);
2172 break;
2173 }
Jordan Liu109698e2020-11-24 14:50:34 -08002174
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002175 case CMD_GET_SLICING_CONFIG: {
2176 request = (MainThreadRequest) msg.obj;
2177 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2178 request.phone.getSlicingConfig(onCompleted);
2179 break;
2180 }
2181 case EVENT_GET_SLICING_CONFIG_DONE: {
2182 ar = (AsyncResult) msg.obj;
2183 request = (MainThreadRequest) ar.userObj;
2184 ResultReceiver result = (ResultReceiver) request.argument;
2185
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002186 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002187 Bundle bundle = new Bundle();
2188 int resultCode = 0;
2189 if (ar.exception != null) {
2190 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2191 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002192 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002193 } else if (ar.result == null) {
2194 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002195 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002196 } else {
2197 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002198 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2199 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002200 }
2201
2202 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002203 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002204 }
2205 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2206 result.send(resultCode, bundle);
2207 notifyRequester(request);
2208 break;
2209 }
2210
Sarah Chin71b3a852022-09-28 15:54:19 -07002211 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002212 request = (MainThreadRequest) msg.obj;
2213 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002214 PurchasePremiumCapabilityArgument arg =
2215 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002216 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002217 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002218 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002219 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002220
Sarah Chin71b3a852022-09-28 15:54:19 -07002221 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002222 ar = (AsyncResult) msg.obj;
2223 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002224 PurchasePremiumCapabilityArgument arg =
2225 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002226 try {
2227 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002229 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002230 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 + ", result= "
2232 + TelephonyManager.convertPurchaseResultToString(result));
2233 } catch (RemoteException e) {
2234 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 + " failed: " + e;
2237 if (DBG) log(logStr);
2238 AnomalyReporter.reportAnomaly(
2239 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2240 }
2241 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243
Michele Berionne5e411512020-11-13 02:36:59 +00002244 case CMD_PREPARE_UNATTENDED_REBOOT:
2245 request = (MainThreadRequest) msg.obj;
2246 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002247 UiccController.getInstance().getPinStorage()
2248 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002249 notifyRequester(request);
2250 break;
2251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 default:
2253 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2254 break;
2255 }
2256 }
Jake Hambye994d462014-02-03 13:10:13 -08002257
Pengquan Menga1bb6272018-09-06 09:59:22 -07002258 private void notifyRequester(MainThreadRequest request) {
2259 synchronized (request) {
2260 request.notifyAll();
2261 }
2262 }
2263
Jake Hambye994d462014-02-03 13:10:13 -08002264 private void handleNullReturnEvent(Message msg, String command) {
2265 AsyncResult ar = (AsyncResult) msg.obj;
2266 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2267 if (ar.exception == null) {
2268 request.result = true;
2269 } else {
2270 request.result = false;
2271 if (ar.exception instanceof CommandException) {
2272 loge(command + ": CommandException: " + ar.exception);
2273 } else {
2274 loge(command + ": Unknown exception");
2275 }
2276 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002277 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
2281 /**
2282 * Posts the specified command to be executed on the main thread,
2283 * waits for the request to complete, and returns the result.
2284 * @see #sendRequestAsync
2285 */
2286 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002287 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2288 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002289 }
2290
2291 /**
2292 * Posts the specified command to be executed on the main thread,
2293 * waits for the request to complete, and returns the result.
2294 * @see #sendRequestAsync
2295 */
2296 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2297 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002298 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002299 }
2300
2301 /**
2302 * Posts the specified command to be executed on the main thread,
2303 * waits for the request to complete, and returns the result.
2304 * @see #sendRequestAsync
2305 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002306 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002307 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2308 }
2309
2310 /**
2311 * Posts the specified command to be executed on the main thread,
2312 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2313 * if not timeout or null otherwise.
2314 * @see #sendRequestAsync
2315 */
2316 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2317 long timeoutInMs) {
2318 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002319 }
2320
2321 /**
2322 * Posts the specified command to be executed on the main thread,
2323 * waits for the request to complete, and returns the result.
2324 * @see #sendRequestAsync
2325 */
Nathan Harold92bed182018-10-12 18:16:49 -07002326 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002327 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002328 }
2329
2330 /**
2331 * Posts the specified command to be executed on the main thread,
2332 * waits for the request to complete, and returns the result.
2333 * @see #sendRequestAsync
2334 */
2335 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2337 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002338 }
2339
2340 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2342 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2343 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002344 * @see #sendRequestAsync
2345 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002346 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2347 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2349 throw new RuntimeException("This method will deadlock if called from the main thread.");
2350 }
2351
Nathan Harold92bed182018-10-12 18:16:49 -07002352 MainThreadRequest request = null;
2353 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2354 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2355 } else if (phone != null) {
2356 request = new MainThreadRequest(argument, phone, workSource);
2357 } else {
2358 request = new MainThreadRequest(argument, subId, workSource);
2359 }
2360
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 Message msg = mMainThreadHandler.obtainMessage(command, request);
2362 msg.sendToTarget();
2363
Rambo Wang0f050d82021-02-12 11:43:36 -08002364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 if (timeoutInMs >= 0) {
2367 // Wait for at least timeoutInMs before returning null request result
2368 long now = SystemClock.elapsedRealtime();
2369 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002370 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 try {
2372 request.wait(deadline - now);
2373 } catch (InterruptedException e) {
2374 // Do nothing, go back and check if request is completed or timeout
2375 } finally {
2376 now = SystemClock.elapsedRealtime();
2377 }
2378 }
2379 } else {
2380 // Wait for the request to complete
2381 while (request.result == null) {
2382 try {
2383 request.wait();
2384 } catch (InterruptedException e) {
2385 // Do nothing, go back and wait until the request is complete
2386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388 }
2389 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002390 if (request.result == null) {
2391 Log.wtf(LOG_TAG,
2392 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 return request.result;
2395 }
2396
2397 /**
2398 * Asynchronous ("fire and forget") version of sendRequest():
2399 * Posts the specified command to be executed on the main thread, and
2400 * returns immediately.
2401 * @see #sendRequest
2402 */
2403 private void sendRequestAsync(int command) {
2404 mMainThreadHandler.sendEmptyMessage(command);
2405 }
2406
2407 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002408 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002409 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002410 */
2411 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002412 sendRequestAsync(command, argument, null, null);
2413 }
2414
2415 /**
2416 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2417 * @see {@link #sendRequest(int,Object)}
2418 */
2419 private void sendRequestAsync(
2420 int command, Object argument, Phone phone, WorkSource workSource) {
2421 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002422 Message msg = mMainThreadHandler.obtainMessage(command, request);
2423 msg.sendToTarget();
2424 }
2425
2426 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 * Initialize the singleton PhoneInterfaceManager instance.
2428 * This is only done once, at startup, from PhoneApp.onCreate().
2429 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002430 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 synchronized (PhoneInterfaceManager.class) {
2432 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002433 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 } else {
2435 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2436 }
2437 return sInstance;
2438 }
2439 }
2440
2441 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002442 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002445 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002446 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002448 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002450 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2451 mSubscriptionController = SubscriptionController.getInstance();
2452 } else {
2453 mSubscriptionController = null;
2454 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002455 mTelephonySharedPreferences =
2456 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002457 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002458 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002459 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002460 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002461 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002462 mTelephony2gUpdater = new Telephony2gUpdater(
2463 Executors.newSingleThreadExecutor(), mApp);
2464 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 publish();
arunvoddud7401012022-12-15 16:08:12 +00002466 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002469 @VisibleForTesting
2470 public SharedPreferences getSharedPreferences() {
2471 return mTelephonySharedPreferences;
2472 }
2473
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002474 /**
2475 * Get the default phone for this device.
2476 */
2477 @VisibleForTesting
2478 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002479 Phone thePhone = getPhone(getDefaultSubscription());
2480 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2481 }
2482
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 private void publish() {
2484 if (DBG) log("publish: " + this);
2485
Peter Wangc035ce42020-01-08 21:00:22 -08002486 TelephonyFrameworkInitializer
2487 .getTelephonyServiceManager()
2488 .getTelephonyServiceRegisterer()
2489 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 }
2491
Stuart Scott584921c2015-01-15 17:10:34 -08002492 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002493 if (request.phone != null) {
2494 return request.phone;
2495 } else {
2496 return getPhoneFromSubId(request.subId);
2497 }
2498 }
2499
2500 private Phone getPhoneFromSubId(int subId) {
2501 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2502 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002503 }
2504
Rambo Wange53e07d2022-05-10 13:01:13 -07002505 @Nullable
2506 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002507 Phone phone = getPhoneFromRequest(request);
2508 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002509 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002510 }
2511
Wink Saville36469e72014-06-11 15:17:00 -07002512 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002513 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002514 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516
Kai Shif70f46f2021-03-03 13:59:46 -08002517 private void sendEraseModemConfig(@NonNull Phone phone) {
2518 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2519 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2520 }
2521
2522 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2523 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2524 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002525 }
2526
Peter Wang44b186e2020-01-13 23:33:09 -08002527 private boolean isImsAvailableOnDevice() {
2528 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2529 if (pm == null) {
2530 // For some reason package manger is not available.. This will fail internally anyway,
2531 // so do not throw error and allow.
2532 return true;
2533 }
2534 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2535 }
2536
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002538 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002539 }
2540
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 if (DBG) log("dial: " + number);
2543 // No permission check needed here: This is just a wrapper around the
2544 // ACTION_DIAL intent, which is available to any app since it puts up
2545 // the UI before it does anything.
2546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 String url = createTelUrl(number);
2550 if (url == null) {
2551 return;
2552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 // PENDING: should we just silently fail if phone is offhook or ringing?
2555 PhoneConstants.State state = mCM.getState(subId);
2556 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2557 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2558 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2559 mApp.startActivity(intent);
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 }
2564 }
2565
2566 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002567 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002568 }
2569
Wink Savilleb564aae2014-10-23 10:18:09 -07002570 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 if (DBG) log("call: " + number);
2572
2573 // This is just a wrapper around the ACTION_CALL intent, but we still
2574 // need to do a permission check since we're calling startActivity()
2575 // from the context of the phone app.
2576 enforceCallPermission();
2577
Jordan Liu1617b712019-07-10 15:06:26 -07002578 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 != AppOpsManager.MODE_ALLOWED) {
2580 return;
2581 }
2582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 String url = createTelUrl(number);
2586 if (url == null) {
2587 return;
2588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 boolean isValid = false;
2591 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2592 if (slist != null) {
2593 for (SubscriptionInfo subInfoRecord : slist) {
2594 if (subInfoRecord.getSubscriptionId() == subId) {
2595 isValid = true;
2596 break;
2597 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002598 }
Wink Saville08874612014-08-31 19:19:58 -07002599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 if (!isValid) {
2601 return;
2602 }
Wink Saville08874612014-08-31 19:19:58 -07002603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2605 intent.putExtra(SUBSCRIPTION_KEY, subId);
2606 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2607 mApp.startActivity(intent);
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
2610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612
Wink Savilleb564aae2014-10-23 10:18:09 -07002613 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002614 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002615 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2616 }
2617
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002619 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002620 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2621 }
2622
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002628 Phone phone = getPhone(subId);
2629 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 checkSimPin.start();
2631 return checkSimPin.unlockSim(null, pin);
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 }
2636
Wink Savilleb564aae2014-10-23 10:18:09 -07002637 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002642 Phone phone = getPhone(subId);
2643 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 checkSimPuk.start();
2645 return checkSimPuk.unlockSim(puk, pin);
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 }
2650
2651 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002652 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 * a synchronous one.
2654 */
2655 private static class UnlockSim extends Thread {
2656
2657 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002658 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659
2660 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002661 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2662 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663
2664 // For replies from SimCard interface
2665 private Handler mHandler;
2666
2667 // For async handler to identify request type
2668 private static final int SUPPLY_PIN_COMPLETE = 100;
2669
Michele Berionne5e411512020-11-13 02:36:59 +00002670 UnlockSim(int phoneId, IccCard simCard) {
2671 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 mSimCard = simCard;
2673 }
2674
2675 @Override
2676 public void run() {
2677 Looper.prepare();
2678 synchronized (UnlockSim.this) {
2679 mHandler = new Handler() {
2680 @Override
2681 public void handleMessage(Message msg) {
2682 AsyncResult ar = (AsyncResult) msg.obj;
2683 switch (msg.what) {
2684 case SUPPLY_PIN_COMPLETE:
2685 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2686 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002687 mRetryCount = msg.arg1;
2688 if (ar.exception != null) {
2689 if (ar.exception instanceof CommandException &&
2690 ((CommandException)(ar.exception)).getCommandError()
2691 == CommandException.Error.PASSWORD_INCORRECT) {
2692 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002693 } //When UiccCardApp dispose,handle message and return exception
2694 else if (ar.exception instanceof CommandException &&
2695 ((CommandException) (ar.exception)).getCommandError()
2696 == CommandException.Error.ABORTED) {
2697 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002698 } else {
2699 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2700 }
2701 } else {
2702 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 mDone = true;
2705 UnlockSim.this.notifyAll();
2706 }
2707 break;
2708 }
2709 }
2710 };
2711 UnlockSim.this.notifyAll();
2712 }
2713 Looper.loop();
2714 }
2715
2716 /*
2717 * Use PIN or PUK to unlock SIM card
2718 *
2719 * If PUK is null, unlock SIM card with PIN
2720 *
2721 * If PUK is not null, unlock SIM card with PUK and set PIN code
2722 */
Wink Saville9de0f752013-10-22 19:04:03 -07002723 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724
2725 while (mHandler == null) {
2726 try {
2727 wait();
2728 } catch (InterruptedException e) {
2729 Thread.currentThread().interrupt();
2730 }
2731 }
2732 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2733
2734 if (puk == null) {
2735 mSimCard.supplyPin(pin, callback);
2736 } else {
2737 mSimCard.supplyPuk(puk, pin, callback);
2738 }
2739
2740 while (!mDone) {
2741 try {
2742 Log.d(LOG_TAG, "wait for done");
2743 wait();
2744 } catch (InterruptedException e) {
2745 // Restore the interrupted status
2746 Thread.currentThread().interrupt();
2747 }
2748 }
2749 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002750 int[] resultArray = new int[2];
2751 resultArray[0] = mResult;
2752 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002753
2754 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002755 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002756 }
2757
Wink Saville9de0f752013-10-22 19:04:03 -07002758 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 }
2760 }
2761
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002762 /**
2763 * This method has been removed due to privacy and stability concerns.
2764 */
2765 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002767 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2768 return;
Wink Saville36469e72014-06-11 15:17:00 -07002769 }
2770
Nathan Harold1f889d82020-06-04 17:05:26 -07002771 @Override
2772 public void updateServiceLocationWithPackageName(String callingPackage) {
2773 mApp.getSystemService(AppOpsManager.class)
2774 .checkPackage(Binder.getCallingUid(), callingPackage);
2775
Nathan Haroldf096d982020-11-18 17:18:06 -08002776 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002777 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2778 // Callers targeting S have no business invoking this method.
2779 return;
2780 }
2781
2782 LocationAccessPolicy.LocationPermissionResult locationResult =
2783 LocationAccessPolicy.checkLocationPermission(mApp,
2784 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2785 .setCallingPackage(callingPackage)
2786 .setCallingFeatureId(null)
2787 .setCallingPid(Binder.getCallingPid())
2788 .setCallingUid(Binder.getCallingUid())
2789 .setMethod("updateServiceLocation")
2790 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2791 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2792 .build());
2793 // Apps that lack location permission have no business calling this method;
2794 // however, because no permission was declared in the public API, denials must
2795 // all be "soft".
2796 switch (locationResult) {
2797 case DENIED_HARD: /* fall through */
2798 case DENIED_SOFT:
2799 return;
2800 }
2801
2802 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 final long identity = Binder.clearCallingIdentity();
2804 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002805 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002807 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
2813
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002814 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002815 @Override
2816 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002817 return isRadioOnWithFeature(callingPackage, null);
2818 }
2819
2820
2821 @Override
2822 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2823 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2824 callingFeatureId);
2825 }
2826
2827 @Deprecated
2828 @Override
2829 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2830 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002831 }
2832
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002833 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002834 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2835 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002837 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002838 return false;
2839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 return isRadioOnForSubscriber(subId);
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
2846 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002847 }
2848
2849 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 final Phone phone = getPhone(subId);
2853 if (phone != null) {
2854 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2855 } else {
2856 return false;
2857 }
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
2862
2863 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002864 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
Wink Saville36469e72014-06-11 15:17:00 -07002866
Wink Savilleb564aae2014-10-23 10:18:09 -07002867 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 final Phone phone = getPhone(subId);
2873 if (phone != null) {
2874 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2875 }
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 }
Wink Saville36469e72014-06-11 15:17:00 -07002879 }
2880
2881 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002882 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002883 }
2884
Wink Savilleb564aae2014-10-23 10:18:09 -07002885 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002886 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887
2888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 final Phone phone = getPhone(subId);
2891 if (phone == null) {
2892 return false;
2893 }
2894 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2895 toggleRadioOnOffForSubscriber(subId);
2896 }
2897 return true;
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
Wink Saville36469e72014-06-11 15:17:00 -07002902
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002903 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002904 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002905 /*
2906 * If any of the Radios are available, it will need to be
2907 * shutdown. So return true if any Radio is available.
2908 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2912 Phone phone = PhoneFactory.getPhone(i);
2913 if (phone != null && phone.isRadioAvailable()) return true;
2914 }
2915 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2916 return false;
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002919 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002920 }
2921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002923 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 enforceModifyPermission();
2925
2926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2929 logv("Shutting down Phone " + i);
2930 shutdownRadioUsingPhoneId(i);
2931 }
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002934 }
2935 }
2936
2937 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002938 Phone phone = PhoneFactory.getPhone(phoneId);
2939 if (phone != null && phone.isRadioAvailable()) {
2940 phone.shutdownRadio();
2941 }
2942 }
2943
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2950 if (defaultPhone != null) {
2951 defaultPhone.setRadioPower(turnOn);
2952 return true;
2953 } else {
2954 loge("There's no default phone.");
2955 return false;
2956 }
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002959 }
Wink Saville36469e72014-06-11 15:17:00 -07002960 }
2961
Wink Savilleb564aae2014-10-23 10:18:09 -07002962 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 final Phone phone = getPhone(subId);
2968 if (phone != null) {
2969 phone.setRadioPower(turnOn);
2970 return true;
2971 } else {
2972 return false;
2973 }
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
2978
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002979 /**
2980 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2981 * no reason to power it off. When any of the voters want to power it off, it will be turned
2982 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2983 * powering it off, and these radio off votes will be cleared.
2984 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2985 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2986 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2987 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2988 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2989 * check its vote.
2990 *
2991 * @param subId The subscription ID.
2992 * @param reason The reason for powering off radio.
2993 * @return true on success and false on failure.
2994 */
2995 public boolean requestRadioPowerOffForReason(int subId,
2996 @TelephonyManager.RadioPowerReason int reason) {
2997 enforceModifyPermission();
2998
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 final Phone phone = getPhone(subId);
3002 if (phone != null) {
3003 phone.setRadioPowerForReason(false, reason);
3004 return true;
3005 } else {
3006 return false;
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 /**
3014 * Remove the vote on powering off the radio for a reason, as requested by
3015 * {@link requestRadioPowerOffForReason}.
3016 *
3017 * @param subId The subscription ID.
3018 * @param reason The reason for powering off radio.
3019 * @return true on success and false on failure.
3020 */
3021 public boolean clearRadioPowerOffForReason(int subId,
3022 @TelephonyManager.RadioPowerReason int reason) {
3023 enforceModifyPermission();
3024
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 final Phone phone = getPhone(subId);
3028 if (phone != null) {
3029 phone.setRadioPowerForReason(true, reason);
3030 return true;
3031 } else {
3032 return false;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 /**
3040 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3041 *
3042 * @param subId The subscription ID.
3043 * @param callingPackage The package making the call.
3044 * @param callingFeatureId The feature in the package.
3045 * @return List of reasons for powering off radio.
3046 */
3047 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3048 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3049
3050 final long identity = Binder.clearCallingIdentity();
3051 List result = new ArrayList();
3052 try {
3053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3054 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3055 return result;
3056 }
3057
3058 final Phone phone = getPhone(subId);
3059 if (phone != null) {
3060 result.addAll(phone.getRadioPowerOffReasons());
3061 }
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 return result;
3066 }
3067
Wink Saville36469e72014-06-11 15:17:00 -07003068 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003069 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003070 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
Jack Yu285100e2022-12-02 22:48:35 -08003075 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 final Phone phone = getPhone(subId);
3077 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003078 phone.getDataSettingsManager().setDataEnabled(
3079 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 return true;
3081 } else {
3082 return false;
3083 }
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087 }
3088
Wink Saville36469e72014-06-11 15:17:00 -07003089 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003090 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003091 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
Jack Yu285100e2022-12-02 22:48:35 -08003096 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 final Phone phone = getPhone(subId);
3098 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003099 phone.getDataSettingsManager().setDataEnabled(
3100 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 return true;
3102 } else {
3103 return false;
3104 }
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Sanket Padawe356d7632015-06-22 14:03:32 -07003110 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003111 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 final Phone phone = getPhone(subId);
3115 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003116 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 } else {
3118 return false;
3119 }
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124
3125 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003126 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003127 }
3128
pkanwarae03a6b2016-11-06 20:37:09 -08003129 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130 enforceCallPermission();
3131
3132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3135 return;
3136 }
3137 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3138 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
pkanwar32d516d2016-10-14 19:37:38 -07003142 };
3143
Wink Savilleb564aae2014-10-23 10:18:09 -07003144 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3150 return false;
3151 }
3152 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003158 /**
3159 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3160 * tag on getCallState Binder call.
3161 */
3162 @Deprecated
3163 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003165 if (CompatChanges.isChangeEnabled(
3166 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3167 Binder.getCallingUid())) {
3168 // Do not allow this API to be called on API version 31+, it should only be
3169 // called on old apps using this Binder call directly.
3170 throw new SecurityException("This method can only be used for applications "
3171 + "targeting API version 30 or less.");
3172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 final long identity = Binder.clearCallingIdentity();
3174 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003175 Phone phone = getPhone(getDefaultSubscription());
3176 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3177 PhoneConstantConversions.convertCallState(phone.getState());
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
3181 }
3182
3183 @Override
3184 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3185 if (CompatChanges.isChangeEnabled(
3186 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3187 Binder.getCallingUid())) {
3188 // Check READ_PHONE_STATE for API version 31+
3189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3190 featureId, "getCallStateForSubscription")) {
3191 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3192 + "targeting API level 31+.");
3193 }
3194 }
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3199 PhoneConstantConversions.convertCallState(phone.getState());
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
Sanket Padawe356d7632015-06-22 14:03:32 -07003205 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003206 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003207 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003208 }
3209
3210 @Override
3211 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003214 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003216 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 } else {
3218 return PhoneConstantConversions.convertDataState(
3219 PhoneConstants.DataState.DISCONNECTED);
3220 }
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 }
3225
Sanket Padawe356d7632015-06-22 14:03:32 -07003226 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003227 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003228 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003229 }
3230
3231 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003232 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 final long identity = Binder.clearCallingIdentity();
3234 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003235 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003237 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 } else {
3239 return TelephonyManager.DATA_ACTIVITY_NONE;
3240 }
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003244 }
3245
3246 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003247 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003248 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003249 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003250
3251 LocationAccessPolicy.LocationPermissionResult locationResult =
3252 LocationAccessPolicy.checkLocationPermission(mApp,
3253 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3254 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003255 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003256 .setCallingPid(Binder.getCallingPid())
3257 .setCallingUid(Binder.getCallingUid())
3258 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003259 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003260 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3261 .build());
3262 switch (locationResult) {
3263 case DENIED_HARD:
3264 throw new SecurityException("Not allowed to access cell location");
3265 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003266 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3267 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 }
3269
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003274 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003275 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
Svetoslav64fad262015-04-14 14:35:21 -07003279 }
3280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003281 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003282 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003283 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3284 // registered cell info, so return a NULL country instead.
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003287 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3288 // Get default phone in this case.
3289 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3290 }
Jack Yu285100e2022-12-02 22:48:35 -08003291 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003293 if (phone == null) return "";
3294 ServiceStateTracker sst = phone.getServiceStateTracker();
3295 if (sst == null) return "";
3296 LocaleTracker lt = sst.getLocaleTracker();
3297 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003298 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003302 }
3303
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003304 /**
3305 * This method was removed due to potential issues caused by performing partial
3306 * updates of service state, and lack of a credible use case.
3307 *
3308 * This has the ability to break the telephony implementation by disabling notification of
3309 * changes in device connectivity. DO NOT USE THIS!
3310 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003311 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312 public void enableLocationUpdates() {
3313 mApp.enforceCallingOrSelfPermission(
3314 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 }
3316
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003317 /**
3318 * This method was removed due to potential issues caused by performing partial
3319 * updates of service state, and lack of a credible use case.
3320 *
3321 * This has the ability to break the telephony implementation by disabling notification of
3322 * changes in device connectivity. DO NOT USE THIS!
3323 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 @Override
3325 public void disableLocationUpdates() {
3326 mApp.enforceCallingOrSelfPermission(
3327 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 }
3329
3330 @Override
3331 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003332 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3333 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003334 try {
3335 mApp.getSystemService(AppOpsManager.class)
3336 .checkPackage(Binder.getCallingUid(), callingPackage);
3337 } catch (SecurityException e) {
3338 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3339 throw e;
3340 }
3341
Nathan Haroldf096d982020-11-18 17:18:06 -08003342 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003343 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3344 throw new SecurityException(
3345 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3346 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003347
Jordan Liu1617b712019-07-10 15:06:26 -07003348 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003349 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3350 return null;
3351 }
Svetoslav64fad262015-04-14 14:35:21 -07003352
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003353 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003355 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003356 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003357
Nathan Haroldf180aac2018-06-01 18:43:55 -07003358 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3359 for (CellInfo ci : info) {
3360 if (ci instanceof CellInfoGsm) {
3361 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3362 } else if (ci instanceof CellInfoWcdma) {
3363 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003365 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003366 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003369 private List<CellInfo> getCachedCellInfo() {
3370 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3371 for (Phone phone : PhoneFactory.getPhones()) {
3372 List<CellInfo> info = phone.getAllCellInfo();
3373 if (info != null) cellInfos.addAll(info);
3374 }
3375 return cellInfos;
3376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003377
3378 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003379 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003381 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003382
3383 LocationAccessPolicy.LocationPermissionResult locationResult =
3384 LocationAccessPolicy.checkLocationPermission(mApp,
3385 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3386 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003387 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003388 .setCallingPid(Binder.getCallingPid())
3389 .setCallingUid(Binder.getCallingUid())
3390 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003391 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003392 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3393 .build());
3394 switch (locationResult) {
3395 case DENIED_HARD:
3396 throw new SecurityException("Not allowed to access cell info");
3397 case DENIED_SOFT:
3398 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 }
3400
Nathan Haroldf096d982020-11-18 17:18:06 -08003401 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003402 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3403 return getCachedCellInfo();
3404 }
3405
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003406 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003407 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3411 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003412 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003413 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414 if (info != null) cellInfos.addAll(info);
3415 }
3416 return cellInfos;
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419 }
3420 }
3421
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003422 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003423 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3424 String callingFeatureId) {
3425 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3426 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003427 }
3428
3429 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003430 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3431 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003432 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003433 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003434 }
3435
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003436 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3437 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003439 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003440
3441 LocationAccessPolicy.LocationPermissionResult locationResult =
3442 LocationAccessPolicy.checkLocationPermission(mApp,
3443 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3444 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003445 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003446 .setCallingPid(Binder.getCallingPid())
3447 .setCallingUid(Binder.getCallingUid())
3448 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003449 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3450 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003451 .build());
3452 switch (locationResult) {
3453 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003454 if (TelephonyPermissions
3455 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003456 // Safetynet logging for b/154934934
3457 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3458 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003459 throw new SecurityException("Not allowed to access cell info");
3460 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003461 if (TelephonyPermissions
3462 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003463 // Safetynet logging for b/154934934
3464 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3465 }
Nathan Harold5320c422019-05-09 10:26:08 -07003466 try {
3467 cb.onCellInfo(new ArrayList<CellInfo>());
3468 } catch (RemoteException re) {
3469 // Drop without consequences
3470 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003471 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003472 }
3473
Nathan Harolda939a962019-05-09 10:13:47 -07003474
3475 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003476 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3477
3478 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3479 }
3480
3481 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003482 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003483 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003485
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003488 Phone phone = getPhone(subId);
3489 if (phone == null) {
3490 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3491 } else {
3492 phone.setCellInfoListRate(rateInMillis, workSource);
3493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494 } finally {
3495 Binder.restoreCallingIdentity(identity);
3496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
3498
Shishir Agrawala9f32182016-04-12 12:00:16 -07003499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003500 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003501 Phone phone = PhoneFactory.getPhone(slotIndex);
3502 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003503 return null;
3504 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003505 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003506 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003507 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003508 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003509 return null;
3510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 return phone.getImei();
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
3517 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003518 }
3519
3520 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003521 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3522 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3523 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3524 callingFeatureId, "getPrimaryImei")) {
3525 throw new SecurityException("Caller does not have permission");
3526 }
3527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 for (Phone phone : PhoneFactory.getPhones()) {
3530 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3531 return phone.getImei();
3532 }
3533 }
3534 throw new UnsupportedOperationException("Operation not supported");
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
3537 }
3538 }
3539
3540 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003541 public String getTypeAllocationCodeForSlot(int slotIndex) {
3542 Phone phone = PhoneFactory.getPhone(slotIndex);
3543 String tac = null;
3544 if (phone != null) {
3545 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003546 try {
3547 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3548 } catch (IndexOutOfBoundsException e) {
3549 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3550 return null;
3551 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003552 }
3553 return tac;
3554 }
3555
3556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003557 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003558 try {
3559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3560 } catch (SecurityException se) {
3561 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3562 throw new SecurityException("Package " + callingPackage + " does not belong to "
3563 + Binder.getCallingUid());
3564 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003565 Phone phone = PhoneFactory.getPhone(slotIndex);
3566 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003567 return null;
3568 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003569
Jeff Davidson913390f2018-02-23 17:11:49 -08003570 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003571 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003572 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003573 return null;
3574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575
3576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 return phone.getMeid();
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
3581 }
Jack Yu2af8d712017-03-15 17:14:14 -07003582 }
3583
3584 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003585 public String getManufacturerCodeForSlot(int slotIndex) {
3586 Phone phone = PhoneFactory.getPhone(slotIndex);
3587 String manufacturerCode = null;
3588 if (phone != null) {
3589 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003590 try {
3591 manufacturerCode =
3592 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3593 } catch (IndexOutOfBoundsException e) {
3594 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3595 return null;
3596 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003597 }
3598 return manufacturerCode;
3599 }
3600
3601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003602 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3603 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003604 Phone phone = PhoneFactory.getPhone(slotIndex);
3605 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003606 return null;
3607 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003608 int subId = phone.getSubId();
3609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003610 mApp, subId, callingPackage, callingFeatureId,
3611 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003612 return null;
3613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614
3615 final long identity = Binder.clearCallingIdentity();
3616 try {
3617 return phone.getDeviceSvn();
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003621 }
3622
fionaxu43304da2017-11-27 22:51:16 -08003623 @Override
3624 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = getPhone(subId);
3628 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
fionaxu43304da2017-11-27 22:51:16 -08003632 }
3633
3634 @Override
3635 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 final Phone phone = getPhone(subId);
3639 return phone == null ? null : phone.getCarrierName();
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
fionaxu43304da2017-11-27 22:51:16 -08003643 }
3644
calvinpanffe225e2018-11-01 19:43:06 +08003645 @Override
chen xu0026ca62019-03-06 15:28:50 -08003646 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 final Phone phone = getPhone(subId);
3650 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003651 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
3655 }
3656
3657 @Override
chen xu0026ca62019-03-06 15:28:50 -08003658 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003662 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
3666 }
3667
chen xu651eec72018-11-11 19:03:44 -08003668 @Override
chen xu864e11c2018-12-06 22:10:03 -08003669 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3670 if (!isSubscriptionMccMnc) {
3671 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3672 }
chen xu651eec72018-11-11 19:03:44 -08003673 final Phone phone = PhoneFactory.getPhone(slotIndex);
3674 if (phone == null) {
3675 return TelephonyManager.UNKNOWN_CARRIER_ID;
3676 }
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003685 //
3686 // Internal helper methods.
3687 //
3688
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003689 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003690 * Make sure the caller is the calling package itself
3691 *
3692 * @throws SecurityException if the caller is not the calling package
3693 */
3694 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3695 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003696 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3697 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003698 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003699 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003700 } catch (PackageManager.NameNotFoundException e) {
3701 // packageUid is -1
3702 }
3703 if (packageUid != callingUid) {
3704 throw new SecurityException(message + ": Package " + callingPackage
3705 + " does not belong to " + callingUid);
3706 }
3707 }
3708
3709 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003710 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3711 *
3712 * @throws SecurityException if the caller does not have the required permission
3713 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003714 @VisibleForTesting
3715 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003716 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3717 }
3718
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003719 /**
arunvoddud7401012022-12-15 16:08:12 +00003720 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003721 *
3722 * @throws SecurityException if the caller does not have the required permission
3723 */
3724 @VisibleForTesting
3725 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003726 enforceReadPermission(null);
3727 }
3728
3729 /**
3730 * Make sure the caller has the READ_PHONE_STATE permissions.
3731 *
3732 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3733 */
3734 @VisibleForTesting
3735 public void enforceReadPermission(String msg) {
3736 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003737 }
3738
Shuo Qian3b6ee772019-11-13 17:43:31 -08003739 private void enforceActiveEmergencySessionPermission() {
3740 mApp.enforceCallingOrSelfPermission(
3741 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3742 }
3743
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003744 /**
3745 * Make sure the caller has the CALL_PHONE permission.
3746 *
3747 * @throws SecurityException if the caller does not have the required permission
3748 */
3749 private void enforceCallPermission() {
3750 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3751 }
3752
paulhu5a773602019-08-23 19:17:33 +08003753 private void enforceSettingsPermission() {
3754 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003755 }
3756
Michele Berionne5e411512020-11-13 02:36:59 +00003757 private void enforceRebootPermission() {
3758 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3759 }
3760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003761 private String createTelUrl(String number) {
3762 if (TextUtils.isEmpty(number)) {
3763 return null;
3764 }
3765
Jake Hambye994d462014-02-03 13:10:13 -08003766 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003767 }
3768
Ihab Awadf9e92732013-12-05 18:02:52 -08003769 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003770 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3771 }
3772
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003773 private static void logv(String msg) {
3774 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3775 }
3776
Ihab Awadf9e92732013-12-05 18:02:52 -08003777 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003778 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3779 }
3780
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003781 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003782 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003783 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003784 }
3785
Sanket Padawe356d7632015-06-22 14:03:32 -07003786 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003787 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788 final long identity = Binder.clearCallingIdentity();
3789 try {
3790 final Phone phone = PhoneFactory.getPhone(slotIndex);
3791 if (phone == null) {
3792 return PhoneConstants.PHONE_TYPE_NONE;
3793 } else {
3794 return phone.getPhoneType();
3795 }
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003799 }
3800
3801 /**
3802 * Returns the CDMA ERI icon index to display
3803 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003805 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3806 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3807 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003808 }
3809
Sanket Padawe356d7632015-06-22 14:03:32 -07003810 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003811 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3812 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003814 mApp, subId, callingPackage, callingFeatureId,
3815 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003816 return -1;
3817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 final Phone phone = getPhone(subId);
3822 if (phone != null) {
3823 return phone.getCdmaEriIconIndex();
3824 } else {
3825 return -1;
3826 }
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003830 }
3831
3832 /**
3833 * Returns the CDMA ERI icon mode,
3834 * 0 - ON
3835 * 1 - FLASHING
3836 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003838 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3839 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3840 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003841 }
3842
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003844 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3845 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003847 mApp, subId, callingPackage, callingFeatureId,
3848 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 return -1;
3850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 final Phone phone = getPhone(subId);
3855 if (phone != null) {
3856 return phone.getCdmaEriIconMode();
3857 } else {
3858 return -1;
3859 }
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003863 }
3864
3865 /**
3866 * Returns the CDMA ERI text,
3867 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003869 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3870 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3871 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003872 }
3873
Sanket Padawe356d7632015-06-22 14:03:32 -07003874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003875 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3876 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003878 mApp, subId, callingPackage, callingFeatureId,
3879 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003880 return null;
3881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882
3883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 final Phone phone = getPhone(subId);
3886 if (phone != null) {
3887 return phone.getCdmaEriText();
3888 } else {
3889 return null;
3890 }
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003894 }
3895
3896 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003897 * Returns the CDMA MDN.
3898 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003899 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003900 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3902 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903
3904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003907 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 return phone.getLine1Number();
3909 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 return null;
3912 }
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003915 }
3916 }
3917
3918 /**
3919 * Returns the CDMA MIN.
3920 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003921 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003922 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3924 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
3926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 final Phone phone = getPhone(subId);
3929 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3930 return phone.getCdmaMin();
3931 } else {
3932 return null;
3933 }
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003936 }
3937 }
3938
Hall Liud892bec2018-11-30 14:51:45 -08003939 @Override
3940 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3941 INumberVerificationCallback callback, String callingPackage) {
3942 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3943 != PERMISSION_GRANTED) {
3944 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3945 }
3946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3947
3948 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3949 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003950 throw new SecurityException("Calling package must be configured in the device config: "
3951 + "calling package: " + callingPackage
3952 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003953 }
3954
3955 if (range == null) {
3956 throw new NullPointerException("Range must be non-null");
3957 }
3958
3959 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003960 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003961
3962 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3963 }
3964
Junda Liuca05d5d2014-08-14 22:36:34 -07003965 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003966 * Returns true if CDMA provisioning needs to run.
3967 */
3968 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969 final long identity = Binder.clearCallingIdentity();
3970 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 }
3976
3977 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003978 * Sets the voice mail number of a given subId.
3979 */
3980 @Override
3981 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003982 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3983 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984
3985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3988 new Pair<String, String>(alphaTag, number), new Integer(subId));
3989 return success;
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
3992 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003993 }
3994
Ta-wei Yen87c49842016-05-13 21:19:52 -07003995 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003996 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003998 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3999 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004000 if (!TextUtils.equals(callingPackage, systemDialer)) {
4001 throw new SecurityException("caller must be system dialer");
4002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4007 if (phoneAccountHandle == null) {
4008 return null;
4009 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004010 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004013 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004014 }
4015
4016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004017 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4018 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004021 mApp, subId, callingPackage, callingFeatureId,
4022 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004023 return null;
4024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004026 final long identity = Binder.clearCallingIdentity();
4027 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004028 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004029 } finally {
4030 Binder.restoreCallingIdentity(identity);
4031 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004032 }
4033
4034 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004035 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4036 VisualVoicemailSmsFilterSettings settings) {
4037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004042 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004046 }
4047
4048 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004049 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004059 }
4060
4061 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004062 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4063 String callingPackage, int subId) {
4064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004069 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004073 }
4074
4075 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004076 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078
4079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004082 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004086 }
4087
4088 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004089 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4090 String callingAttributionTag, int subId, String number, int port, String text,
4091 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004092 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004093 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004094 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004095 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004096 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4097 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004098 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004099
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004100 /**
fionaxu0152e512016-11-14 13:36:14 -08004101 * Sets the voice activation state of a given subId.
4102 */
4103 @Override
4104 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4106 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107
4108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 final Phone phone = getPhone(subId);
4111 if (phone != null) {
4112 phone.setVoiceActivationState(activationState);
4113 } else {
4114 loge("setVoiceActivationState fails with invalid subId: " + subId);
4115 }
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004118 }
4119 }
4120
4121 /**
4122 * Sets the data activation state of a given subId.
4123 */
4124 @Override
4125 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4127 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128
4129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 final Phone phone = getPhone(subId);
4132 if (phone != null) {
4133 phone.setDataActivationState(activationState);
4134 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004135 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136 }
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004139 }
4140 }
4141
4142 /**
4143 * Returns the voice activation state of a given subId.
4144 */
4145 @Override
4146 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148
fionaxu0152e512016-11-14 13:36:14 -08004149 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 if (phone != null) {
4153 return phone.getVoiceActivationState();
4154 } else {
4155 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4156 }
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004159 }
4160 }
4161
4162 /**
4163 * Returns the data activation state of a given subId.
4164 */
4165 @Override
4166 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168
fionaxu0152e512016-11-14 13:36:14 -08004169 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 final long identity = Binder.clearCallingIdentity();
4171 try {
4172 if (phone != null) {
4173 return phone.getDataActivationState();
4174 } else {
4175 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4176 }
4177 } finally {
4178 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004179 }
4180 }
4181
4182 /**
Wink Saville36469e72014-06-11 15:17:00 -07004183 * Returns the unread count of voicemails for a subId
4184 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004186 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4187 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004189 mApp, subId, callingPackage, callingFeatureId,
4190 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004191 return 0;
4192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 final Phone phone = getPhone(subId);
4196 if (phone != null) {
4197 return phone.getVoiceMessageCount();
4198 } else {
4199 return 0;
4200 }
4201 } finally {
4202 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004204 }
4205
4206 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004207 * returns true, if the device is in a state where both voice and data
4208 * are supported simultaneously. This can change based on location or network condition.
4209 */
4210 @Override
4211 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 final Phone phone = getPhone(subId);
4215 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
4218 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004219 }
4220
4221 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004222 * Send the dialer code if called from the current default dialer or the caller has
4223 * carrier privilege.
4224 * @param inputCode The dialer code to send
4225 */
4226 @Override
4227 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004228 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004229 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004230 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4231 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004232 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004233 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004234 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236
4237 final long identity = Binder.clearCallingIdentity();
4238 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004239 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
fionaxu235cc5e2017-03-06 22:25:57 -08004243 }
4244
Pengquan Menga1bb6272018-09-06 09:59:22 -07004245 @Override
4246 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004247 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004248 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004249 mApp, subId, "getNetworkSelectionMode");
4250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 if (!isActiveSubscription(subId)) {
4253 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4254 }
4255 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4256 } finally {
4257 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004259 }
4260
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004262 public boolean isInEmergencySmsMode() {
4263 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 for (Phone phone : PhoneFactory.getPhones()) {
4267 if (phone.isInEmergencySmsMode()) {
4268 return true;
4269 }
4270 }
4271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 return false;
4275 }
4276
shilu366312e2019-12-17 09:28:10 -08004277 /**
4278 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4279 * @param subId The subscription to use to check the configuration.
4280 * @param c The callback that will be used to send the result.
4281 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004282 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004283 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4284 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004285 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004286 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004287
4288 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4289 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4290 "IMS not available on device.");
4291 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 final long token = Binder.clearCallingIdentity();
4293 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004294 int slotId = getSlotIndexOrException(subId);
4295 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004296
4297 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4298 if (controller != null) {
4299 ImsManager imsManager = controller.getImsManager(subId);
4300 if (imsManager != null) {
4301 imsManager.addRegistrationCallbackForSubscription(c, subId);
4302 } else {
4303 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4304 }
4305 } else {
4306 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4307 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004308 } catch (ImsException e) {
4309 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 } finally {
4311 Binder.restoreCallingIdentity(token);
4312 }
4313 }
4314
shilu366312e2019-12-17 09:28:10 -08004315 /**
4316 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4317 * @param subId The subscription to use to check the configuration.
4318 * @param c The callback that will be used to send the result.
4319 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004321 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004322 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004323 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004324 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4325 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4326 }
Meng Wangafbc5852019-09-19 17:37:13 -07004327 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004328
Meng Wangafbc5852019-09-19 17:37:13 -07004329 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004330 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4331 if (controller != null) {
4332 ImsManager imsManager = controller.getImsManager(subId);
4333 if (imsManager != null) {
4334 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4335 } else {
4336 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4337 + "is inactive, ignoring unregister.");
4338 // If the ImsManager is not valid, just return, since the callback
4339 // will already have been removed internally.
4340 }
4341 }
Meng Wangafbc5852019-09-19 17:37:13 -07004342 } finally {
4343 Binder.restoreCallingIdentity(token);
4344 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 }
4346
Brad Ebingera34a6c22019-10-22 17:36:18 -07004347 /**
4348 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4349 */
4350 @Override
4351 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4352 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4353 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4354 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4355 "IMS not available on device.");
4356 }
4357 final long token = Binder.clearCallingIdentity();
4358 try {
4359 Phone phone = getPhone(subId);
4360 if (phone == null) {
4361 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4362 + subId + "'");
4363 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4364 }
4365 phone.getImsRegistrationState(regState -> {
4366 try {
4367 consumer.accept((regState == null)
4368 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4369 } catch (RemoteException e) {
4370 // Ignore if the remote process is no longer available to call back.
4371 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4372 }
4373 });
4374 } finally {
4375 Binder.restoreCallingIdentity(token);
4376 }
4377 }
4378
4379 /**
4380 * Get the transport type for the IMS service registration state.
4381 */
4382 @Override
4383 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004384 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004385 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004386 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4387 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4388 "IMS not available on device.");
4389 }
4390 final long token = Binder.clearCallingIdentity();
4391 try {
4392 Phone phone = getPhone(subId);
4393 if (phone == null) {
4394 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4395 + subId + "'");
4396 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4397 }
4398 phone.getImsRegistrationTech(regTech -> {
4399 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4400 int regTechConverted = (regTech == null)
4401 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4402 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4403 regTechConverted);
4404 try {
4405 consumer.accept(regTechConverted);
4406 } catch (RemoteException e) {
4407 // Ignore if the remote process is no longer available to call back.
4408 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4409 }
4410 });
4411 } finally {
4412 Binder.restoreCallingIdentity(token);
4413 }
4414 }
4415
shilu366312e2019-12-17 09:28:10 -08004416 /**
4417 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4418 * @param subId The subscription to use to check the configuration.
4419 * @param c The callback that will be used to send the result.
4420 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004422 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4423 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004424 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004425 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004426 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4427 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4428 "IMS not available on device.");
4429 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 final long token = Binder.clearCallingIdentity();
4431 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004432 int slotId = getSlotIndexOrException(subId);
4433 verifyImsMmTelConfiguredOrThrow(slotId);
4434 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004435 } catch (ImsException e) {
4436 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 } finally {
4438 Binder.restoreCallingIdentity(token);
4439 }
4440 }
4441
shilu366312e2019-12-17 09:28:10 -08004442 /**
4443 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4444 * @param subId The subscription to use to check the configuration.
4445 * @param c The callback that will be used to send the result.
4446 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004448 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004449 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004450 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004451 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4452 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4453 }
Meng Wangafbc5852019-09-19 17:37:13 -07004454
4455 final long token = Binder.clearCallingIdentity();
4456 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004457 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004458 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004459 } catch (ImsException e) {
4460 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4461 + "is inactive, ignoring unregister.");
4462 // If the subscription is no longer active, just return, since the callback
4463 // will already have been removed internally.
4464 } finally {
4465 Binder.restoreCallingIdentity(token);
4466 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 }
4468
4469 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004470 public boolean isCapable(int subId, int capability, int regTech) {
4471 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 final long token = Binder.clearCallingIdentity();
4473 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004474 int slotId = getSlotIndexOrException(subId);
4475 verifyImsMmTelConfiguredOrThrow(slotId);
4476 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4477 } catch (com.android.ims.ImsException e) {
4478 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4479 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004480 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004481 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4482 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 } finally {
4484 Binder.restoreCallingIdentity(token);
4485 }
4486 }
4487
4488 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004489 public boolean isAvailable(int subId, int capability, int regTech) {
4490 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 final long token = Binder.clearCallingIdentity();
4492 try {
4493 Phone phone = getPhone(subId);
4494 if (phone == null) return false;
4495 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004496 } catch (com.android.ims.ImsException e) {
4497 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4498 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 } finally {
4500 Binder.restoreCallingIdentity(token);
4501 }
4502 }
4503
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004504 /**
4505 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4506 * subscription.
4507 * @param subId The subscription to use to check the configuration.
4508 * @param callback The callback that will be used to send the result.
4509 * @param capability The MmTelFeature capability that will be used to send the result.
4510 * @param transportType The transport type of the MmTelFeature capability.
4511 */
4512 @Override
4513 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4514 int transportType) {
4515 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004516 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4517 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4518 "IMS not available on device.");
4519 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004520 final long token = Binder.clearCallingIdentity();
4521 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004522 int slotId = getSlotIndex(subId);
4523 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4524 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4525 + subId + "'");
4526 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4527 }
4528 verifyImsMmTelConfiguredOrThrow(slotId);
4529 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4530 transportType, aBoolean -> {
4531 try {
4532 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4533 } catch (RemoteException e) {
4534 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4535 + "running. Ignore");
4536 }
4537 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 } catch (ImsException e) {
4539 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004540 } finally {
4541 Binder.restoreCallingIdentity(token);
4542 }
4543 }
4544
shilu366312e2019-12-17 09:28:10 -08004545 /**
4546 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4547 * @param subId The subscription to use to check the configuration.
4548 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 @Override
4550 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004551 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004552 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004553
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 final long token = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(token);
4563 }
4564 }
4565
4566 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004567 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004569 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004570 final long identity = Binder.clearCallingIdentity();
4571 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004572 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004573 // This setting doesn't require an active ImsService connection, so do not verify. The
4574 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004576 } catch (ImsException e) {
4577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
4581 }
4582
shilu366312e2019-12-17 09:28:10 -08004583 /**
4584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4585 * @param subId The subscription to use to check the configuration.
4586 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004588 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004589 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004590 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004593 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004594 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004595 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (ImsException e) {
4597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
4601 }
4602
4603 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004604 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004606 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004607 final long identity = Binder.clearCallingIdentity();
4608 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004609 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004610 // This setting doesn't require an active ImsService connection, so do not verify. The
4611 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004612 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004613 } catch (ImsException e) {
4614 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
4618 }
4619
shilu366312e2019-12-17 09:28:10 -08004620 /**
4621 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4622 * @param subId The subscription to use to check the configuration.
4623 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004624 @Override
4625 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004626 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004627 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 final long identity = Binder.clearCallingIdentity();
4629 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004630 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004631 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004632 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004633 } catch (ImsException e) {
4634 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
4640 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004641 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004643 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004644 final long identity = Binder.clearCallingIdentity();
4645 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004646 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004647 // This setting doesn't require an active ImsService connection, so do not verify. The
4648 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004649 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004650 } catch (ImsException e) {
4651 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
4655 }
4656
shilu366312e2019-12-17 09:28:10 -08004657 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004658 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4659 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4660 * @param subId The subscription to use to check the configuration.
4661 */
4662 @Override
4663 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004664 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004665 mApp, subId, "isCrossSimCallingEnabledByUser");
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004668 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004669 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004671 } catch (ImsException e) {
4672 throw new ServiceSpecificException(e.getCode());
4673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
4676 }
4677
4678 /**
4679 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4680 * Requires MODIFY_PHONE_STATE permission.
4681 * @param subId The subscription to use to check the configuration.
4682 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4683 * false otherwise
4684 */
4685 @Override
4686 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4688 "setCrossSimCallingEnabled");
4689 final long identity = Binder.clearCallingIdentity();
4690 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004691 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004692 // This setting doesn't require an active ImsService connection, so do not verify. The
4693 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004694 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004695 } catch (ImsException e) {
4696 throw new ServiceSpecificException(e.getCode());
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
4700 }
4701
4702 /**
shilu366312e2019-12-17 09:28:10 -08004703 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4704 * @param subId The subscription to use to check the configuration.
4705 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004706 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004707
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004709 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004710 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004711 final long identity = Binder.clearCallingIdentity();
4712 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004713 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004714 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004715 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004716 } catch (ImsException e) {
4717 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
4723 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004724 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004726 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004727 final long identity = Binder.clearCallingIdentity();
4728 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004729 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004730 // This setting doesn't require an active ImsService connection, so do not verify. The
4731 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004732 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004733 } catch (ImsException e) {
4734 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 @Override
4741 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4743 "setVoWiFiNonPersistent");
4744 final long identity = Binder.clearCallingIdentity();
4745 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004746 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004747 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004748 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004749 } catch (ImsException e) {
4750 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
4754 }
4755
shilu366312e2019-12-17 09:28:10 -08004756 /**
4757 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4758 * @param subId The subscription to use to check the configuration.
4759 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 @Override
4761 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004762 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004763 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004764 final long identity = Binder.clearCallingIdentity();
4765 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004766 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004767 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004768 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004769 } catch (ImsException e) {
4770 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
4774 }
4775
4776 @Override
4777 public void setVoWiFiModeSetting(int subId, int mode) {
4778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4779 "setVoWiFiModeSetting");
4780 final long identity = Binder.clearCallingIdentity();
4781 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004782 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004783 // This setting doesn't require an active ImsService connection, so do not verify. The
4784 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004785 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004786 } catch (ImsException e) {
4787 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
4791 }
4792
4793 @Override
4794 public int getVoWiFiRoamingModeSetting(int subId) {
4795 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4796 final long identity = Binder.clearCallingIdentity();
4797 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004798 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004799 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004800 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004801 } catch (ImsException e) {
4802 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
4806 }
4807
4808 @Override
4809 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4811 "setVoWiFiRoamingModeSetting");
4812 final long identity = Binder.clearCallingIdentity();
4813 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004814 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004815 // This setting doesn't require an active ImsService connection, so do not verify. The
4816 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004817 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004818 } catch (ImsException e) {
4819 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
4823 }
4824
4825 @Override
4826 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4828 "setRttCapabilityEnabled");
4829 final long identity = Binder.clearCallingIdentity();
4830 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004831 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004832 // This setting doesn't require an active ImsService connection, so do not verify. The
4833 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004834 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004835 } catch (ImsException e) {
4836 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
4840 }
4841
shilu366312e2019-12-17 09:28:10 -08004842 /**
4843 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4844 * @param subId The subscription to use to check the configuration.
4845 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004846 @Override
4847 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004848 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004849 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004850 final long identity = Binder.clearCallingIdentity();
4851 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004852 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004853 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004854 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004855 } catch (ImsException e) {
4856 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
4860 }
4861
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004862 @Override
4863 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4864 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004865
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 final long identity = Binder.clearCallingIdentity();
4867 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004868 if (!isImsAvailableOnDevice()) {
4869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4870 "IMS not available on device.");
4871 }
4872 int slotId = getSlotIndexOrException(subId);
4873 verifyImsMmTelConfiguredOrThrow(slotId);
4874 ImsManager.getInstance(mApp, slotId)
4875 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004876 } catch (ImsException e) {
4877 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
4883 @Override
4884 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4885 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004886
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004887 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4889 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4890 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004892 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004893 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004894 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004895 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4896 + "is inactive, ignoring unregister.");
4897 // If the subscription is no longer active, just return, since the callback will already
4898 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
4902 }
4903
joonhunshincffb7fc2021-11-28 07:32:01 +00004904 @Override
4905 public void registerFeatureProvisioningChangedCallback(int subId,
4906 IFeatureProvisioningCallback callback) {
4907 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4908 mApp, subId, "registerFeatureProvisioningChangedCallback");
4909
4910 final long identity = Binder.clearCallingIdentity();
4911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4912 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4913 }
4914
joonhunshin91bc1952022-04-29 08:47:15 +00004915 try {
4916 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4917 if (controller == null) {
4918 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4919 "Device does not support IMS");
4920 }
4921 controller.addFeatureProvisioningChangedCallback(subId, callback);
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004925 }
4926
4927 @Override
4928 public void unregisterFeatureProvisioningChangedCallback(int subId,
4929 IFeatureProvisioningCallback callback) {
4930 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4931 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4932
4933 final long identity = Binder.clearCallingIdentity();
4934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4935 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4936 }
4937
joonhunshin91bc1952022-04-29 08:47:15 +00004938 try {
4939 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4940 if (controller == null) {
4941 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4942 return;
4943 }
4944 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004948 }
allenwtsu99c623b2020-01-03 18:24:23 +08004949
4950 private void checkModifyPhoneStatePermission(int subId, String message) {
4951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4952 message);
4953 }
4954
allenwtsu99c623b2020-01-03 18:24:23 +08004955 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004956 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004957 boolean isProvisioned) {
4958 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4959
4960 final long identity = Binder.clearCallingIdentity();
4961 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004962 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4963 if (controller == null) {
4964 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4965 return;
4966 }
4967 controller.setRcsProvisioningStatusForCapability(
4968 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
allenwtsu99c623b2020-01-03 18:24:23 +08004972 }
4973
4974
4975 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004976 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4977 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4978 mApp, subId, "getRcsProvisioningStatusForCapability");
4979
allenwtsu99c623b2020-01-03 18:24:23 +08004980 final long identity = Binder.clearCallingIdentity();
4981 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004982 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4983 if (controller == null) {
4984 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4985
4986 // device does not support IMS, this method will return true always.
4987 return true;
4988 }
4989 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
4993 }
4994
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004995 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4997 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004998 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004999
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005000 final long identity = Binder.clearCallingIdentity();
5001 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005002 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5003 if (controller == null) {
5004 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5005 return;
5006 }
5007 controller.setImsProvisioningStatusForCapability(
5008 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
5012 }
5013
5014 @Override
5015 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005016 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5017 mApp, subId, "getProvisioningStatusForCapability");
5018
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005019 final long identity = Binder.clearCallingIdentity();
5020 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005021 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5022 if (controller == null) {
5023 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005024
joonhunshin91bc1952022-04-29 08:47:15 +00005025 // device does not support IMS, this method will return true always.
5026 return true;
5027 }
5028 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
5032 }
5033
5034 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005035 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5036 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5037 mApp, subId, "isProvisioningRequiredForCapability");
5038
5039 final long identity = Binder.clearCallingIdentity();
5040 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005041 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5042 if (controller == null) {
5043 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5044
5045 // device does not support IMS, this method will return false
5046 return false;
5047 }
5048 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005049 } finally {
5050 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005051 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005052 }
5053
5054 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005055 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5056 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5057 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005058
joonhunshincffb7fc2021-11-28 07:32:01 +00005059 final long identity = Binder.clearCallingIdentity();
5060 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005061 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5062 if (controller == null) {
5063 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5064
5065 // device does not support IMS, this method will return false
5066 return false;
5067 }
5068 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005072 }
5073
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005074 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005075 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5077 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5078 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005079 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5080 mApp, subId, "getImsProvisioningInt");
5081
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005085 int slotId = getSlotIndex(subId);
5086 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5087 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5088 + subId + "' for key:" + key);
5089 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5090 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005091
joonhunshin91bc1952022-04-29 08:47:15 +00005092 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5093 if (controller == null) {
5094 loge("getImsProvisioningInt: Device does not support IMS");
5095
5096 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5097 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5098 }
5099 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005100 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5101 return retVal;
5102 }
5103
calvinpanb5a34062021-02-08 19:59:36 +08005104 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005105 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005106 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5107 + subId + "' for key:" + key);
5108 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
5112 }
5113
5114 @Override
5115 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5117 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5118 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005119 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5120 mApp, subId, "getImsProvisioningString");
5121
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005125 int slotId = getSlotIndex(subId);
5126 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5127 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5128 + subId + "' for key:" + key);
5129 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5130 }
calvinpanb5a34062021-02-08 19:59:36 +08005131 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005132 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005133 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5134 + subId + "' for key:" + key);
5135 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
5139 }
5140
5141 @Override
5142 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005143 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5144 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5145 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5147 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005148
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005152 int slotId = getSlotIndex(subId);
5153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5154 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5155 + subId + "' for key:" + key);
5156 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5157 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005158
joonhunshin91bc1952022-04-29 08:47:15 +00005159 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5160 if (controller == null) {
5161 loge("setImsProvisioningInt: Device does not support IMS");
5162
5163 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5164 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5165 }
5166 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005167 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5168 return retVal;
5169 }
5170
calvinpanb5a34062021-02-08 19:59:36 +08005171 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5172 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005173 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005174 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005175 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 @Override
5182 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005183 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5184 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5185 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5187 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005188 final long identity = Binder.clearCallingIdentity();
5189 try {
5190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005191 int slotId = getSlotIndex(subId);
5192 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5193 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5194 + subId + "' for key:" + key);
5195 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5196 }
calvinpanb5a34062021-02-08 19:59:36 +08005197 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5198 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005199 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005200 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005201 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
5205 }
5206
Brad Ebinger919631e2021-06-02 17:46:35 -07005207 /**
5208 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5209 * for the given slot ID or no ImsResolver instance has been created.
5210 * @param slotId The slot ID that the IMS service is created for.
5211 * @throws ImsException If there is no ImsService configured for this slot.
5212 */
5213 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5214 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5215 ImsFeature.FEATURE_MMTEL)) {
5216 throw new ImsException("This subscription does not support MMTEL over IMS",
5217 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5218 }
5219 }
5220
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005221 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005222 int slotId = SubscriptionManager.getSlotIndex(subId);
5223 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005224 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5225 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 }
5227 return slotId;
5228 }
5229
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005230 private int getSlotIndex(int subId) {
5231 int slotId = SubscriptionManager.getSlotIndex(subId);
5232 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5233 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5234 }
5235 return slotId;
5236 }
5237
Wink Saville36469e72014-06-11 15:17:00 -07005238 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005239 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005240 */
5241 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005242 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5243 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005244 try {
5245 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5246 } catch (SecurityException se) {
5247 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5248 throw new SecurityException("Package " + callingPackage + " does not belong to "
5249 + Binder.getCallingUid());
5250 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005251 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005252 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005253 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005254 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005255 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005256 mApp, subId, callingPackage, callingFeatureId,
5257 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5259 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 final Phone phone = getPhone(subId);
5264 if (phone != null) {
5265 return phone.getServiceState().getDataNetworkType();
5266 } else {
5267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5268 }
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005272 }
5273
5274 /**
5275 * Returns the data network type
5276 */
5277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005278 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005279 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005280 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005281 }
5282
5283 /**
5284 * Returns the data network type for a subId
5285 */
5286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005287 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5288 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005289 String functionName = "getDataNetworkTypeForSubscriber";
5290 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5291 mApp, functionName)) {
5292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5293 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5294 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5295 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005296 }
5297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 final long identity = Binder.clearCallingIdentity();
5299 try {
5300 final Phone phone = getPhone(subId);
5301 if (phone != null) {
5302 return phone.getServiceState().getDataNetworkType();
5303 } else {
5304 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5305 }
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005309 }
5310
5311 /**
Wink Saville36469e72014-06-11 15:17:00 -07005312 * Returns the Voice network type for a subId
5313 */
5314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005315 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5316 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005317 String functionName = "getVoiceNetworkTypeForSubscriber";
5318 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5319 mApp, functionName)) {
5320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5321 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5322 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5323 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005324 }
5325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 final Phone phone = getPhone(subId);
5329 if (phone != null) {
5330 return phone.getServiceState().getVoiceNetworkType();
5331 } else {
5332 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5333 }
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005337 }
5338
5339 /**
5340 * @return true if a ICC card is present
5341 */
5342 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005343 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005344 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005345 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005346 }
5347
5348 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005349 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005350 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005351 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005352 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 final Phone phone = PhoneFactory.getPhone(slotIndex);
5356 if (phone != null) {
5357 return phone.getIccCard().hasIccCard();
5358 } else {
5359 return false;
5360 }
5361 } finally {
5362 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005364 }
5365
5366 /**
5367 * Return if the current radio is LTE on CDMA. This
5368 * is a tri-state return value as for a period of time
5369 * the mode may be unknown.
5370 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005371 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005372 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005373 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005374 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005375 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005376 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5377 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5378 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005379 }
5380
Sanket Padawe356d7632015-06-22 14:03:32 -07005381 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005382 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5383 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005384 try {
5385 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5386 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005387 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5388 }
5389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 final Phone phone = getPhone(subId);
5393 if (phone == null) {
5394 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5395 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005396 return TelephonyProperties.lte_on_cdma_device()
5397 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 }
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005401 }
Wink Saville36469e72014-06-11 15:17:00 -07005402 }
5403
Wink Saville36469e72014-06-11 15:17:00 -07005404 /**
5405 * {@hide}
5406 * Returns Default subId, 0 in the case of single standby.
5407 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005408 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005409 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005410 }
5411
Shishir Agrawala9f32182016-04-12 12:00:16 -07005412 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005413 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005414 }
5415
Wink Savilleb564aae2014-10-23 10:18:09 -07005416 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005417 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005418 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005419
Pengquan Menge92a50d2018-09-21 15:54:48 -07005420 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005421 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5422 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5423 mApp.getOpPackageName(), mApp.getFeatureId());
5424 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005425 return mSubscriptionController.isActiveSubId(subId);
5426 }
5427
Ihab Awadf2177b72013-11-25 13:33:23 -08005428 /**
5429 * @see android.telephony.TelephonyManager.WifiCallingChoices
5430 */
5431 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005434 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5436 getWhenToMakeWifiCallsDefaultPreference());
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005440 }
5441
5442 /**
5443 * @see android.telephony.TelephonyManager.WifiCallingChoices
5444 */
5445 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
5448 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005449 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005454 }
5455
Sailesh Nepald1e68152013-12-12 19:08:02 -08005456 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005457 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005458 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005459 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005460
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005461 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5462 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5463 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005464 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005465 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5466 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005467 }
5468 return PhoneFactory.getPhone(phoneId);
5469 }
5470
Shishir Agrawal566b7612013-10-28 14:41:00 -07005471 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005472 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005473 @NonNull IccLogicalChannelRequest request) {
5474 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5475 /*message=*/ "iccOpenLogicalChannel");
5476
5477 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5478 // Verify that the callingPackage in the request belongs to the calling UID
5479 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5480
5481 return iccOpenLogicalChannelWithPermission(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 Phone getPhoneFromValidIccLogicalChannelRequest(
5485 @NonNull IccLogicalChannelRequest request, String message) {
5486 Phone phone;
5487 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5489 mApp, request.subId, message);
5490 phone = getPhoneFromSubId(request.subId);
5491 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5492 enforceModifyPermission();
5493 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5494 } else {
5495 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005496 }
Rambo Wanga1782702021-11-10 20:15:19 -08005497 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005498 }
5499
5500 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005501 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005504 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005506 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5507 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005508 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5509 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 loge("The calling package is not allowed to access ISD-R.");
5511 throw new SecurityException(
5512 "The calling package is not allowed to access ISD-R.");
5513 }
Derek Tan740e1672017-06-27 14:56:27 -07005514 }
Derek Tan740e1672017-06-27 14:56:27 -07005515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005517 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5518 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 return response;
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005523 }
5524
5525 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005526 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5527 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5528 /*message=*/"iccCloseLogicalChannel");
5529
5530 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5531
5532 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005534
Rambo Wanga1782702021-11-10 20:15:19 -08005535 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5536 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005537 // before this feature is enabled, this API should only return false if
5538 // the operation fails instead of throwing runtime exception for
5539 // backward-compatibility.
5540 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5541 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 final long identity = Binder.clearCallingIdentity();
5543 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005544 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005545 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 }
Chen Xue9d737e2022-01-01 23:41:31 -08005547 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005548 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005549 Boolean success = false;
5550 if (result instanceof RuntimeException) {
5551 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005552 if (shouldThrowExceptionOnFailure) {
5553 throw (RuntimeException) result;
5554 } else {
5555 return false;
5556 }
Chen Xue9d737e2022-01-01 23:41:31 -08005557 } else if (result instanceof Boolean) {
5558 success = (Boolean) result;
5559 } else {
5560 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5561 }
Rambo Wanga1782702021-11-10 20:15:19 -08005562 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 return success;
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005566 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005567 }
5568
5569 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005570 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005571 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5573 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005574 if (DBG) {
5575 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5576 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5577 + p3 + " data=" + data);
5578 }
5579 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5580 command, p1, p2, p3, data);
5581 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005582
Jordan Liu4c733742019-02-28 12:03:40 -08005583 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005584 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5585 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005586 enforceModifyPermission();
5587 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005588 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5589 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5590 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005591 }
5592 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005593 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5594 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005595 }
5596
5597 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5598 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 final long identity = Binder.clearCallingIdentity();
5600 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005601 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 return "";
5603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005606 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5607 null /* workSource */);
5608 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 // Append the returned status code to the end of the response payload.
5611 String s = Integer.toHexString(
5612 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5613 if (response.payload != null) {
5614 s = IccUtils.bytesToHexString(response.payload) + s;
5615 }
5616 return s;
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005619 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005620 }
Jake Hambye994d462014-02-03 13:10:13 -08005621
Evan Charltonc66da362014-05-16 14:06:40 -07005622 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005623 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5624 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005628 if (DBG) {
5629 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5630 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5631 }
5632 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5633 cla, command, p1, p2, p3, data);
5634 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005635
Jordan Liu4c733742019-02-28 12:03:40 -08005636 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005637 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5638 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005639 enforceModifyPermission();
5640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5641 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005642 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5643 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5644 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005645 }
5646
5647 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005648 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5649 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005650 }
5651
5652 // open APDU basic channel assuming the caller has sufficient permissions
5653 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5654 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5658 && TextUtils.equals(ISDR_AID, data)) {
5659 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005660 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5661 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662 if (bestComponent == null
5663 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5664 loge("The calling package is not allowed to select ISD-R.");
5665 throw new SecurityException(
5666 "The calling package is not allowed to select ISD-R.");
5667 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005668 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005671 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5672 null /* workSource */);
5673 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 // Append the returned status code to the end of the response payload.
5676 String s = Integer.toHexString(
5677 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5678 if (response.payload != null) {
5679 s = IccUtils.bytesToHexString(response.payload) + s;
5680 }
5681 return s;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005684 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005685 }
5686
5687 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005688 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005689 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 if (DBG) {
5696 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5697 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5698 }
5699
5700 IccIoResult response =
5701 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5702 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5703 subId);
5704
5705 if (DBG) {
5706 log("Exchange SIM_IO [R]" + response);
5707 }
5708
5709 byte[] result = null;
5710 int length = 2;
5711 if (response.payload != null) {
5712 length = 2 + response.payload.length;
5713 result = new byte[length];
5714 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5715 } else {
5716 result = new byte[length];
5717 }
5718
5719 result[length - 1] = (byte) response.sw2;
5720 result[length - 2] = (byte) response.sw1;
5721 return result;
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005724 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005725 }
5726
Nathan Haroldb3014052017-01-25 15:57:32 -08005727 /**
5728 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5729 * on a particular subscription
5730 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005731 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5732 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005734 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005735 return null;
5736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 if (appType != TelephonyManager.APPTYPE_USIM
5741 && appType != TelephonyManager.APPTYPE_SIM) {
5742 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5743 return null;
5744 }
5745 Object response = sendRequest(
5746 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5747 if (response instanceof String[]) {
5748 return (String[]) response;
5749 }
yincheng zhao2737e882019-09-06 17:06:54 -07005750 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005752 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005755 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005756 }
5757
yincheng zhao2737e882019-09-06 17:06:54 -07005758 /**
5759 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5760 * subscription.
5761 *
5762 * @param subId the id of the subscription.
5763 * @param appType the uicc app type, must be USIM or SIM.
5764 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5765 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005766 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005767 * @return number of fplmns that is successfully written to the SIM.
5768 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005769 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5770 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5772 mApp, subId, "setForbiddenPlmns");
5773
yincheng zhao2737e882019-09-06 17:06:54 -07005774 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5775 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5776 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5777 }
5778 if (fplmns == null) {
5779 throw new IllegalArgumentException("Fplmn List provided is null");
5780 }
5781 for (String fplmn : fplmns) {
5782 if (!CellIdentity.isValidPlmn(fplmn)) {
5783 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5784 }
5785 }
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 Object response = sendRequest(
5789 CMD_SET_FORBIDDEN_PLMNS,
5790 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5791 subId);
5792 return (int) response;
5793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
5796 }
5797
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005798 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005799 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5801 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5806 if (response.payload == null) {
5807 return "";
5808 }
Evan Charltonc66da362014-05-16 14:06:40 -07005809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 // Append the returned status code to the end of the response payload.
5811 String s = Integer.toHexString(
5812 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5813 s = IccUtils.bytesToHexString(response.payload) + s;
5814 return s;
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Evan Charltonc66da362014-05-16 14:06:40 -07005818 }
5819
Jake Hambye994d462014-02-03 13:10:13 -08005820 /**
5821 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5822 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5823 *
5824 * @param itemID the ID of the item to read
5825 * @return the NV item as a String, or null on error.
5826 */
5827 @Override
5828 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005829 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5831 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005836 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5838 return value;
5839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
Jake Hambye994d462014-02-03 13:10:13 -08005842 }
5843
5844 /**
5845 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5846 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5847 *
5848 * @param itemID the ID of the item to read
5849 * @param itemValue the value to write, as a String
5850 * @return true on success; false on any failure
5851 */
5852 @Override
5853 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005854 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5856 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5861 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005862 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5864 return success;
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
Jake Hambye994d462014-02-03 13:10:13 -08005868 }
5869
5870 /**
5871 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5872 * Used for device configuration by some CDMA operators.
5873 *
5874 * @param preferredRoamingList byte array containing the new PRL
5875 * @return true on success; false on any failure
5876 */
5877 @Override
5878 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5880 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5885 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5886 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5887 return success;
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
Jake Hambye994d462014-02-03 13:10:13 -08005891 }
5892
5893 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005894 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005895 * Used for device configuration by some CDMA operators.
5896 *
chen xu6dac5ab2018-10-26 17:39:23 -07005897 * @param slotIndex - device slot.
5898 *
Jake Hambye994d462014-02-03 13:10:13 -08005899 * @return true on success; false on any failure
5900 */
5901 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005902 public boolean resetModemConfig(int slotIndex) {
5903 Phone phone = PhoneFactory.getPhone(slotIndex);
5904 if (phone != null) {
5905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5906 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907
chen xu6dac5ab2018-10-26 17:39:23 -07005908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5911 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5912 return success;
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 }
chen xu6dac5ab2018-10-26 17:39:23 -07005917 return false;
5918 }
5919
5920 /**
5921 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5922 *
5923 * @param slotIndex - device slot.
5924 *
5925 * @return true on success; false on any failure
5926 */
5927 @Override
5928 public boolean rebootModem(int slotIndex) {
5929 Phone phone = PhoneFactory.getPhone(slotIndex);
5930 if (phone != null) {
5931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5932 mApp, phone.getSubId(), "rebootModem");
5933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
5936 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5937 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5938 return success;
5939 } finally {
5940 Binder.restoreCallingIdentity(identity);
5941 }
5942 }
5943 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005944 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005945
Brad Ebinger51f743a2017-01-23 13:50:20 -08005946 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005947 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5948 * {@link #disableIms(int)}.
5949 * @param slotIndex device slot.
5950 */
5951 public void resetIms(int slotIndex) {
5952 enforceModifyPermission();
5953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 if (mImsResolver == null) {
5957 // may happen if the does not support IMS.
5958 return;
5959 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005960 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
5964 }
5965
5966 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005967 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5968 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005969 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005970 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005971 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972
5973 final long identity = Binder.clearCallingIdentity();
5974 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005975 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005976 // may happen if the device does not support IMS.
5977 return;
5978 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005979 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 } finally {
5981 Binder.restoreCallingIdentity(identity);
5982 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005983 }
5984
5985 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005986 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5987 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005988 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005989 public void disableIms(int slotId) {
5990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991
5992 final long identity = Binder.clearCallingIdentity();
5993 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005994 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005995 // may happen if the device does not support IMS.
5996 return;
5997 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005998 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006002 }
6003
6004 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006005 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6006 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006007 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006008 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006009 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006010 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006014 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006015 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6016 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006017 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006018 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006022 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006023 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006024 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6025 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006026 @Override
6027 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006028 enforceModifyPermission();
6029
6030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006033 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
6037 }
6038
6039 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006040 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006041 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006042 */
6043 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6044 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045
6046 final long identity = Binder.clearCallingIdentity();
6047 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006048 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006049 // may happen if the device does not support IMS.
6050 return null;
6051 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006052 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006056 }
6057
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006058 /**
6059 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006060 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006061 */
6062 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064
6065 final long identity = Binder.clearCallingIdentity();
6066 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006067 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006068 // may happen if the device does not support IMS.
6069 return null;
6070 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006071 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 } finally {
6073 Binder.restoreCallingIdentity(identity);
6074 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006075 }
6076
Brad Ebinger884c07b2018-02-15 16:17:40 -08006077 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006078 * Sets the ImsService Package Name that Telephony will bind to.
6079 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006080 * @param slotIndex the slot ID that the ImsService should bind for.
6081 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006082 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006083 * @param featureTypes An integer array of feature types associated with a packageName.
6084 * @param packageName The name of the package that the current configuration will be replaced
6085 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006086 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006087 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006088 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6089 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006092 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 final long identity = Binder.clearCallingIdentity();
6095 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006096 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006097 // may happen if the device does not support IMS.
6098 return false;
6099 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006100 Map<Integer, String> featureConfig = new HashMap<>();
6101 for (int featureType : featureTypes) {
6102 featureConfig.put(featureType, packageName);
6103 }
6104 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6105 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006109 }
6110
6111 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006112 * Clears any carrier ImsService overrides for the slot index specified that were previously
6113 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6114 *
6115 * This should only be used for testing.
6116 *
6117 * @param slotIndex the slot ID that the ImsService should bind for.
6118 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6119 */
6120 @Override
6121 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6123 "clearCarrierImsServiceOverride");
6124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006125 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 if (mImsResolver == null) {
6130 // may happen if the device does not support IMS.
6131 return false;
6132 }
6133 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006140 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006141 *
6142 * @param slotId The slot that the ImsService is associated with.
6143 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6144 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006145 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006146 * @return the package name of the ImsService configuration.
6147 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006148 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6149 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006150 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006151 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6152 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 final long identity = Binder.clearCallingIdentity();
6155 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006156 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006157 // may happen if the device does not support IMS.
6158 return "";
6159 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006160 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006161 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6162 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006166 }
6167
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006168 /**
6169 * Get the MmTelFeature state associated with the requested subscription id.
6170 * @param subId The subscription that the MmTelFeature is associated with.
6171 * @param callback A callback with an integer containing the
6172 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6173 */
6174 @Override
6175 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6176 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006177 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6178 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6179 "IMS not available on device.");
6180 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006181 final long token = Binder.clearCallingIdentity();
6182 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006183 int slotId = getSlotIndex(subId);
6184 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6185 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6186 + subId + "'");
6187 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6188 }
6189 verifyImsMmTelConfiguredOrThrow(slotId);
6190 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6191 try {
6192 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6193 } catch (RemoteException e) {
6194 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6195 + "Ignore");
6196 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006197 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006198 } catch (ImsException e) {
6199 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006200 } finally {
6201 Binder.restoreCallingIdentity(token);
6202 }
6203 }
6204
Daniel Brightbb5840b2021-01-12 15:48:18 -08006205 /**
6206 * Sets the ims registration state on all valid {@link Phone}s.
6207 */
6208 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210
6211 final long identity = Binder.clearCallingIdentity();
6212 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006213 // NOTE: Before S, this method only set the default phone.
6214 for (final Phone phone : PhoneFactory.getPhones()) {
6215 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6216 phone.setImsRegistrationState(registered);
6217 }
6218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 } finally {
6220 Binder.restoreCallingIdentity(identity);
6221 }
Wink Saville36469e72014-06-11 15:17:00 -07006222 }
6223
6224 /**
Stuart Scott54788802015-03-30 13:18:01 -07006225 * Set the network selection mode to automatic.
6226 *
6227 */
6228 @Override
6229 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6231 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232
6233 final long identity = Binder.clearCallingIdentity();
6234 try {
shilufc958392020-01-20 11:36:01 -08006235 if (!isActiveSubscription(subId)) {
6236 return;
6237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006239 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6240 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 } finally {
6242 Binder.restoreCallingIdentity(identity);
6243 }
Stuart Scott54788802015-03-30 13:18:01 -07006244 }
6245
Jack Yud10cdd42020-09-28 20:28:01 -07006246 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006247 * Ask the radio to connect to the input network and change selection mode to manual.
6248 *
6249 * @param subId the id of the subscription.
6250 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6251 * the operator to attach to.
6252 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6253 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6254 * normal network selection next time.
6255 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006256 */
6257 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006258 public boolean setNetworkSelectionModeManual(
6259 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6261 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006262
Jack Yu285100e2022-12-02 22:48:35 -08006263 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006264 if (!isActiveSubscription(subId)) {
6265 return false;
6266 }
6267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006269 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006271 if (DBG) {
6272 log("setNetworkSelectionModeManual: subId: " + subId
6273 + " operator: " + operatorInfo);
6274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6276 } finally {
6277 Binder.restoreCallingIdentity(identity);
6278 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006279 }
shilu84f6e8b2019-12-19 13:58:01 -08006280 /**
6281 * Get the manual network selection
6282 *
6283 * @param subId the id of the subscription.
6284 *
6285 * @return the previously saved user selected PLMN
6286 */
6287 @Override
6288 public String getManualNetworkSelectionPlmn(int subId) {
6289 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006290 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006291 mApp, subId, "getManualNetworkSelectionPlmn");
6292
6293 final long identity = Binder.clearCallingIdentity();
6294 try {
6295 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006296 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006297 }
6298
6299 final Phone phone = getPhone(subId);
6300 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006301 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006302 }
6303 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6304 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6305 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006310
6311 /**
6312 * Scans for available networks.
6313 */
6314 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006315 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6316 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6318 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006319 LocationAccessPolicy.LocationPermissionResult locationResult =
6320 LocationAccessPolicy.checkLocationPermission(mApp,
6321 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6322 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006323 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006324 .setCallingPid(Binder.getCallingPid())
6325 .setCallingUid(Binder.getCallingUid())
6326 .setMethod("getCellNetworkScanResults")
6327 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006328 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6329 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006330 .build());
6331 switch (locationResult) {
6332 case DENIED_HARD:
6333 throw new SecurityException("Not allowed to access scan results -- location");
6334 case DENIED_SOFT:
6335 return null;
6336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337
Pengquan Menga1bb6272018-09-06 09:59:22 -07006338 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 try {
6340 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006341 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006346 }
6347
6348 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006349 * Get the call forwarding info, given the call forwarding reason.
6350 */
6351 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006352 public void getCallForwarding(int subId, int callForwardingReason,
6353 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006354 enforceReadPrivilegedPermission("getCallForwarding");
6355 long identity = Binder.clearCallingIdentity();
6356 try {
6357 if (DBG) {
6358 log("getCallForwarding: subId " + subId
6359 + " callForwardingReason" + callForwardingReason);
6360 }
Hall Liu27d24262020-09-18 19:04:59 -07006361
6362 Phone phone = getPhone(subId);
6363 if (phone == null) {
6364 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006365 callback.onError(
6366 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006367 } catch (RemoteException e) {
6368 // ignore
6369 }
6370 return;
6371 }
6372
6373 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6374 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6375 @Override
6376 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6377 try {
6378 callback.onCallForwardingInfoAvailable(info);
6379 } catch (RemoteException e) {
6380 // ignore
6381 }
6382 }
6383
6384 @Override
6385 public void onError(int error) {
6386 try {
6387 callback.onError(error);
6388 } catch (RemoteException e) {
6389 // ignore
6390 }
6391 }
6392 });
6393 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
6397 }
6398
6399 /**
6400 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6401 * reason, the number to forward, and the timeout before the forwarding is attempted.
6402 */
6403 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006404 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6405 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006406 enforceModifyPermission();
6407 long identity = Binder.clearCallingIdentity();
6408 try {
6409 if (DBG) {
6410 log("setCallForwarding: subId " + subId
6411 + " callForwardingInfo" + callForwardingInfo);
6412 }
Hall Liu27d24262020-09-18 19:04:59 -07006413
6414 Phone phone = getPhone(subId);
6415 if (phone == null) {
6416 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006417 callback.accept(
6418 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006419 } catch (RemoteException e) {
6420 // ignore
6421 }
6422 return;
6423 }
6424
6425 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6426 FunctionalUtils.ignoreRemoteException(callback::accept));
6427
6428 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
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 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006436 */
6437 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006438 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006439 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006440 long identity = Binder.clearCallingIdentity();
6441 try {
Hall Liu27d24262020-09-18 19:04:59 -07006442 Phone phone = getPhone(subId);
6443 if (phone == null) {
6444 try {
6445 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6446 } catch (RemoteException e) {
6447 // ignore
6448 }
6449 return;
6450 }
SongFerngWang0e767992021-03-31 22:08:45 +08006451 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6452 PersistableBundle c = configManager.getConfigForSubId(subId);
6453 boolean requireUssd = c.getBoolean(
6454 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006455
Shuo Qian4a594052020-01-23 11:59:30 -08006456 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006457 if (requireUssd) {
6458 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6459 getSubscriptionCarrierId(subId));
6460 String newUssdCommand = "";
6461 try {
6462 newUssdCommand = carrierXmlParser.getFeature(
6463 CarrierXmlParser.FEATURE_CALL_WAITING)
6464 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6465 } catch (NullPointerException e) {
6466 loge("Failed to generate USSD number" + e);
6467 }
6468 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6469 mMainThreadHandler, callback, carrierXmlParser,
6470 CarrierXmlParser.SsEntry.SSAction.QUERY);
6471 final String ussdCommand = newUssdCommand;
6472 Executors.newSingleThreadExecutor().execute(() -> {
6473 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6474 });
6475 } else {
6476 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6477 callback::accept);
6478 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6479 }
Shuo Qian4a594052020-01-23 11:59:30 -08006480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
6483 }
6484
6485 /**
Hall Liu27d24262020-09-18 19:04:59 -07006486 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006487 */
6488 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006489 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006490 enforceModifyPermission();
6491 long identity = Binder.clearCallingIdentity();
6492 try {
Hall Liu27d24262020-09-18 19:04:59 -07006493 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6494
6495 Phone phone = getPhone(subId);
6496 if (phone == null) {
6497 try {
6498 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6499 } catch (RemoteException e) {
6500 // ignore
6501 }
6502 return;
6503 }
6504
SongFerngWang0e767992021-03-31 22:08:45 +08006505 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6506 PersistableBundle c = configManager.getConfigForSubId(subId);
6507 boolean requireUssd = c.getBoolean(
6508 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006509
SongFerngWang0e767992021-03-31 22:08:45 +08006510 if (DBG) log("getCallWaitingStatus: subId " + subId);
6511 if (requireUssd) {
6512 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6513 getSubscriptionCarrierId(subId));
6514 CarrierXmlParser.SsEntry.SSAction ssAction =
6515 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6516 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6517 String newUssdCommand = "";
6518 try {
6519 newUssdCommand = carrierXmlParser.getFeature(
6520 CarrierXmlParser.FEATURE_CALL_WAITING)
6521 .makeCommand(ssAction, null);
6522 } catch (NullPointerException e) {
6523 loge("Failed to generate USSD number" + e);
6524 }
6525 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6526 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6527 final String ussdCommand = newUssdCommand;
6528 Executors.newSingleThreadExecutor().execute(() -> {
6529 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6530 });
6531 } else {
6532 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6533 FunctionalUtils.ignoreRemoteException(callback::accept));
6534
6535 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6536 }
Shuo Qian4a594052020-01-23 11:59:30 -08006537 } finally {
6538 Binder.restoreCallingIdentity(identity);
6539 }
6540 }
6541
6542 /**
yinxub1bed742017-04-17 11:45:04 -07006543 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006544 *
yinxub1bed742017-04-17 11:45:04 -07006545 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006546 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6547 * location related information which will be sent if the caller already possess
6548 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006549 * @param request contains the radio access networks with bands/channels to scan
6550 * @param messenger callback messenger for scan results or errors
6551 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006552 * @return the id of the requested scan which can be used to stop the scan.
6553 */
6554 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006555 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6556 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006557 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6559 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006560 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006561 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6562 if (!renounceFineLocationAccess) {
6563 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6564 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6565 .setCallingPackage(callingPackage)
6566 .setCallingFeatureId(callingFeatureId)
6567 .setCallingPid(Binder.getCallingPid())
6568 .setCallingUid(Binder.getCallingUid())
6569 .setMethod("requestNetworkScan")
6570 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6571 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6572 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6573 .build());
6574 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006575 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006576 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6577 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006578 if (e != null) {
6579 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6580 throw e;
6581 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006582 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006583 return TelephonyScanManager.INVALID_SCAN_ID;
6584 }
6585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 }
Hall Liu912dfd32019-04-25 14:02:26 -07006587 int callingUid = Binder.getCallingUid();
6588 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006592 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006593 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
yinxu504e1392017-04-12 16:03:22 -07006597 }
6598
Hall Liub2ac8ef2019-02-28 15:56:23 -08006599 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006600 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006601 boolean hasCarrierPriv;
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6605 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
Hall Liu558027f2019-05-15 19:14:05 -07006609 boolean hasNetworkScanPermission =
6610 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6611 == PERMISSION_GRANTED;
6612
6613 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6614 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6615 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006616 }
6617
6618 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6619 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006620 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6621 return new SecurityException("Specific channels must not be"
6622 + " scanned without location access.");
6623 }
6624 }
6625 }
6626
Hall Liub2ac8ef2019-02-28 15:56:23 -08006627 return null;
6628 }
6629
yinxu504e1392017-04-12 16:03:22 -07006630 /**
6631 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006632 *
6633 * @param subId id of the subscription
6634 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006635 */
6636 @Override
6637 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6639 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640
Hall Liu912dfd32019-04-25 14:02:26 -07006641 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 final long identity = Binder.clearCallingIdentity();
6643 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006644 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 } finally {
6646 Binder.restoreCallingIdentity(identity);
6647 }
yinxu504e1392017-04-12 16:03:22 -07006648 }
6649
6650 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006651 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006652 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006653 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006654 */
6655 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006656 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006657 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660
6661 final long identity = Binder.clearCallingIdentity();
6662 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006663 if (DBG) log("getAllowedNetworkTypesBitmask");
6664 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6665 int networkTypesBitmask = (result != null ? result[0] : -1);
6666 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6667 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006671 }
6672
6673 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006674 * Get the allowed network types for certain reason.
6675 *
6676 * @param subId the id of the subscription.
6677 * @param reason the reason the allowed network type change is taking place
6678 * @return the allowed network types.
6679 */
6680 @Override
6681 public long getAllowedNetworkTypesForReason(int subId,
6682 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006683 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006684 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006685 final long identity = Binder.clearCallingIdentity();
6686 try {
6687 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
6690 }
6691 }
6692
6693 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006694 * Enable/Disable E-UTRA-NR Dual Connectivity
6695 * @param subId subscription id of the sim card
6696 * @param nrDualConnectivityState expected NR dual connectivity state
6697 * This can be passed following states
6698 * <ol>
6699 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6700 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6701 * <li>Disable NR dual connectivity and force secondary cell to be released
6702 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6703 * </ol>
6704 * @return operation result.
6705 */
6706 @Override
6707 public int setNrDualConnectivityState(int subId,
6708 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6710 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006711 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006712 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6713 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6714 }
6715
Sooraj Sasindran37444802020-08-11 10:40:43 -07006716 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
6719 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6720 nrDualConnectivityState, subId,
6721 workSource);
6722 if (DBG) log("enableNRDualConnectivity result: " + result);
6723 return result;
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
6727 }
6728
6729 /**
6730 * Is E-UTRA-NR Dual Connectivity enabled
6731 * @return true if dual connectivity is enabled else false
6732 */
6733 @Override
6734 public boolean isNrDualConnectivityEnabled(int subId) {
6735 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006736 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006737 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006738 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006739 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6740 return false;
6741 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006742 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6746 null, subId, workSource);
6747 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6748 return isEnabled;
6749 } finally {
6750 Binder.restoreCallingIdentity(identity);
6751 }
6752 }
6753
6754 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006755 * Set the allowed network types of the device and
6756 * provide the reason triggering the allowed network change.
6757 *
6758 * @param subId the id of the subscription.
6759 * @param reason the reason the allowed network type change is taking place
6760 * @param allowedNetworkTypes the allowed network types.
6761 * @return true on success; false on any failure.
6762 */
6763 @Override
6764 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006765 @TelephonyManager.AllowedNetworkTypesReason int reason,
6766 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6768 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006769 // If the caller only has carrier privileges, then they should not be able to override
6770 // any network types which were set for security reasons.
6771 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6772 != PERMISSION_GRANTED
6773 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6774 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6775 throw new SecurityException(
6776 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6777 + " reason "
6778 + reason);
6779 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006780 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006781 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6782 return false;
6783 }
6784 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6785 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006786 return false;
6787 }
6788
Jack Yue37dd262022-12-16 11:53:37 -08006789 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006790 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6791
Jack Yue37dd262022-12-16 11:53:37 -08006792 Phone phone = getPhone(subId);
6793 if (phone == null) {
6794 return false;
6795 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006796
Jack Yue37dd262022-12-16 11:53:37 -08006797 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006798 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6799 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006800 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006801
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006802 final long identity = Binder.clearCallingIdentity();
6803 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006804 Boolean success = (Boolean) sendRequest(
6805 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6806 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6807
6808 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6809 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
6813 }
6814
6815 /**
Miaoa84611c2019-03-15 09:21:10 +08006816 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006817 *
Miaoa84611c2019-03-15 09:21:10 +08006818 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006819 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006820 * @hide
6821 */
6822 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006823 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006824 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006826 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 try {
Miaoa84611c2019-03-15 09:21:10 +08006828 if (phone != null) {
6829 return phone.hasMatchedTetherApnSetting();
6830 } else {
6831 return false;
6832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 } finally {
6834 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006835 }
Junda Liu475951f2014-11-07 16:45:03 -08006836 }
6837
6838 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006839 * Get the user enabled state of Mobile Data.
6840 *
6841 * TODO: remove and use isUserDataEnabled.
6842 * This can't be removed now because some vendor codes
6843 * calls through ITelephony directly while they should
6844 * use TelephonyManager.
6845 *
6846 * @return true on enabled
6847 */
6848 @Override
6849 public boolean getDataEnabled(int subId) {
6850 return isUserDataEnabled(subId);
6851 }
6852
6853 /**
6854 * Get whether mobile data is enabled per user setting.
6855 *
6856 * There are other factors deciding whether mobile data is actually enabled, but they are
6857 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006858 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006859 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6860 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006861 *
6862 * @return {@code true} if data is enabled else {@code false}
6863 */
6864 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006865 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006866 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006867 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006868 try {
6869 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6870 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006871 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006872 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6873 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006874 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006876 mApp, subId, functionName);
6877
Robert Greenwalt646120a2014-05-23 11:54:03 -07006878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879
6880 final long identity = Binder.clearCallingIdentity();
6881 try {
Jack Yu285100e2022-12-02 22:48:35 -08006882 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6884 Phone phone = PhoneFactory.getPhone(phoneId);
6885 if (phone != null) {
6886 boolean retVal = phone.isUserDataEnabled();
6887 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6888 return retVal;
6889 } else {
6890 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6891 return false;
6892 }
6893 } finally {
6894 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006895 }
6896 }
6897
6898 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006899 * Checks if the device is capable of mobile data by considering whether whether the
6900 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6901 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006902 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006903 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006904 */
6905 @Override
6906 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006907 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006908 try {
6909 try {
6910 mApp.enforceCallingOrSelfPermission(
6911 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006912 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006913 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006914 try {
6915 mApp.enforceCallingOrSelfPermission(
6916 android.Manifest.permission.READ_PHONE_STATE,
6917 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006918 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006919 mApp.enforceCallingOrSelfPermission(
6920 permission.READ_BASIC_PHONE_STATE, functionName);
6921 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006922 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006923 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006924 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926
6927 final long identity = Binder.clearCallingIdentity();
6928 try {
Jack Yu285100e2022-12-02 22:48:35 -08006929 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 Phone phone = PhoneFactory.getPhone(phoneId);
6931 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006932 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006933 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 return retVal;
6935 } else {
6936 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6937 return false;
6938 }
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006941 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006942 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006943
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006944 /**
6945 * Check if data is enabled for a specific reason
6946 * @param subId Subscription index
6947 * @param reason the reason the data enable change is taking place
6948 * @return {@code true} if the overall data is enabled; {@code false} if not.
6949 */
6950 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006951 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006952 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006953 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006954 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006955 try {
6956 mApp.enforceCallingOrSelfPermission(
6957 android.Manifest.permission.ACCESS_NETWORK_STATE,
6958 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006959 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006960 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6961 functionName);
6962 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006963 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006964 try {
6965 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006966 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006967 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006969 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006970 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006971 }
6972
6973
6974 final long identity = Binder.clearCallingIdentity();
6975 try {
Jack Yu285100e2022-12-02 22:48:35 -08006976 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006977 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006978 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006979 + " reason=" + reason);
6980 }
6981 Phone phone = PhoneFactory.getPhone(phoneId);
6982 if (phone != null) {
6983 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006984 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006985 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006986 return retVal;
6987 } else {
6988 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006989 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006990 + subId + " retVal=false");
6991 }
6992 return false;
6993 }
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
6996 }
6997 }
6998
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006999 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007000 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007001 // No permission needed; this only lets the caller inspect their own status.
7002 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007003 }
Junda Liu29340342014-07-10 15:23:27 -07007004
7005 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007006 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007007 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007008 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7009 }
7010
7011 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7012 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007013 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007014 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007015 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7016 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007017 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7018 if (cpt == null) {
7019 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007020 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7021 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007022 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007023 }
7024
7025 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007026 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007027 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007028 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007029 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007030 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007031 Phone phone = getPhone(subId);
7032 if (phone == null) {
7033 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7034 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7035 }
7036 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7037 if (cpt == null) {
7038 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007039 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7040 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007041 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007042 }
7043
7044 @Override
7045 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007046 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007047 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7048 }
7049
7050 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007051 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007052 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007053 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007054 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007055 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7056 Phone phone = PhoneFactory.getPhone(phoneId);
7057 if (phone == null) {
7058 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007059 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007060 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7061 if (cpt == null) {
7062 continue;
7063 }
7064 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007065 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7066 break;
7067 }
7068 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007069 return result;
Junda Liu29340342014-07-10 15:23:27 -07007070 }
Derek Tan89e89d42014-07-08 17:00:10 -07007071
7072 @Override
Junda Liue64de782015-04-16 17:19:16 -07007073 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007074 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007075 Phone phone = PhoneFactory.getPhone(phoneId);
7076 if (phone == null) {
7077 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007078 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007079 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7080 if (cpt == null) {
7081 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007082 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007083 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007084 }
7085
Amith Yamasani6e118872016-02-19 12:53:51 -08007086 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007087 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007088 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007089 Phone phone = PhoneFactory.getPhone(phoneId);
7090 if (phone == null) {
7091 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007092 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007093 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7094 if (cpt == null) {
7095 return Collections.emptyList();
7096 }
7097 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007098 }
7099
chen xuf7e9fe82019-05-09 19:31:02 -07007100 @Override
7101 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007102 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007103 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007104 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007105 try {
7106 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7107 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7108 }
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007111 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007112 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007113 }
7114
Rambo Wang6812ffb2022-03-15 16:54:17 -07007115 @Override
7116 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7117 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7118
7119 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7120 if (phone == null) {
7121 return null;
7122 }
7123 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7124 if (cpt == null) {
7125 return null;
7126 }
7127 return cpt.getCarrierServicePackageName();
7128 }
7129
Wink Savilleb564aae2014-10-23 10:18:09 -07007130 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007131 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007132 UiccPort port = phone == null ? null : phone.getUiccPort();
7133 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007134 return null;
7135 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007136 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007137 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007138 return null;
7139 }
7140 return iccId;
7141 }
7142
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007143 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007144 public void setCallComposerStatus(int subId, int status) {
7145 enforceModifyPermission();
7146
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 Phone phone = getPhone(subId);
7150 if (phone != null) {
7151 Phone defaultPhone = phone.getImsPhone();
7152 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7153 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7154 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007155 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7156 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007157 }
7158 }
Shuo Qian284ae752020-12-22 19:10:14 -08007159 } catch (ImsException e) {
7160 throw new ServiceSpecificException(e.getCode());
7161 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007162 Binder.restoreCallingIdentity(identity);
7163 }
7164 }
7165
7166 @Override
7167 public int getCallComposerStatus(int subId) {
7168 enforceReadPrivilegedPermission("getCallComposerStatus");
7169
7170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 Phone phone = getPhone(subId);
7173 if (phone != null) {
7174 Phone defaultPhone = phone.getImsPhone();
7175 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7176 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7177 return imsPhone.getCallComposerStatus();
7178 }
7179 }
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
7183 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7184 }
7185
7186 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007187 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7188 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007189 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007190 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 final String iccId = getIccId(subId);
7195 final Phone phone = getPhone(subId);
7196 if (phone == null) {
7197 return false;
7198 }
7199 final String subscriberId = phone.getSubscriberId();
7200
7201 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007202 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 + subscriberId + " to " + number);
7204 }
7205
7206 if (TextUtils.isEmpty(iccId)) {
7207 return false;
7208 }
7209
7210 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7211
7212 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7213 if (alphaTag == null) {
7214 editor.remove(alphaTagPrefKey);
7215 } else {
7216 editor.putString(alphaTagPrefKey, alphaTag);
7217 }
7218
7219 // Record both the line number and IMSI for this ICCID, since we need to
7220 // track all merged IMSIs based on line number
7221 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7222 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7223 if (number == null) {
7224 editor.remove(numberPrefKey);
7225 editor.remove(subscriberPrefKey);
7226 } else {
7227 editor.putString(numberPrefKey, number);
7228 editor.putString(subscriberPrefKey, subscriberId);
7229 }
7230
7231 editor.commit();
7232 return true;
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007235 }
Derek Tan7226c842014-07-02 17:42:23 -07007236 }
7237
7238 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007239 public String getLine1NumberForDisplay(int subId, String callingPackage,
7240 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007241 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007243 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007244 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007245 return null;
7246 }
Derek Tan97ebb422014-09-05 16:55:38 -07007247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 String iccId = getIccId(subId);
7251 if (iccId != null) {
7252 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7253 if (DBG_MERGE) {
7254 log("getLine1NumberForDisplay returning "
7255 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7256 }
7257 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7260 return null;
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007263 }
Derek Tan7226c842014-07-02 17:42:23 -07007264 }
7265
7266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007267 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7268 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007270 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007271 return null;
7272 }
Derek Tan97ebb422014-09-05 16:55:38 -07007273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 String iccId = getIccId(subId);
7277 if (iccId != null) {
7278 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7279 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7280 }
7281 return null;
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007284 }
Derek Tan7226c842014-07-02 17:42:23 -07007285 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007286
7287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007288 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7289 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007290 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7291 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007293 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007294 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007295 return null;
7296 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007297
Jordan Liub49b04b2019-05-06 14:45:15 -07007298 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7299 // the process, where TelephonyManager was instantiated.
7300 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007301 final long identity = Binder.clearCallingIdentity();
7302 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007303 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304 final TelephonyManager tele = TelephonyManager.from(context);
7305 final SubscriptionManager sub = SubscriptionManager.from(context);
7306
7307 // Figure out what subscribers are currently active
7308 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309
Jordan Liub49b04b2019-05-06 14:45:15 -07007310 // Only consider subs which match the current subId
7311 // This logic can be simplified. See b/131189269 for progress.
7312 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007313 activeSubscriberIds.add(tele.getSubscriberId(subId));
7314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315
7316 // First pass, find a number override for an active subscriber
7317 String mergeNumber = null;
7318 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7319 for (String key : prefs.keySet()) {
7320 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7321 final String subscriberId = (String) prefs.get(key);
7322 if (activeSubscriberIds.contains(subscriberId)) {
7323 final String iccId = key.substring(
7324 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7325 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7326 mergeNumber = (String) prefs.get(numberKey);
7327 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007328 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 + " for active subscriber " + subscriberId);
7330 }
7331 if (!TextUtils.isEmpty(mergeNumber)) {
7332 break;
7333 }
7334 }
7335 }
7336 }
7337
7338 // Shortcut when no active merged subscribers
7339 if (TextUtils.isEmpty(mergeNumber)) {
7340 return null;
7341 }
7342
7343 // Second pass, find all subscribers under that line override
7344 final ArraySet<String> result = new ArraySet<>();
7345 for (String key : prefs.keySet()) {
7346 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7347 final String number = (String) prefs.get(key);
7348 if (mergeNumber.equals(number)) {
7349 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7350 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7351 final String subscriberId = (String) prefs.get(subscriberKey);
7352 if (!TextUtils.isEmpty(subscriberId)) {
7353 result.add(subscriberId);
7354 }
7355 }
7356 }
7357 }
7358
7359 final String[] resultArray = result.toArray(new String[result.size()]);
7360 Arrays.sort(resultArray);
7361 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007362 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7364 }
7365 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007368 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007369 }
7370
7371 @Override
zoey chen38003472019-12-13 17:16:31 +08007372 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7373 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007374
7375 final long identity = Binder.clearCallingIdentity();
7376 try {
7377 final TelephonyManager telephonyManager = mApp.getSystemService(
7378 TelephonyManager.class);
7379 String subscriberId = telephonyManager.getSubscriberId(subId);
7380 if (subscriberId == null) {
7381 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007382 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007383 + subId);
7384 }
7385 return null;
7386 }
7387
Jack Yu285100e2022-12-02 22:48:35 -08007388 ParcelUuid groupUuid;
7389 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7390 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7391 .getSubscriptionInfo(subId);
7392 groupUuid = info.getGroupUuid();
7393 } else {
7394 final SubscriptionInfo info = mSubscriptionController
7395 .getSubscriptionInfo(subId);
7396 groupUuid = info.getGroupUuid();
7397 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007398 // If it doesn't belong to any group, return just subscriberId of itself.
7399 if (groupUuid == null) {
7400 return new String[]{subscriberId};
7401 }
7402
7403 // Get all subscriberIds from the group.
7404 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007405 List<SubscriptionInfo> groupInfos;
7406 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7407 groupInfos = SubscriptionManagerService.getInstance()
7408 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7409 mApp.getAttributionTag());
7410 } else {
7411 groupInfos = mSubscriptionController
7412 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7413 mApp.getAttributionTag());
7414 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007415 for (SubscriptionInfo subInfo : groupInfos) {
7416 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7417 if (subscriberId != null) {
7418 mergedSubscriberIds.add(subscriberId);
7419 }
7420 }
7421
7422 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425
7426 }
7427 }
7428
7429 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007430 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007431 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007432 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433
7434 final long identity = Binder.clearCallingIdentity();
7435 try {
7436 final Phone phone = getPhone(subId);
7437 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007441 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007442
7443 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007444 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007445 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7446 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007447 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7448 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449
7450 final long identity = Binder.clearCallingIdentity();
7451 try {
7452 final Phone phone = getPhone(subId);
7453 if (phone == null) {
7454 return false;
7455 }
7456 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7457 cdmaNonRoamingList);
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007460 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007461 }
7462
7463 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007464 @Deprecated
7465 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7466 enforceModifyPermission();
7467
7468 int returnValue = 0;
7469 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007470 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007471 if(result.exception == null) {
7472 if (result.result != null) {
7473 byte[] responseData = (byte[])(result.result);
7474 if(responseData.length > oemResp.length) {
7475 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7476 responseData.length + "bytes. Buffer Size is " +
7477 oemResp.length + "bytes.");
7478 }
7479 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7480 returnValue = responseData.length;
7481 }
7482 } else {
7483 CommandException ex = (CommandException) result.exception;
7484 returnValue = ex.getCommandError().ordinal();
7485 if(returnValue > 0) returnValue *= -1;
7486 }
7487 } catch (RuntimeException e) {
7488 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7489 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7490 if(returnValue > 0) returnValue *= -1;
7491 }
7492
7493 return returnValue;
7494 }
7495
7496 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007497 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007498 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007499 try {
7500 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007501 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007502 mApp, phone.getSubId(), "getRadioAccessFamily");
7503 } catch (SecurityException e) {
7504 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7505 throw e;
7506 }
chen xub97461a2018-10-26 14:17:57 -07007507 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007508 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007509 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 final long identity = Binder.clearCallingIdentity();
7512 try {
chen xub97461a2018-10-26 14:17:57 -07007513 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007514 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007515 mApp, phone.getSubId(), "getRadioAccessFamily");
7516 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
chen xub97461a2018-10-26 14:17:57 -07007520 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007521 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007522
7523 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007524 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007525 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007526 try {
7527 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7528 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007529 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007530 }
7531 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007532 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007533 }
7534 RoleManager rm = mApp.getSystemService(RoleManager.class);
7535 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7536 if (!dialerRoleHolders.contains(callingPackage)) {
7537 throw new SecurityException("App must be the dialer role holder to"
7538 + " upload a call composer pic");
7539 }
7540
7541 Executors.newSingleThreadExecutor().execute(() -> {
7542 ByteArrayOutputStream output = new ByteArrayOutputStream(
7543 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7544 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7545 boolean readUntilEnd = false;
7546 int totalBytesRead = 0;
7547 byte[] buffer = new byte[16 * 1024];
7548 while (true) {
7549 int numRead;
7550 try {
7551 numRead = input.read(buffer);
7552 } catch (IOException e) {
7553 try {
7554 fd.checkError();
7555 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7556 null);
7557 } catch (IOException e1) {
7558 // This means that the other side closed explicitly with an error. If this
7559 // happens, log and ignore.
7560 loge("Remote end of call composer picture pipe closed: " + e1);
7561 }
7562 break;
7563 }
7564 if (numRead == -1) {
7565 readUntilEnd = true;
7566 break;
7567 }
7568 totalBytesRead += numRead;
7569 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7570 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7571 try {
7572 input.close();
7573 } catch (IOException e) {
7574 // ignore
7575 }
7576 break;
7577 }
7578 output.write(buffer, 0, numRead);
7579 }
7580 // Generally, the remote end will close the file descriptors. The only case where we
7581 // close is above, where the picture size is too big.
7582
7583 try {
7584 fd.checkError();
7585 } catch (IOException e) {
7586 loge("Remote end for call composer closed with an error: " + e);
7587 return;
7588 }
7589
Hall Liuaa4211e2021-01-20 15:43:39 -08007590 if (!readUntilEnd) {
7591 loge("Did not finish reading entire image; aborting");
7592 return;
7593 }
Hall Liu82694d52020-12-11 18:22:04 -08007594
Hall Liuaa4211e2021-01-20 15:43:39 -08007595 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7596 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7597 new CallComposerPictureTransfer.Factory() {},
7598 imageData,
7599 (result) -> {
7600 if (result.first != null) {
7601 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7602 Bundle outputResult = new Bundle();
7603 outputResult.putParcelable(
7604 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7605 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7606 outputResult);
7607 } else {
7608 callback.send(result.second, null);
7609 }
7610 }
7611 );
Hall Liu82694d52020-12-11 18:22:04 -08007612 });
7613 }
7614
7615 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007616 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007617 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007618 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007622 ImsManager.getInstance(defaultPhone.getContext(),
7623 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007627 }
7628
7629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007630 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007631 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7633 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007634 return false;
7635 }
Svet Ganovb320e182015-04-16 12:30:10 -07007636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 final long identity = Binder.clearCallingIdentity();
7638 try {
7639 // Check the user preference and the system-level IMS setting. Even if the user has
7640 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7641 // In the long run, we may instead need to check if there exists a connection service
7642 // which can support video calling.
7643 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007644 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 return imsManager.isVtEnabledByPlatform()
7646 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7647 && imsManager.isVtEnabledByUser();
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
7650 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007651 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007652
Andrew Leea1239f22015-03-02 17:44:07 -08007653 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007654 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7655 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007657 mApp, subId, callingPackage, callingFeatureId,
7658 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 return false;
7660 }
7661
7662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 CarrierConfigManager configManager =
7665 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007666 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
Andrew Leea1239f22015-03-02 17:44:07 -08007671 }
7672
7673 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007674 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007676 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 return false;
7678 }
7679
7680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 CarrierConfigManager configManager =
7683 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007684 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
Andrew Leea1239f22015-03-02 17:44:07 -08007689 }
7690
Andrew Lee9431b832015-03-09 18:46:45 -07007691 @Override
7692 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007693 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007694 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007695 }
7696
7697 @Override
7698 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 final long identity = Binder.clearCallingIdentity();
7700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007701 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
Andrew Lee9431b832015-03-09 18:46:45 -07007705 }
7706
Hall Liuf6668912018-10-31 17:05:23 -07007707 /**
7708 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7709 * support for the feature and device firmware support.
7710 *
7711 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7712 */
7713 @Override
7714 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007716 final Phone phone = getPhone(subscriptionId);
7717 if (phone == null) {
7718 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7719 return false;
7720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007722 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7724 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007725 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 return isCarrierSupported && isDeviceSupported;
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
Hall Liu98187582018-01-22 19:15:32 -08007730 }
7731
Hall Liuf6668912018-10-31 17:05:23 -07007732 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007733 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7734 * RTT setting, will return true if the device and carrier both support RTT.
7735 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007736 */
7737 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 final long identity = Binder.clearCallingIdentity();
7739 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007740 boolean isRttSupported = isRttSupported(subscriptionId);
7741 boolean isUserRttSettingOn = Settings.Secure.getInt(
7742 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7743 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7744 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7745 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 } finally {
7747 Binder.restoreCallingIdentity(identity);
7748 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007749 }
7750
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007751 @Deprecated
7752 @Override
7753 public String getDeviceId(String callingPackage) {
7754 return getDeviceIdWithFeature(callingPackage, null);
7755 }
7756
Sanket Padawe7310cc72015-01-14 09:53:20 -08007757 /**
7758 * Returns the unique device ID of phone, for example, the IMEI for
7759 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7760 *
7761 * <p>Requires Permission:
7762 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7763 */
7764 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007765 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007766 try {
7767 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7768 } catch (SecurityException se) {
7769 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7770 throw new SecurityException("Package " + callingPackage + " does not belong to "
7771 + Binder.getCallingUid());
7772 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007773 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007774 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007775 return null;
7776 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007777 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007778 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007779 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007780 return null;
7781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782
7783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 return phone.getDeviceId();
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007789 }
7790
Ping Sunc67b7c22016-03-02 19:16:45 +08007791 /**
7792 * {@hide}
7793 * Returns the IMS Registration Status on a particular subid
7794 *
7795 * @param subId
7796 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007797 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007798 Phone phone = getPhone(subId);
7799 if (phone != null) {
7800 return phone.isImsRegistered();
7801 } else {
7802 return false;
7803 }
7804 }
7805
Santos Cordon7a1885b2015-02-03 11:15:19 -08007806 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007807 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007808 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007810 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007811 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7812 }
7813 final long identity = Binder.clearCallingIdentity();
7814 try {
7815 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7816 } finally {
7817 Binder.restoreCallingIdentity(identity);
7818 }
7819 }
7820
7821 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007822 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007823 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007824 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007825 mApp,
7826 subscriptionId,
7827 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007828 final long identity = Binder.clearCallingIdentity();
7829 try {
7830 Phone phone = getPhone(subscriptionId);
7831 if (phone == null) {
7832 return null;
7833 }
7834 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
7838 }
7839
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007840 /**
7841 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007842 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007843 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 final long identity = Binder.clearCallingIdentity();
7845 try {
7846 Phone phone = getPhone(subId);
7847 if (phone != null) {
7848 return phone.isWifiCallingEnabled();
7849 } else {
7850 return false;
7851 }
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007854 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007855 }
7856
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007857 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007858 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007859 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007860 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 Phone phone = getPhone(subId);
7864 if (phone != null) {
7865 return phone.isVideoEnabled();
7866 } else {
7867 return false;
7868 }
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007871 }
7872 }
7873
7874 /**
7875 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7876 * defined in {@link ImsRegistrationImplBase}.
7877 */
7878 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879 final long identity = Binder.clearCallingIdentity();
7880 try {
7881 Phone phone = getPhone(subId);
7882 if (phone != null) {
7883 return phone.getImsRegistrationTech();
7884 } else {
7885 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7886 }
7887 } finally {
7888 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007889 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007890 }
7891
Stuart Scott8eef64f2015-04-08 15:13:54 -07007892 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007893 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007894 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007895 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7896 return;
7897 }
Kai Shif70f46f2021-03-03 13:59:46 -08007898 Phone defaultPhone = getDefaultPhone();
7899 if (defaultPhone != null) {
7900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7901 mApp, getDefaultPhone().getSubId(), "factoryReset");
7902 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007903 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007904
Svet Ganovcc087f82015-05-12 20:35:54 -07007905 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007906 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7907 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007908 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007909 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007910 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007911 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007912 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007913 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007914 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007915 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007916 // There has been issues when Sms raw table somehow stores orphan
7917 // fragments. They lead to garbled message when new fragments come
7918 // in and combined with those stale ones. In case this happens again,
7919 // user can reset all network settings which will clean up this table.
7920 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007921 // Clean up IMS settings as well here.
7922 int slotId = getSlotIndex(subId);
7923 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7924 ImsManager.getInstance(mApp, slotId).factoryReset();
7925 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007926
Kai Shif70f46f2021-03-03 13:59:46 -08007927 if (defaultPhone == null) {
7928 return;
7929 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007930 // Erase modem config if erase modem on network setting is enabled.
7931 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7932 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7933 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007934 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007935 }
Kai Shif70f46f2021-03-03 13:59:46 -08007936
7937 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007938 } finally {
7939 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007940 }
7941 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007942
SongFerngWangfd89b102021-05-27 22:44:54 +08007943 @VisibleForTesting
7944 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7945 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7946 return;
7947 }
7948 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7949 RILConstants.PREFERRED_NETWORK_MODE);
7950 SubscriptionManager.setSubscriptionProperty(subId,
7951 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7952 "user=" + defaultNetworkType);
7953 phone.loadAllowedNetworksFromSubscriptionDatabase();
7954 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7955 defaultNetworkType, null);
7956 }
7957
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007958 private void cleanUpSmsRawTable(Context context) {
7959 ContentResolver resolver = context.getContentResolver();
7960 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7961 resolver.delete(uri, null, null);
7962 }
7963
Narayan Kamath1c496c22015-04-16 14:40:19 +01007964 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007965 public String getSimLocaleForSubscriber(int subId) {
7966 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7967 final Phone phone = getPhone(subId);
7968 if (phone == null) {
7969 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007970 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 final long identity = Binder.clearCallingIdentity();
7973 try {
Jack Yu285100e2022-12-02 22:48:35 -08007974 SubscriptionInfo info;
7975 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7976 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7977 phone.getContext().getOpPackageName(),
7978 phone.getContext().getAttributionTag());
7979 if (info == null) {
7980 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7981 return null;
7982 }
7983 } else {
7984 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7985 phone.getContext().getOpPackageName(),
7986 phone.getContext().getAttributionTag());
7987 if (info == null) {
7988 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7989 return null;
7990 }
chen xu6291c472019-02-04 12:55:53 -08007991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 // Try and fetch the locale from the carrier properties or from the SIM language
7993 // preferences (EF-PL and EF-LI)...
7994 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007996 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7997 if (localeFromDefaultSim != null) {
7998 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7999 if (DBG) log("Using locale from subId: " + subId + " locale: "
8000 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008001 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008002 } else {
8003 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 }
8005 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007 // The SIM language preferences only store a language (e.g. fr = French), not an
8008 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8009 // the SIM and carrier preferences does not include a country we add the country
8010 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008011 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008013 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008014 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 }
8016
8017 if (DBG) log("No locale found - returning null");
8018 return null;
8019 } finally {
8020 Binder.restoreCallingIdentity(identity);
8021 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008022 }
8023
tom hsu0b59d292022-09-29 23:49:21 +08008024 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008025 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008026 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008027 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008028 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008029 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8030 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008031 Locale.forLanguageTag(localeTag).getCountry())) {
8032 return localeTag;
8033 }
8034 }
8035 return inputLocale.toLanguageTag();
8036 }
8037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 /**
8039 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8040 */
8041 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008042 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8043 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8044 mApp.getOpPackageName(), mApp.getAttributionTag());
8045 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008046 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008047 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008048 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008049
Gary Jian3aa9a762022-01-24 16:41:19 +08008050 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8051 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008052
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008053 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008054 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8055 * representing the state of the modem.
8056 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008057 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8058 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008059 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008060 */
8061 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008062 public void requestModemActivityInfo(ResultReceiver result) {
8063 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065
8066 final long identity = Binder.clearCallingIdentity();
8067 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008068 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 } finally {
8070 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008071 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008072 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008073
Gary Jian76280a42022-12-07 16:18:33 +08008074 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008075 // less than total activity duration.
8076 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8077 if (info == null) {
8078 return false;
8079 }
8080 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008081 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008082 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8083
Hall Liu49656c02020-10-09 19:00:11 -07008084 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8085
Siddharth Rayb8114062018-06-17 15:02:38 -07008086 return (info.isValid()
8087 && (info.getSleepTimeMillis() <= activityDurationMs)
Gary Jian76280a42022-12-07 16:18:33 +08008088 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008089 }
8090
Gary Jian3aa9a762022-01-24 16:41:19 +08008091 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8092 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8093 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8094 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8095
8096 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8097 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8098 }
8099
8100 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8101 mLastModemActivityInfo.setReceiveTimeMillis(
8102 rat,
8103 freq,
8104 info.getReceiveTimeMillis(rat, freq)
8105 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8106 }
8107
8108 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8109 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8110 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8111 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8112
8113 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8114 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8115 }
8116 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8117 mLastModemActivityInfo.setReceiveTimeMillis(
8118 rat,
8119 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8120 }
8121
8122 /**
8123 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8124 * @param info recent ModemActivityInfo
8125 */
8126 private void mergeModemActivityInfo(ModemActivityInfo info) {
8127 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008128 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008129 boolean matched;
8130 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8131 matched = false;
8132 int rat = info.getSpecificInfoRat(i);
8133 int freq = info.getSpecificInfoFrequencyRange(i);
8134 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8135 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8136 //if it already exists
8137 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8138 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8139 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8140 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8141 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8142 updateLastModemActivityInfo(info, rat, freq);
8143 matched = true;
8144 }
8145 } else {
8146 updateLastModemActivityInfo(info, rat);
8147 matched = true;
8148 }
8149 }
8150 }
8151
8152 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008153 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008154 new ActivityStatsTechSpecificInfo(
8155 rat,
8156 freq,
8157 info.getTransmitTimeMillis(rat, freq),
8158 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008159 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008160 }
8161 }
8162 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8163 mLastModemActivitySpecificInfo =
8164 new ActivityStatsTechSpecificInfo[merged.size()];
8165 merged.toArray(mLastModemActivitySpecificInfo);
8166
8167 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8168 mLastModemActivityInfo.setSleepTimeMillis(
8169 info.getSleepTimeMillis()
8170 + mLastModemActivityInfo.getSleepTimeMillis());
8171 mLastModemActivityInfo.setIdleTimeMillis(
8172 info.getIdleTimeMillis()
8173 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008174
8175 mLastModemActivityInfo =
8176 new ModemActivityInfo(
8177 mLastModemActivityInfo.getTimestampMillis(),
8178 mLastModemActivityInfo.getSleepTimeMillis(),
8179 mLastModemActivityInfo.getIdleTimeMillis(),
8180 mLastModemActivitySpecificInfo);
8181 }
8182
8183 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8184 ActivityStatsTechSpecificInfo[] info) {
8185 int infoSize = info.length;
8186 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8187 for (int i = 0; i < infoSize; i++) {
8188 ret[i] = new ActivityStatsTechSpecificInfo(
8189 info[i].getRat(), info[i].getFrequencyRange(),
8190 info[i].getTransmitTimeMillis(),
8191 (int) info[i].getReceiveTimeMillis());
8192 }
8193 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008194 }
8195
Jack Yu85bd38a2015-11-09 11:34:32 -08008196 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008197 * Returns the service state information on specified subscription.
8198 */
8199 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008200 public ServiceState getServiceStateForSubscriber(int subId,
8201 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8202 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008204 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008205 return null;
8206 }
8207
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008208 boolean hasFinePermission = false;
8209 boolean hasCoarsePermission = false;
8210 if (!renounceFineLocationAccess) {
8211 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8212 LocationAccessPolicy.checkLocationPermission(mApp,
8213 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8214 .setCallingPackage(callingPackage)
8215 .setCallingFeatureId(callingFeatureId)
8216 .setCallingPid(Binder.getCallingPid())
8217 .setCallingUid(Binder.getCallingUid())
8218 .setMethod("getServiceStateForSubscriber")
8219 .setLogAsInfo(true)
8220 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8221 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8222 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8223 .build());
8224 hasFinePermission =
8225 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8226 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008227
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008228 if (!renounceCoarseLocationAccess) {
8229 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8230 LocationAccessPolicy.checkLocationPermission(mApp,
8231 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8232 .setCallingPackage(callingPackage)
8233 .setCallingFeatureId(callingFeatureId)
8234 .setCallingPid(Binder.getCallingPid())
8235 .setCallingUid(Binder.getCallingUid())
8236 .setMethod("getServiceStateForSubscriber")
8237 .setLogAsInfo(true)
8238 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8239 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8240 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8241 .build());
8242 hasCoarsePermission =
8243 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8244 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008245
Jack Yu479f40e2020-10-27 21:29:25 -07008246 final Phone phone = getPhone(subId);
8247 if (phone == null) {
8248 return null;
8249 }
8250
Jordan Liu0f2bc442020-11-18 16:47:37 -08008251 final long identity = Binder.clearCallingIdentity();
8252
Jack Yu479f40e2020-10-27 21:29:25 -07008253 boolean isCallingPackageDataService = phone.getDataServicePackages()
8254 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008256 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008257 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8258 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8259 .getSubscriptionInfoInternal(subId);
8260 if (subInfo == null || !subInfo.isActive()) {
8261 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8262 + "subId=" + subId);
8263 return null;
8264 }
8265 } else {
8266 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8267 callingFeatureId)) {
8268 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8269 + "subId=" + subId);
8270 return null;
8271 }
Jordan Liuc437b192020-08-17 10:59:12 -07008272 }
8273
Hall Liuf19c44f2018-11-27 14:38:17 -08008274 ServiceState ss = phone.getServiceState();
8275
8276 // Scrub out the location info in ServiceState depending on what level of access
8277 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008278 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008279 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8280 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008284 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008285
8286 /**
8287 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8288 *
8289 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8290 * voicemail ringtone.
8291 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8292 * PhoneAccount.
8293 */
8294 @Override
8295 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 final long identity = Binder.clearCallingIdentity();
8297 try {
8298 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8299 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008300 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008307 }
8308
8309 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008310 * Sets the per-account voicemail ringtone.
8311 *
8312 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8313 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8314 *
8315 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8316 * voicemail ringtone.
8317 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8318 * PhoneAccount.
8319 */
8320 @Override
8321 public void setVoicemailRingtoneUri(String callingPackage,
8322 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008323 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008325 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8326 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8328 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8329 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331
8332 final long identity = Binder.clearCallingIdentity();
8333 try {
8334 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8335 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008336 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 }
8338 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008341 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008342 }
8343
8344 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008345 * Returns whether vibration is set for voicemail notification in Phone settings.
8346 *
8347 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8348 * voicemail vibration setting.
8349 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8350 */
8351 @Override
8352 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353 final long identity = Binder.clearCallingIdentity();
8354 try {
8355 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8356 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008357 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008364 }
8365
Youhan Wange64578a2016-05-02 15:32:42 -07008366 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008367 * Sets the per-account voicemail vibration.
8368 *
8369 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8370 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8371 *
8372 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8373 * voicemail vibration setting.
8374 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8375 * specific PhoneAccount.
8376 */
8377 @Override
8378 public void setVoicemailVibrationEnabled(String callingPackage,
8379 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008380 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008382 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8383 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8385 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8386 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008387 }
8388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8392 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008393 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 }
8395 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008398 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008399 }
8400
8401 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008402 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8403 *
8404 * @throws SecurityException if the caller does not have the required permission
8405 */
arunvoddud7401012022-12-15 16:08:12 +00008406 @VisibleForTesting
8407 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008408 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008409 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008410 }
8411
8412 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008413 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8414 * permission.
8415 *
8416 * @throws SecurityException if the caller does not have the required permission
8417 */
8418 private void enforceSendSmsPermission() {
8419 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8420 }
8421
8422 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008423 * Make sure either called from same process as self (phone) or IPC caller has interact across
8424 * users permission.
8425 *
8426 * @throws SecurityException if the caller does not have the required permission
8427 */
8428 private void enforceInteractAcrossUsersPermission(String message) {
8429 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8430 }
8431
8432 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008433 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008434 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008435 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008436 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008437 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442 if (componentName == null) {
8443 throw new SecurityException(
8444 "Caller not current active visual voicemail package[null]");
8445 }
8446 String vvmPackage = componentName.getPackageName();
8447 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008448 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449 }
8450 } finally {
8451 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008452 }
8453 }
8454
8455 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008456 * Return the application ID for the app type.
8457 *
8458 * @param subId the subscription ID that this request applies to.
8459 * @param appType the uicc app type.
8460 * @return Application ID for specificied app type, or null if no uicc.
8461 */
8462 @Override
8463 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008464 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008465 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466
8467 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008468 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 if (phone == null) {
8470 return null;
8471 }
8472 String aid = null;
8473 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008474 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008475 .getApplicationByType(appType).getAid();
8476 } catch (Exception e) {
8477 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8478 }
8479 return aid;
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008482 }
Youhan Wange64578a2016-05-02 15:32:42 -07008483 }
8484
Youhan Wang4001d252016-05-11 10:29:41 -07008485 /**
8486 * Return the Electronic Serial Number.
8487 *
8488 * @param subId the subscription ID that this request applies to.
8489 * @return ESN or null if error.
8490 */
8491 @Override
8492 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008493 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008494 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495
8496 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008497 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008498 if (phone == null) {
8499 return null;
8500 }
8501 String esn = null;
8502 try {
8503 esn = phone.getEsn();
8504 } catch (Exception e) {
8505 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8506 }
8507 return esn;
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008510 }
Youhan Wang4001d252016-05-11 10:29:41 -07008511 }
8512
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008513 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008514 * Return the Preferred Roaming List Version.
8515 *
8516 * @param subId the subscription ID that this request applies to.
8517 * @return PRLVersion or null if error.
8518 */
8519 @Override
8520 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008521 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008522 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523
8524 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008525 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 if (phone == null) {
8527 return null;
8528 }
8529 String cdmaPrlVersion = null;
8530 try {
8531 cdmaPrlVersion = phone.getCdmaPrlVersion();
8532 } catch (Exception e) {
8533 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8534 }
8535 return cdmaPrlVersion;
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008538 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008539 }
8540
8541 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008542 * Get snapshot of Telephony histograms
8543 * @return List of Telephony histograms
8544 * @hide
8545 */
8546 @Override
8547 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8549 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 return RIL.getTelephonyRILTimingHistograms();
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008557 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008558
8559 /**
8560 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008561 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8562 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008563 * Require system privileges. In the future we may add this to carrier APIs.
8564 *
Michele Berionne482f8202018-11-27 18:57:59 -08008565 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008566 */
8567 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008568 @TelephonyManager.SetCarrierRestrictionResult
8569 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008570 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008571 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008572
Michele Berionne482f8202018-11-27 18:57:59 -08008573 if (carrierRestrictionRules == null) {
8574 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008575 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577 final long identity = Binder.clearCallingIdentity();
8578 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008579 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008580 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008584 }
8585
8586 /**
8587 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008588 * Get the allowed carrier list and the excluded carrier list, including the priority between
8589 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008590 * Require system privileges. In the future we may add this to carrier APIs.
8591 *
Michele Berionne482f8202018-11-27 18:57:59 -08008592 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008593 */
8594 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008595 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008596 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008597 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598
8599 final long identity = Binder.clearCallingIdentity();
8600 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008601 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8602 if (response instanceof CarrierRestrictionRules) {
8603 return (CarrierRestrictionRules) response;
8604 }
8605 // Response is an Exception of some kind,
8606 // which is signalled to the user as a NULL retval
8607 return null;
8608 } catch (Exception e) {
8609 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8610 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008614 }
8615
fionaxu59545b42016-05-25 15:53:37 -07008616 /**
arunvoddud7401012022-12-15 16:08:12 +00008617 * Fetches the carrier restriction status of the device and sends the status to the caller
8618 * through the callback.
8619 *
8620 * @param callback The callback that will be used to send the result.
8621 * @throws SecurityException if the caller does not have the required permission/privileges or
8622 * the caller is not allowlisted.
8623 */
8624 @Override
8625 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8626 enforceReadPermission("getCarrierRestrictionStatus");
8627 int carrierId = validateCallerAndGetCarrierId(packageName);
8628 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8629 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8630 throw new SecurityException("Not an authorized caller");
8631 }
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8635 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8636 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
8640 }
8641
8642 @VisibleForTesting
8643 public int validateCallerAndGetCarrierId(String packageName) {
8644 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8645 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8646 }
8647
8648 /**
fionaxu59545b42016-05-25 15:53:37 -07008649 * Action set from carrier signalling broadcast receivers to enable/disable radio
8650 * @param subId the subscription ID that this action applies to.
8651 * @param enabled control enable or disable radio.
8652 * {@hide}
8653 */
8654 @Override
8655 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8656 enforceModifyPermission();
8657 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658
8659 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008660 if (phone == null) {
8661 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8662 return;
8663 }
8664 try {
8665 phone.carrierActionSetRadioEnabled(enabled);
8666 } catch (Exception e) {
8667 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 } finally {
8669 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008670 }
8671 }
8672
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008673 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008674 * Enable or disable Voice over NR (VoNR)
8675 * @param subId the subscription ID that this action applies to.
8676 * @param enabled enable or disable VoNR.
8677 * @return operation result.
8678 */
8679 @Override
8680 public int setVoNrEnabled(int subId, boolean enabled) {
8681 enforceModifyPermission();
8682 final Phone phone = getPhone(subId);
8683
8684 final long identity = Binder.clearCallingIdentity();
8685 if (phone == null) {
8686 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8687 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8688 }
8689
8690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8691 try {
8692 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8693 workSource);
8694 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008695
8696 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8697 if (DBG) {
8698 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8699 }
8700 SubscriptionManager.setSubscriptionProperty(
8701 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8702 (enabled ? "1" : "0"));
8703 }
8704
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008705 return result;
8706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
8709 }
8710
8711 /**
8712 * Is voice over NR enabled
8713 * @return true if VoNR is enabled else false
8714 */
8715 @Override
8716 public boolean isVoNrEnabled(int subId) {
8717 enforceReadPrivilegedPermission("isVoNrEnabled");
8718 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8722 null, subId, workSource);
8723 if (DBG) log("isVoNrEnabled: " + isEnabled);
8724 return isEnabled;
8725 } finally {
8726 Binder.restoreCallingIdentity(identity);
8727 }
8728 }
8729
8730 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008731 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8732 * network status based on which carrier apps could apply actions accordingly,
8733 * enable/disable default url handler for example.
8734 *
8735 * @param subId the subscription ID that this action applies to.
8736 * @param report control start/stop reporting the default network status.
8737 * {@hide}
8738 */
8739 @Override
8740 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8741 enforceModifyPermission();
8742 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743
8744 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008745 if (phone == null) {
8746 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8747 return;
8748 }
8749 try {
8750 phone.carrierActionReportDefaultNetworkStatus(report);
8751 } catch (Exception e) {
8752 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008753 } finally {
8754 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008755 }
8756 }
8757
8758 /**
fionaxud9622282017-07-17 17:51:30 -07008759 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8760 * @param subId the subscription ID that this action applies to.
8761 * {@hide}
8762 */
8763 @Override
8764 public void carrierActionResetAll(int subId) {
8765 enforceModifyPermission();
8766 final Phone phone = getPhone(subId);
8767 if (phone == null) {
8768 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8769 return;
8770 }
8771 try {
8772 phone.carrierActionResetAll();
8773 } catch (Exception e) {
8774 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8775 }
8776 }
8777
8778 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008779 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8780 * bug report is being generated.
8781 */
8782 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008783 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008784 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8785 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008786 writer.println("Permission Denial: can't dump Phone from pid="
8787 + Binder.getCallingPid()
8788 + ", uid=" + Binder.getCallingUid()
8789 + "without permission "
8790 + android.Manifest.permission.DUMP);
8791 return;
8792 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008793 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008794 }
Jack Yueb89b242016-06-22 13:27:47 -07008795
Brad Ebingerdac2f002018-04-03 15:17:52 -07008796 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008797 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8798 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8799 @NonNull String[] args) {
8800 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8801 this, in.getFileDescriptor(), out.getFileDescriptor(),
8802 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008803 }
8804
Jack Yueb89b242016-06-22 13:27:47 -07008805 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008806 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008807 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008808 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008809 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008810 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008811 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008812 */
8813 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008814 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008815 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008816 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8817 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8818 try {
8819 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008820 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008821 } catch (SecurityException se) {
8822 enforceModifyPermission();
8823 }
8824 } else {
8825 enforceModifyPermission();
8826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008827
8828 final long identity = Binder.clearCallingIdentity();
8829 try {
8830 Phone phone = getPhone(subId);
8831 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008832 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8833 phone.carrierActionSetMeteredApnsEnabled(enabled);
8834 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008835 phone.getDataSettingsManager().setDataEnabled(
8836 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008838 }
8839 } finally {
8840 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008841 }
8842 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008843
8844 /**
8845 * Get Client request stats
8846 * @return List of Client Request Stats
8847 * @hide
8848 */
8849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008850 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8851 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008853 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008854 return null;
8855 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008856 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 if (phone != null) {
8861 return phone.getClientRequestStats();
8862 }
8863
8864 return null;
8865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008868 }
8869
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008870 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008871 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008872 if (uid == Process.ROOT_UID && packageName == null) {
8873 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8874 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8875 // exception. ROOT_UID seems not to have a valid package name returned by
8876 // PackageManager, so just fake it here to avoid issues when running telephony shell
8877 // commands that plumb through the RIL as root, like so:
8878 // $ adb root
8879 // $ adb shell cmd phone ...
8880 packageName = "root";
8881 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008882 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008883 }
Jack Yueb4124c2017-02-16 15:32:43 -08008884
8885 /**
Grace Chen70990072017-03-24 17:21:30 -07008886 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008887 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008888 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008889 * @param state State of SIM (power down, power up, pass through)
8890 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8891 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8892 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008893 *
8894 **/
8895 @Override
Grace Chen70990072017-03-24 17:21:30 -07008896 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008897 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008898 Phone phone = PhoneFactory.getPhone(slotIndex);
8899
vagdeviaf9a5b92018-08-15 16:01:53 -07008900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008902 final long identity = Binder.clearCallingIdentity();
8903 try {
8904 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008905 phone.setSimPowerState(state, null, workSource);
8906 }
8907 } finally {
8908 Binder.restoreCallingIdentity(identity);
8909 }
8910 }
8911
8912 /**
8913 * Set SIM card power state.
8914 *
8915 * @param slotIndex SIM slot id.
8916 * @param state State of SIM (power down, power up, pass through)
8917 * @param callback callback to trigger after success or failure
8918 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8919 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8920 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8921 *
8922 **/
8923 @Override
8924 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8925 IIntegerConsumer callback) {
8926 enforceModifyPermission();
8927 Phone phone = PhoneFactory.getPhone(slotIndex);
8928
8929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8930
8931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 if (phone != null) {
8934 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8935 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 }
8937 } finally {
8938 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008939 }
8940 }
Shuo Qiandd210312017-04-12 22:11:33 +00008941
Tyler Gunn65d45c22017-06-05 11:22:26 -07008942 private boolean isUssdApiAllowed(int subId) {
8943 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008944 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008945 if (configManager == null) {
8946 return false;
8947 }
8948 PersistableBundle pb = configManager.getConfigForSubId(subId);
8949 if (pb == null) {
8950 return false;
8951 }
8952 return pb.getBoolean(
8953 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8954 }
8955
Shuo Qiandd210312017-04-12 22:11:33 +00008956 /**
8957 * Check if phone is in emergency callback mode
8958 * @return true if phone is in emergency callback mode
8959 * @param subId sub id
8960 */
goneil9c5f4872017-12-05 14:07:56 -08008961 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008962 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008963 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008965
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 if (phone != null) {
8969 return phone.isInEcm();
8970 } else {
8971 return false;
8972 }
8973 } finally {
8974 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008975 }
8976 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008977
8978 /**
8979 * Get the current signal strength information for the given subscription.
8980 * Because this information is not updated when the device is in a low power state
8981 * it should not be relied-upon to be current.
8982 * @param subId Subscription index
8983 * @return the most recent cached signal strength info from the modem
8984 */
8985 @Override
8986 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 Phone p = getPhone(subId);
8990 if (p == null) {
8991 return null;
8992 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 return p.getSignalStrength();
8995 } finally {
8996 Binder.restoreCallingIdentity(identity);
8997 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008998 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008999
Pengquan Meng77b7f132018-08-22 14:49:57 -07009000 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009001 * Get the current modem radio state for the given slot.
9002 * @param slotIndex slot index.
9003 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009004 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009005 * @return the current radio power state from the modem
9006 */
9007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009008 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009009 Phone phone = PhoneFactory.getPhone(slotIndex);
9010 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9012 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009013 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9014 }
9015
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 return phone.getRadioPowerState();
9019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
9022 }
9023 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9024 }
9025
9026 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009027 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9028 *
9029 * <p>Requires one of the following permissions:
9030 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009031 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009032 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9033 * privileges.
9034 *
9035 * @param subId subscription id
9036 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9037 * {@code false}.
9038 */
9039 @Override
9040 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009041 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009042 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009043 try {
9044 mApp.enforceCallingOrSelfPermission(
9045 android.Manifest.permission.ACCESS_NETWORK_STATE,
9046 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009047 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009048 mApp.enforceCallingOrSelfPermission(
9049 permission.READ_BASIC_PHONE_STATE, functionName);
9050 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009051 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009052 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009053 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009054 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009055
Pengquan Menga1bb6272018-09-06 09:59:22 -07009056 boolean isEnabled = false;
9057 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009058 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009059 Phone phone = getPhone(subId);
9060 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009061 } finally {
9062 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009063 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009064 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009065 }
9066
9067
9068 /**
9069 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9070 *
9071 * <p> Requires permission:
9072 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9073 * privileges.
9074 *
9075 * @param subId subscription id
9076 * @param isEnabled {@code true} means enable, {@code false} means disable.
9077 */
9078 @Override
9079 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9081 mApp, subId, "setDataRoamingEnabled");
9082
Pengquan Menga1bb6272018-09-06 09:59:22 -07009083 final long identity = Binder.clearCallingIdentity();
9084 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009085 Phone phone = getPhone(subId);
9086 if (phone != null) {
9087 phone.setDataRoamingEnabled(isEnabled);
9088 }
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009091 }
9092 }
9093
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009094 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009095 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009096 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009097 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009098 mApp, subId, "isManualNetworkSelectionAllowed");
9099
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009100 boolean isAllowed = true;
9101 final long identity = Binder.clearCallingIdentity();
9102 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009103 Phone phone = getPhone(subId);
9104 if (phone != null) {
9105 isAllowed = phone.isCspPlmnEnabled();
9106 }
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
9109 }
9110 return isAllowed;
9111 }
9112
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009113 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9114 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009115 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009116 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009117 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009118 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9119 if (phone == null) {
9120 return false;
9121 }
9122 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9123 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9124 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009125 }
9126
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009127 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009128 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009129 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009130 mApp.getSystemService(AppOpsManager.class)
9131 .checkPackage(Binder.getCallingUid(), callingPackage);
9132
Jordan Liu1e142fc2019-04-22 15:10:43 -07009133 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009134 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009135 try {
9136 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009137 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009138 } catch (SecurityException e) {
9139 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9140 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009141 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009142 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009143 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009144 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009145 }
sandeepjsb6c87872021-09-27 15:34:44 +00009146 // checking compatibility, if calling app's target SDK is T and beyond.
9147 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9148 Binder.getCallingUid())) {
9149 isIccIdAccessRestricted = true;
9150 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009151 final long identity = Binder.clearCallingIdentity();
9152 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009153 UiccController uiccController = UiccController.getInstance();
9154 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009155 if (hasReadPermission) {
9156 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009157 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009158
9159 // Remove private info if the caller doesn't have access
9160 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9161 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009162 //setting the value after compatibility check
9163 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009164 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9165 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009166 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009167 if (card == null) {
9168 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009169 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009170 continue;
9171 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009172 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9173 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009174 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009175 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009176 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009177 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9178 for (UiccPortInfo portInfo : portInfos) {
9179 UiccPort port = uiccController.getUiccPortForSlot(
9180 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9181 if (port == null) {
9182 // assume no access if port is null
9183 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9184 continue;
9185 }
9186 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9187 uiccPortInfos.add(portInfo);
9188 } else {
9189 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9190 }
9191 }
9192 filteredInfos.add(new UiccCardInfo(
9193 cardInfo.isEuicc(),
9194 cardInfo.getCardId(),
9195 null,
9196 cardInfo.getPhysicalSlotIndex(),
9197 cardInfo.isRemovable(),
9198 cardInfo.isMultipleEnabledProfilesSupported(),
9199 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009200 }
9201 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 }
9206
sandeepjsb6c87872021-09-27 15:34:44 +00009207 /**
9208 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9209 * generally private and require carrier privileges to view.
9210 *
9211 * @hide
9212 */
9213 @NonNull
9214 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9215 List<UiccPortInfo> portinfo = new ArrayList<>();
9216 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9217 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9218 }
9219 return new UiccCardInfo(
9220 cardInfo.isEuicc(),
9221 cardInfo.getCardId(),
9222 null,
9223 cardInfo.getPhysicalSlotIndex(),
9224 cardInfo.isRemovable(),
9225 cardInfo.isMultipleEnabledProfilesSupported(),
9226 portinfo
9227 );
9228 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009229
sandeepjsb6c87872021-09-27 15:34:44 +00009230 /**
9231 * @hide
9232 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9233 * These values are generally private and require carrier privileges to view.
9234 */
9235 @NonNull
9236 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9237 return new UiccPortInfo(
9238 UiccPortInfo.ICCID_REDACTED,
9239 portInfo.getPortIndex(),
9240 portInfo.getLogicalSlotIndex(),
9241 portInfo.isActive()
9242 );
9243 }
9244 @Override
9245 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009246 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009247 mApp.getSystemService(AppOpsManager.class)
9248 .checkPackage(Binder.getCallingUid(), callingPackage);
9249
sandeepjsb6c87872021-09-27 15:34:44 +00009250 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009251
Aman Guptaf3c90b32022-03-17 04:54:16 +00009252 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9253 // we are reading iccId which is PII data.
9254 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009255
9256 // checking compatibility, if calling app's target SDK is T and beyond.
9257 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9258 Binder.getCallingUid())) {
9259 isLogicalSlotAccessRestricted = true;
9260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009261 final long identity = Binder.clearCallingIdentity();
9262 try {
9263 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009264 if (slots == null || slots.length == 0) {
9265 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009266 return null;
9267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009268 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9269 for (int i = 0; i < slots.length; i++) {
9270 UiccSlot slot = slots[i];
9271 if (slot == null) {
9272 continue;
9273 }
9274
Jordan Liu7be7e652019-05-06 18:55:02 +00009275 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009276 UiccCard card = slot.getUiccCard();
9277 if (card != null) {
9278 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009279 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009280 cardId = slot.getEid();
9281 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009282 // If cardId is null, use iccId of default port as cardId.
9283 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009285 }
9286
Jordan Liu857451f2019-05-09 16:35:35 -07009287 if (cardId != null) {
9288 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9289 // if cardId is an EID, it's all digits so this is fine
9290 cardId = IccUtils.stripTrailingFs(cardId);
9291 }
9292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009293 int cardState = 0;
9294 switch (slot.getCardState()) {
9295 case CARDSTATE_ABSENT:
9296 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9297 break;
9298 case CARDSTATE_PRESENT:
9299 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9300 break;
9301 case CARDSTATE_ERROR:
9302 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9303 break;
9304 case CARDSTATE_RESTRICTED:
9305 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9306 break;
9307 default:
9308 break;
9309
9310 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009311 List<UiccPortInfo> portInfos = new ArrayList<>();
9312 int[] portIndexes = slot.getPortList();
9313 for (int portIdx : portIndexes) {
9314 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009315 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009316 portInfos.add(new UiccPortInfo(iccId, portIdx,
9317 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009319 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009320 slot.isEuicc(),
9321 cardId,
9322 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009323 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009324 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009325 //setting the value after compatibility check
9326 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009327 }
9328 return infos;
9329 } finally {
9330 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009331 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009332 }
9333
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009334 /* Returns null if doesn't have read permission or carrier privilege access. */
9335 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9336 boolean hasReadPermission) {
9337 String iccId = slot.getIccId(portIndex);
9338 if (hasReadPermission) { // if has read permission
9339 return iccId;
9340 } else {
9341 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9342 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9343 // if no read permission, checking carrier privilege access
9344 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9345 return iccId;
9346 }
9347 }
9348 }
9349 // No read permission or carrier privilege access.
9350 return UiccPortInfo.ICCID_REDACTED;
9351 }
9352
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009353 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009354 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009355 public boolean switchSlots(int[] physicalSlots) {
9356 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009357
9358 final long identity = Binder.clearCallingIdentity();
9359 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009360 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9361 for (int i = 0; i < physicalSlots.length; i++) {
9362 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9363 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9364 physicalSlots[i], i));
9365 }
9366 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009370 }
Jack Yu4c988042018-02-27 15:30:01 -08009371
9372 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009373 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9374 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9375 enforceModifyPermission();
9376
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009379 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009380 } finally {
9381 Binder.restoreCallingIdentity(identity);
9382 }
9383 }
9384
9385 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009386 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009387 final long identity = Binder.clearCallingIdentity();
9388 try {
9389 return UiccController.getInstance().getCardIdForDefaultEuicc();
9390 } finally {
9391 Binder.restoreCallingIdentity(identity);
9392 }
9393 }
9394
Pengquan Meng85728fb2018-03-12 16:31:21 -07009395 /**
goneil47ffb6e2018-04-06 15:40:58 -07009396 * A test API to reload the UICC profile.
9397 *
9398 * <p>Requires that the calling app has permission
9399 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9400 * @hide
9401 */
9402 @Override
9403 public void refreshUiccProfile(int subId) {
9404 enforceModifyPermission();
9405
9406 final long identity = Binder.clearCallingIdentity();
9407 try {
9408 Phone phone = getPhone(subId);
9409 if (phone == null) {
9410 return;
9411 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009412 UiccPort uiccPort = phone.getUiccPort();
9413 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009414 return;
9415 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009416 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009417 if (uiccProfile == null) {
9418 return;
9419 }
9420 uiccProfile.refresh();
9421 } finally {
9422 Binder.restoreCallingIdentity(identity);
9423 }
9424 }
9425
9426 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009427 * Returns false if the mobile data is disabled by default, otherwise return true.
9428 */
9429 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009430 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009431 }
9432
9433 /**
9434 * Returns true if the data roaming is enabled by default, i.e the system property
9435 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9436 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9437 */
9438 private boolean getDefaultDataRoamingEnabled(int subId) {
9439 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009440 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009441 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009442 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9443 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9444 return isDataRoamingEnabled;
9445 }
9446
9447 /**
9448 * Returns the default network type for the given {@code subId}, if the default network type is
9449 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9450 */
9451 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009452 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009453 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009454 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9455 return list.get(phoneId);
9456 }
9457 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009458 }
fionaxua13278b2018-03-21 00:08:13 -07009459
9460 @Override
9461 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009462 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009463 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009464
9465 final long identity = Binder.clearCallingIdentity();
9466 try {
9467 final Phone phone = getPhone(subId);
9468 if (phone == null) {
9469 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9470 return;
9471 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009472 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9473 if (cpt != null) {
9474 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9475 }
9476 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009477 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9478 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009479 if (carrierPrivilegeRules == null) {
9480 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9481 } else {
9482 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009484 } finally {
9485 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009486 }
fionaxua13278b2018-03-21 00:08:13 -07009487 }
9488
9489 @Override
9490 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009491 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009492
9493 final long identity = Binder.clearCallingIdentity();
9494 try {
9495 final Phone phone = getPhone(subId);
9496 if (phone == null) {
9497 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9498 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9499 }
9500 return phone.getCarrierIdListVersion();
9501 } finally {
9502 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009503 }
fionaxua13278b2018-03-21 00:08:13 -07009504 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009505
9506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009507 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9508 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009510 mApp, subId, callingPackage, callingFeatureId,
9511 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009512 return -1;
9513 }
9514
9515 final long identity = Binder.clearCallingIdentity();
9516 try {
9517 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9518 } finally {
9519 Binder.restoreCallingIdentity(identity);
9520 }
9521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009522
9523 @Override
9524 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009525 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009526 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009527 mApp, subId, "getCdmaRoamingMode");
9528
9529 final long identity = Binder.clearCallingIdentity();
9530 try {
9531 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
9534 }
9535 }
9536
9537 @Override
9538 public boolean setCdmaRoamingMode(int subId, int mode) {
9539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9540 mApp, subId, "setCdmaRoamingMode");
9541
9542 final long identity = Binder.clearCallingIdentity();
9543 try {
9544 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9545 } finally {
9546 Binder.restoreCallingIdentity(identity);
9547 }
9548 }
9549
9550 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009551 public int getCdmaSubscriptionMode(int subId) {
9552 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009553 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009554 mApp, subId, "getCdmaSubscriptionMode");
9555
9556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
9564 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009565 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9567 mApp, subId, "setCdmaSubscriptionMode");
9568
9569 final long identity = Binder.clearCallingIdentity();
9570 try {
9571 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9572 } finally {
9573 Binder.restoreCallingIdentity(identity);
9574 }
9575 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009576
sqianc5eccab2018-10-19 18:46:41 -07009577 @Override
sqian8c685422019-02-22 15:55:18 -08009578 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009579 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009581 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9582 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009583 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9584 }
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
sqian854d44b2018-12-12 16:48:18 -08009587 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9588 for (Phone phone: PhoneFactory.getPhones()) {
9589 if (phone.getEmergencyNumberTracker() != null
9590 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9591 emergencyNumberListInternal.put(
9592 phone.getSubId(),
9593 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9594 }
sqian11b7a0e2018-12-05 18:48:28 -08009595 }
sqian854d44b2018-12-12 16:48:18 -08009596 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
sqianc5eccab2018-10-19 18:46:41 -07009600 }
9601
9602 @Override
sqian8c685422019-02-22 15:55:18 -08009603 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009604 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009605 if (!exactMatch) {
9606 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009607 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009608 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009609 }
9610 final long identity = Binder.clearCallingIdentity();
9611 try {
sqian854d44b2018-12-12 16:48:18 -08009612 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009613 //Note: we ignore passed in param exactMatch. We can remove it once
9614 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009615 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009616 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009617 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009618 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009619 }
sqian11b7a0e2018-12-05 18:48:28 -08009620 }
9621 return false;
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
sqianf4ca7ed2019-01-15 18:32:07 -08009627 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009628 * Start emergency callback mode for GsmCdmaPhone for testing.
9629 */
9630 @Override
9631 public void startEmergencyCallbackMode() {
9632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9633 "startEmergencyCallbackMode");
9634 enforceModifyPermission();
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
9637 for (Phone phone : PhoneFactory.getPhones()) {
9638 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9639 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9640 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9641 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9642 gsmCdmaPhone.obtainMessage(
9643 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9644 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9645 }
9646 }
9647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
9652 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009653 * Update emergency number list for test mode.
9654 */
9655 @Override
9656 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9657 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9658 "updateEmergencyNumberListTestMode");
9659
9660 final long identity = Binder.clearCallingIdentity();
9661 try {
9662 for (Phone phone: PhoneFactory.getPhones()) {
9663 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9664 if (tracker != null) {
9665 tracker.executeEmergencyNumberTestModeCommand(action, num);
9666 }
9667 }
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
9672
9673 /**
9674 * Get the full emergency number list for test mode.
9675 */
9676 @Override
9677 public List<String> getEmergencyNumberListTestMode() {
9678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9679 "getEmergencyNumberListTestMode");
9680
9681 final long identity = Binder.clearCallingIdentity();
9682 try {
9683 Set<String> emergencyNumbers = new HashSet<>();
9684 for (Phone phone: PhoneFactory.getPhones()) {
9685 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9686 if (tracker != null) {
9687 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9688 emergencyNumbers.add(num.getNumber());
9689 }
9690 }
9691 }
9692 return new ArrayList<>(emergencyNumbers);
9693 } finally {
9694 Binder.restoreCallingIdentity(identity);
9695 }
9696 }
9697
chen xud6b45bd2018-10-30 22:27:10 -07009698 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009699 public int getEmergencyNumberDbVersion(int subId) {
9700 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9701
9702 final long identity = Binder.clearCallingIdentity();
9703 try {
9704 final Phone phone = getPhone(subId);
9705 if (phone == null) {
9706 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9707 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9708 }
9709 return phone.getEmergencyNumberDbVersion();
9710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713 }
9714
9715 @Override
9716 public void notifyOtaEmergencyNumberDbInstalled() {
9717 enforceModifyPermission();
9718
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
9721 for (Phone phone: PhoneFactory.getPhones()) {
9722 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9723 if (tracker != null) {
9724 tracker.updateOtaEmergencyNumberDatabase();
9725 }
9726 }
9727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
9730 }
9731
9732 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009733 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009734 enforceActiveEmergencySessionPermission();
9735
9736 final long identity = Binder.clearCallingIdentity();
9737 try {
9738 for (Phone phone: PhoneFactory.getPhones()) {
9739 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9740 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009741 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9742 }
9743 }
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
9749 @Override
9750 public void resetOtaEmergencyNumberDbFilePath() {
9751 enforceActiveEmergencySessionPermission();
9752
9753 final long identity = Binder.clearCallingIdentity();
9754 try {
9755 for (Phone phone: PhoneFactory.getPhones()) {
9756 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9757 if (tracker != null) {
9758 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009759 }
9760 }
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
9764 }
9765
9766 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009767 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9768 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9769 Phone phone = getPhone(subId);
9770 if (phone == null) {
9771 return null;
9772 }
9773 final long identity = Binder.clearCallingIdentity();
9774 try {
9775 UiccProfile profile = UiccController.getInstance()
9776 .getUiccProfileForPhone(phone.getPhoneId());
9777 if (profile != null) {
9778 return profile.getCertsFromCarrierPrivilegeAccessRules();
9779 }
9780 } finally {
9781 Binder.restoreCallingIdentity(identity);
9782 }
9783 return null;
9784 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009785
9786 /**
9787 * Enable or disable a modem stack.
9788 */
9789 @Override
9790 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9791 enforceModifyPermission();
9792
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
9795 Phone phone = PhoneFactory.getPhone(slotIndex);
9796 if (phone == null) {
9797 return false;
9798 } else {
9799 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9800 }
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 }
Michelecea4cf22018-12-21 15:00:11 -08009805
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009806 /**
9807 * Whether a modem stack is enabled or not.
9808 */
9809 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009810 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9811 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009812 Phone phone = PhoneFactory.getPhone(slotIndex);
9813 if (phone == null) return false;
9814
9815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009816 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9817 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009818 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9819 }
9820
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009823 try {
9824 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9825 } catch (NoSuchElementException ex) {
9826 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9827 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
Michelecea4cf22018-12-21 15:00:11 -08009833 @Override
Michele0ea7d782019-03-19 14:58:42 -07009834 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009835 enforceModifyPermission();
9836
9837 final long identity = Binder.clearCallingIdentity();
9838 try {
9839 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009840 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009841 .commit();
9842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
9846
9847 @Override
Michele0ea7d782019-03-19 14:58:42 -07009848 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009849 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009851 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9852 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009853 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009854 }
Michelecea4cf22018-12-21 15:00:11 -08009855
9856 final long identity = Binder.clearCallingIdentity();
9857 try {
Michele0ea7d782019-03-19 14:58:42 -07009858 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009859 } finally {
9860 Binder.restoreCallingIdentity(identity);
9861 }
9862 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009863
Michele0ea7d782019-03-19 14:58:42 -07009864 @TelephonyManager.IsMultiSimSupportedResult
9865 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009866 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9867 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9868 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009869 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9870 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009871 }
9872 // Check if the hardware supports multisim functionality. If usage of multisim is not
9873 // supported by the modem, indicate that it is restricted.
9874 PhoneCapability staticCapability =
9875 mPhoneConfigurationManager.getStaticPhoneCapability();
9876 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009877 loge("isMultiSimSupportedInternal: no static configuration available");
9878 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009879 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009880 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009881 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9882 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009883 }
9884 // Check if support of multiple SIMs is restricted by carrier
9885 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009886 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009887 }
9888
Michele0ea7d782019-03-19 14:58:42 -07009889 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009890 }
9891
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009892 /**
9893 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009894 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9895 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9896 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009897 * @param numOfSims number of active sims we want to switch to
9898 */
9899 @Override
9900 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009901 if (numOfSims == 1) {
9902 enforceModifyPermission();
9903 } else {
9904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9905 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9906 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009907 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009908
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009909 try {
Michele30b57b22019-03-01 12:01:14 -08009910 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009911 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009912 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9913 return;
9914 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009915 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9916 } finally {
9917 Binder.restoreCallingIdentity(identity);
9918 }
9919 }
9920
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009921 @Override
9922 public boolean isApplicationOnUicc(int subId, int appType) {
9923 enforceReadPrivilegedPermission("isApplicationOnUicc");
9924 Phone phone = getPhone(subId);
9925 if (phone == null) {
9926 return false;
9927 }
9928 final long identity = Binder.clearCallingIdentity();
9929 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009930 UiccPort uiccPort = phone.getUiccPort();
9931 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009932 return false;
9933 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009934 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009935 if (uiccProfile == null) {
9936 return false;
9937 }
9938 if (TelephonyManager.APPTYPE_SIM <= appType
9939 && appType <= TelephonyManager.APPTYPE_ISIM) {
9940 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9941 }
9942 return false;
9943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 }
9947
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009948 /**
chen xub4baa772019-04-03 10:23:41 -07009949 * Get whether making changes to modem configurations will trigger reboot.
9950 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009951 */
9952 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009953 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9954 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009956 mApp, subId, callingPackage, callingFeatureId,
9957 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009958 return false;
9959 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009960 final long identity = Binder.clearCallingIdentity();
9961 try {
9962 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9963 } finally {
9964 Binder.restoreCallingIdentity(identity);
9965 }
9966 }
9967
Nathan Harold29f5f052019-02-15 13:41:57 -08009968 private void updateModemStateMetrics() {
9969 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9970 // TODO: check the state for each modem if the api is ready.
9971 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9972 }
9973
Pengquan Meng3889a572019-01-23 11:16:29 -08009974 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009975 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009976 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009977 // Verify that the callingPackage belongs to the calling UID
9978 mApp.getSystemService(AppOpsManager.class)
9979 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009980 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009981 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009982 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009983 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9984 if (slotInfos != null) {
9985 for (int i = 0; i < slotInfos.length; i++) {
9986 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9987 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9988 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9989 portInfo.getLogicalSlotIndex()));
9990 }
9991 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009992 }
9993 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009994 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009995 } finally {
9996 Binder.restoreCallingIdentity(identity);
9997 }
9998 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009999
10000 /**
10001 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010002 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010003 */
jimsunf9ec1622022-09-13 21:18:43 +080010004 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010005 @Override
10006 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010007 return getHalVersion(HAL_SERVICE_RADIO);
10008 }
10009
10010 /**
10011 * Get the HAL Version of a specific service
10012 */
10013 @Override
10014 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010015 Phone phone = getDefaultPhone();
10016 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010017 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010018 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10019 return hv.major * 100 + hv.minor;
10020 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010021
10022 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010023 * Get the current calling package name.
10024 * @return the current calling package name
10025 */
10026 @Override
10027 public String getCurrentPackageName() {
10028 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10029 }
10030
10031 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010032 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10033 * corresponding network requests on a subId.
10034 *
10035 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010036 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010037 * 2) APN is un-metered for this subscription, or
10038 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010039 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010040 *
10041 * @return whether data is allowed for a apn type.
10042 *
10043 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010044 */
10045 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010046 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010047 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10048 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010049
10050 // Now that all security checks passes, perform the operation as ourselves.
10051 final long identity = Binder.clearCallingIdentity();
10052 try {
10053 Phone phone = getPhone(subId);
10054 if (phone == null) return false;
10055
Jack Yu27422a52022-03-21 10:38:05 -070010056 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010057 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010058 isMetered = phone.getDataNetworkController().getDataConfigManager()
10059 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10060 phone.getServiceState().getDataRoaming());
10061 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010062 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010063 } finally {
10064 Binder.restoreCallingIdentity(identity);
10065 }
10066 }
10067
10068 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010069 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010070 enforceReadPrivilegedPermission("isApnMetered");
10071
10072 // Now that all security checks passes, perform the operation as ourselves.
10073 final long identity = Binder.clearCallingIdentity();
10074 try {
10075 Phone phone = getPhone(subId);
10076 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010077 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10078 DataUtils.apnTypeToNetworkCapability(apnType),
10079 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010080 } finally {
10081 Binder.restoreCallingIdentity(identity);
10082 }
10083 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010084
10085 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010086 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10087 int subscriptionId, IBooleanConsumer resultCallback) {
10088 enforceModifyPermission();
10089 long token = Binder.clearCallingIdentity();
10090 try {
10091 Phone phone = getPhone(subscriptionId);
10092 if (phone == null) {
10093 try {
10094 if (resultCallback != null) {
10095 resultCallback.accept(false);
10096 }
10097 } catch (RemoteException e) {
10098 // ignore
10099 }
10100 return;
10101 }
10102 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10103 Pair.create(specifiers, (x) -> {
10104 try {
10105 if (resultCallback != null) {
10106 resultCallback.accept(x);
10107 }
10108 } catch (RemoteException e) {
10109 // ignore
10110 }
10111 });
10112 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10113 } finally {
10114 Binder.restoreCallingIdentity(token);
10115 }
10116 }
10117
10118 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010119 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10120 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010121 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010122 mApp, subId, "getSystemSelectionChannels");
10123 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10124 final long identity = Binder.clearCallingIdentity();
10125 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010126 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10127 if (result instanceof IllegalStateException) {
10128 throw (IllegalStateException) result;
10129 }
10130 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010131 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10132 return specifiers;
10133 } finally {
10134 Binder.restoreCallingIdentity(identity);
10135 }
10136 }
10137
10138 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010139 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010140 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010141 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010142 }
10143
10144 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010145 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10146 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010147 if (callingPackage == null) {
10148 callingPackage = getCurrentPackageName();
10149 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010150 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10151 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010152 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10153 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010154 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10155 }
10156 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10157 Intent intent = new Intent();
10158 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10159 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10160 // Bring up choose default SMS subscription dialog right now
10161 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10162 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10163 mApp.startActivity(intent);
10164 }
chen xud5ca2d52019-05-28 15:20:57 -070010165
10166 @Override
10167 public String getMmsUAProfUrl(int subId) {
10168 //TODO investigate if this API should require proper permission check in R b/133791609
10169 final long identity = Binder.clearCallingIdentity();
10170 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010171 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10172 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10173 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10174 return carrierUAProfUrl;
10175 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010176 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10177 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
10182
10183 @Override
10184 public String getMmsUserAgent(int subId) {
10185 //TODO investigate if this API should require proper permission check in R b/133791609
10186 final long identity = Binder.clearCallingIdentity();
10187 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010188 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10189 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10190 if (!TextUtils.isEmpty(carrierUserAgent)) {
10191 return carrierUserAgent;
10192 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010193 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10194 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010195 } finally {
10196 Binder.restoreCallingIdentity(identity);
10197 }
10198 }
Jack Yub07d4972019-05-28 16:12:25 -070010199
10200 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010201 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10202 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010203
Jack Yub07d4972019-05-28 16:12:25 -070010204 final long identity = Binder.clearCallingIdentity();
10205 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010206 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010207 if (phone == null) return false;
10208
Ling Maf188d502022-09-16 15:22:36 -070010209 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
10214
10215 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010216 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010217 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010218 enforceModifyPermission();
10219
changbettyd5c246e2019-12-24 15:40:37 +080010220 final long identity = Binder.clearCallingIdentity();
10221 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010222 Phone phone = getPhone(subscriptionId);
10223 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010224
Ling Maf188d502022-09-16 15:22:36 -070010225 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
10230
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010231 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010232 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010233 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10234 * otherwise.
10235 */
10236 @Override
10237 public void setCepEnabled(boolean isCepEnabled) {
10238 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10239
10240 final long identity = Binder.clearCallingIdentity();
10241 try {
10242 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10243 for (Phone phone : PhoneFactory.getPhones()) {
10244 Phone defaultPhone = phone.getImsPhone();
10245 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10246 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10247 ImsPhoneCallTracker imsPhoneCallTracker =
10248 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10249 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10250 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10251 + imsPhone.getMsisdn());
10252 }
10253 }
10254 } finally {
10255 Binder.restoreCallingIdentity(identity);
10256 }
10257 }
allenwtsu46dcc572020-01-08 18:24:03 +080010258
10259 /**
10260 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10261 *
10262 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10263 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10264 * before being read.
10265 */
10266 @Override
10267 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10268 isCompressed) {
10269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10270 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010271 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10272 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10273 }
10274 if (!isImsAvailableOnDevice()) {
10275 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10276 "IMS not available on device.");
10277 }
10278
10279 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010280 try {
Hui Wang761a6682020-10-31 05:12:53 +000010281 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10282 } finally {
10283 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010284 }
10285 }
zoey chene02881a2019-12-30 16:11:23 +080010286
10287 @Override
10288 public boolean isIccLockEnabled(int subId) {
10289 enforceReadPrivilegedPermission("isIccLockEnabled");
10290
10291 // Now that all security checks passes, perform the operation as ourselves.
10292 final long identity = Binder.clearCallingIdentity();
10293 try {
10294 Phone phone = getPhone(subId);
10295 if (phone != null && phone.getIccCard() != null) {
10296 return phone.getIccCard().getIccLockEnabled();
10297 } else {
10298 return false;
10299 }
10300 } finally {
10301 Binder.restoreCallingIdentity(identity);
10302 }
10303 }
10304
10305 /**
10306 * Set the ICC pin lock enabled or disabled.
10307 *
10308 * @return an integer representing the status of IccLock enabled or disabled in the following
10309 * three cases:
10310 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10311 * successfully.
10312 * - Positive number and zero for remaining password attempts.
10313 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10314 *
10315 */
10316 @Override
10317 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10318 enforceModifyPermission();
10319
10320 Phone phone = getPhone(subId);
10321 if (phone == null) {
10322 return 0;
10323 }
10324 // Now that all security checks passes, perform the operation as ourselves.
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10328 new Pair<Boolean, String>(enabled, password), phone, null);
10329 return attemptsRemaining;
10330
10331 } catch (Exception e) {
10332 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10333 } finally {
10334 Binder.restoreCallingIdentity(identity);
10335 }
10336 return 0;
10337 }
10338
10339 /**
10340 * Change the ICC password used in ICC pin lock.
10341 *
10342 * @return an integer representing the status of IccLock changed in the following three cases:
10343 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10344 * - Positive number and zero for remaining password attempts.
10345 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10346 *
10347 */
10348 @Override
10349 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10350 enforceModifyPermission();
10351
10352 Phone phone = getPhone(subId);
10353 if (phone == null) {
10354 return 0;
10355 }
10356 // Now that all security checks passes, perform the operation as ourselves.
10357 final long identity = Binder.clearCallingIdentity();
10358 try {
10359 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10360 new Pair<String, String>(oldPassword, newPassword), phone, null);
10361 return attemptsRemaining;
10362
10363 } catch (Exception e) {
10364 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10365 } finally {
10366 Binder.restoreCallingIdentity(identity);
10367 }
10368 return 0;
10369 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010370
10371 /**
10372 * Request for receiving user activity notification
10373 */
10374 @Override
10375 public void requestUserActivityNotification() {
10376 if (!mNotifyUserActivity.get()
10377 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10378 mNotifyUserActivity.set(true);
10379 }
10380 }
10381
10382 /**
10383 * Called when userActivity is signalled in the power manager.
10384 * This is safe to call from any thread, with any window manager locks held or not.
10385 */
10386 @Override
10387 public void userActivity() {
10388 // ***************************************
10389 // * Inherited from PhoneWindowManager *
10390 // ***************************************
10391 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10392 // WITH ITS LOCKS HELD.
10393 //
10394 // This code must be VERY careful about the locks
10395 // it acquires.
10396 // In fact, the current code acquires way too many,
10397 // and probably has lurking deadlocks.
10398
10399 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10400 throw new SecurityException("Only the OS may call notifyUserActivity()");
10401 }
10402
10403 if (mNotifyUserActivity.getAndSet(false)) {
10404 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10405 USER_ACTIVITY_NOTIFICATION_DELAY);
10406 }
10407 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010408
10409 @Override
10410 public boolean canConnectTo5GInDsdsMode() {
10411 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10412 }
Jack Yud10cdd42020-09-28 20:28:01 -070010413
10414 @Override
10415 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10416 String callingFeatureId) {
10417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10418 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10419 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10420 }
10421
10422 Phone phone = getPhone(subId);
10423 if (phone == null) {
10424 throw new RuntimeException("phone is not available");
10425 }
10426 // Now that all security checks passes, perform the operation as ourselves.
10427 final long identity = Binder.clearCallingIdentity();
10428 try {
10429 return phone.getEquivalentHomePlmns();
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
Daniel Bright59e67312020-11-13 11:49:37 -080010434
10435 @Override
10436 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010437 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10438 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010439 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010440 if (radioInterfaceCapabilities == null) {
10441 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010442 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010443 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010444 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010445
Hui Wang641e81c2020-10-12 12:14:23 -070010446 @Override
10447 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10448 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010449 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10450 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10451 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10452 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10453 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010454 if (DBG) {
10455 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10456 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10457 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10458 }
10459
10460 if (!SubscriptionManager.isValidSubscriptionId(subId)
10461 || appType < TelephonyManager.APPTYPE_UNKNOWN
10462 || appType > TelephonyManager.APPTYPE_ISIM
10463 || nafUrl == null || securityProtocol == null || callback == null) {
10464 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10465 if (callback != null) {
10466 try {
10467 callback.onAuthenticationFailure(
10468 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10469 } catch (RemoteException exception) {
10470 log("Fail to notify onAuthenticationFailure due to " + exception);
10471 }
10472 return;
10473 }
10474 }
10475
10476 final long token = Binder.clearCallingIdentity();
10477 try {
10478 getGbaManager(subId).bootstrapAuthenticationRequest(
10479 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10480 forceBootStrapping, callback));
10481 } finally {
10482 Binder.restoreCallingIdentity(token);
10483 }
10484 }
10485
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010486 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010487 * Attempts to set the radio power state for all phones for thermal reason.
10488 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010489 * requested radio power state will actually be set. See {@link
10490 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10491 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010492 * @param enable {@code true} if trying to turn radio on.
10493 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10494 * false}.
10495 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010496 private boolean setRadioPowerForThermal(boolean enable) {
10497 boolean isPhoneAvailable = false;
10498 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10499 Phone phone = PhoneFactory.getPhone(i);
10500 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010501 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010502 isPhoneAvailable = true;
10503 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010504 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010505
10506 // return true if successfully informed the phone object about the thermal radio power
10507 // request.
10508 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010509 }
10510
10511 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010512 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010513 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10514 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10515 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10516 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10517 throw new IllegalArgumentException("modem does not support data throttling");
10518 }
10519
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010520 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10521 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010522 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010523 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10524 }
10525
Sarah Chinecc78c42022-03-31 21:16:48 -070010526 setDataEnabledForReason(
10527 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010528
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010529 if (isDataThrottlingSupported) {
10530 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010531 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010532 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10533 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10534 } else if (thermalMitigationResult
10535 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010536 log("Modem likely does not support data throttling on secondary carrier. Data " +
10537 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10538 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010539 }
10540 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010541 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010542
10543 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010544 }
10545
Jack Nudelman644b91a2021-03-12 14:09:48 -080010546 private static List<String> getThermalMitigationAllowlist(Context context) {
10547 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10548 for (String pckg : context.getResources()
10549 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10550 sThermalMitigationAllowlistedPackages.add(pckg);
10551 }
10552 }
10553
10554 return sThermalMitigationAllowlistedPackages;
10555 }
10556
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010557 private boolean isAnyPhoneInEmergencyState() {
10558 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10559 if (tm.isInEmergencyCall()) {
10560 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10561 return true;
10562 }
10563 for (Phone phone : PhoneFactory.getPhones()) {
10564 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10565 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10566 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10567 + phone.isInEcm());
10568 return true;
10569 }
10570 }
10571
10572 return false;
10573 }
10574
Jack Nudelman644b91a2021-03-12 14:09:48 -080010575 /**
10576 * Used by shell commands to add an authorized package name for thermal mitigation.
10577 * @param packageName name of package to be allowlisted
10578 * @param context
10579 */
10580 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10581 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10582 sThermalMitigationAllowlistedPackages.add(packageName);
10583 }
10584
10585 /**
10586 * Used by shell commands to remove an authorized package name for thermal mitigation.
10587 * @param packageName name of package to remove from allowlist
10588 * @param context
10589 */
10590 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10591 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10592 sThermalMitigationAllowlistedPackages.remove(packageName);
10593 }
10594
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010595 /**
10596 * Thermal mitigation request to control functionalities at modem.
10597 *
10598 * @param subId the id of the subscription.
10599 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010600 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010601 *
10602 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10603 */
10604 @Override
10605 @ThermalMitigationResult
10606 public int sendThermalMitigationRequest(
10607 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010608 ThermalMitigationRequest thermalMitigationRequest,
10609 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010610 enforceModifyPermission();
10611
Jack Nudelman644b91a2021-03-12 14:09:48 -080010612 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10613 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10614 .contains(callingPackage)) {
10615 throw new SecurityException("Calling package must be configured in the device config. "
10616 + "calling package: " + callingPackage);
10617 }
10618
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010619 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10620 final long identity = Binder.clearCallingIdentity();
10621
10622 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10623 try {
10624 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10625 switch (thermalMitigationAction) {
10626 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10627 thermalMitigationResult =
10628 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010629 thermalMitigationRequest.getDataThrottlingRequest(),
10630 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010631 break;
10632 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10633 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10634 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10635 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10636 }
10637
10638 // Ensure that radio is on. If not able to power on due to phone being
10639 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010640 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010641 thermalMitigationResult =
10642 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10643 break;
10644 }
10645
10646 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010647 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010648 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10649 break;
10650 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10651 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10652 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10653 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10654 }
10655
10656 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10657 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010658 Phone phone = getPhone(subId);
10659 if (phone == null) {
10660 thermalMitigationResult =
10661 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10662 break;
10663 }
10664
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010665 TelephonyConnectionService service =
10666 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010667 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010668 Log.e(LOG_TAG, "An emergency call is pending");
10669 thermalMitigationResult =
10670 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10671 break;
10672 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010673 thermalMitigationResult =
10674 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10675 break;
10676 }
10677 } else {
10678 thermalMitigationResult =
10679 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10680 break;
10681 }
10682
10683 // Turn radio off. If not able to power off due to phone being unavailable,
10684 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010685 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010686 thermalMitigationResult =
10687 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10688 break;
10689 }
10690 thermalMitigationResult =
10691 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10692 break;
10693 default:
10694 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10695 + "not exist. Requested action: " + thermalMitigationAction);
10696 }
10697 } catch (IllegalArgumentException e) {
10698 throw e;
10699 } catch (Exception e) {
10700 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10701 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10702 } finally {
10703 Binder.restoreCallingIdentity(identity);
10704 }
10705
10706 if (DBG) {
10707 log("thermalMitigationRequest returning with thermalMitigationResult: "
10708 + thermalMitigationResult);
10709 }
10710
10711 return thermalMitigationResult;
10712 }
Hui Wang641e81c2020-10-12 12:14:23 -070010713
10714 /**
10715 * Set the GbaService Package Name that Telephony will bind to.
10716 *
10717 * @param subId The sim that the GbaService is associated with.
10718 * @param packageName The name of the package to be replaced with.
10719 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10720 */
10721 @Override
10722 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10723 enforceModifyPermission();
10724
10725 final long identity = Binder.clearCallingIdentity();
10726 try {
10727 return getGbaManager(subId).overrideServicePackage(packageName);
10728 } finally {
10729 Binder.restoreCallingIdentity(identity);
10730 }
10731 }
10732
10733 /**
10734 * Return the package name of the currently bound GbaService.
10735 *
10736 * @param subId The sim that the GbaService is associated with.
10737 * @return the package name of the GbaService configuration, null if GBA is not supported.
10738 */
10739 @Override
10740 public String getBoundGbaService(int subId) {
10741 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10742
10743 final long identity = Binder.clearCallingIdentity();
10744 try {
10745 return getGbaManager(subId).getServicePackage();
10746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
10750
10751 /**
10752 * Set the release time for telephony to unbind GbaService.
10753 *
10754 * @param subId The sim that the GbaService is associated with.
10755 * @param interval The release time to unbind GbaService by millisecond.
10756 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10757 */
10758 @Override
10759 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10760 enforceModifyPermission();
10761
10762 final long identity = Binder.clearCallingIdentity();
10763 try {
10764 return getGbaManager(subId).overrideReleaseTime(interval);
10765 } finally {
10766 Binder.restoreCallingIdentity(identity);
10767 }
10768 }
10769
10770 /**
10771 * Return the release time for telephony to unbind GbaService.
10772 *
10773 * @param subId The sim that the GbaService is associated with.
10774 * @return The release time to unbind GbaService by millisecond.
10775 */
10776 @Override
10777 public int getGbaReleaseTime(int subId) {
10778 enforceReadPrivilegedPermission("getGbaReleaseTime");
10779
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 return getGbaManager(subId).getReleaseTime();
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
10787
10788 private GbaManager getGbaManager(int subId) {
10789 GbaManager instance = GbaManager.getInstance(subId);
10790 if (instance == null) {
10791 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10792 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10793 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10794 }
10795 return instance;
10796 }
Hui Wang761a6682020-10-31 05:12:53 +000010797
10798 /**
10799 * indicate whether the device and the carrier can support
10800 * RCS VoLTE single registration.
10801 */
10802 @Override
10803 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010804 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10805 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10806 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10807 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010808
10809 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10810 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10811 }
10812
10813 final long identity = Binder.clearCallingIdentity();
10814 try {
10815 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10816 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010817 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10818 if (isCapable != null) {
10819 return isCapable;
10820 }
Hui Wang761a6682020-10-31 05:12:53 +000010821 }
Hui Wang67af90e2021-06-04 16:57:15 -070010822 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10823 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010824 } finally {
10825 Binder.restoreCallingIdentity(identity);
10826 }
10827 }
10828
10829 /**
10830 * Register RCS provisioning callback.
10831 */
10832 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010833 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010834 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010835 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010836 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010837 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10838 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010839
10840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10841 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10842 }
10843 if (!isImsAvailableOnDevice()) {
10844 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10845 "IMS not available on device.");
10846 }
10847
10848 final long identity = Binder.clearCallingIdentity();
10849 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010850 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010851 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010852 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10853 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010854 }
Hui Wang761a6682020-10-31 05:12:53 +000010855 } finally {
10856 Binder.restoreCallingIdentity(identity);
10857 }
10858 }
10859
10860 /**
10861 * Unregister RCS provisioning callback.
10862 */
10863 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010864 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010865 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010866 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010867 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010868 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10869 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010870
10871 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10872 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10873 }
10874 if (!isImsAvailableOnDevice()) {
10875 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10876 "IMS not available on device.");
10877 }
10878
10879 final long identity = Binder.clearCallingIdentity();
10880 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010881 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010882 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010883 } finally {
10884 Binder.restoreCallingIdentity(identity);
10885 }
10886 }
10887
10888 /**
10889 * trigger RCS reconfiguration.
10890 */
10891 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010892 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10893 "triggerRcsReconfiguration",
10894 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010895
10896 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10897 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10898 }
10899 if (!isImsAvailableOnDevice()) {
10900 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10901 "IMS not available on device.");
10902 }
10903
10904 final long identity = Binder.clearCallingIdentity();
10905 try {
10906 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
10912 /**
10913 * Provide the client configuration parameters of the RCS application.
10914 */
10915 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010916 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10917 "setRcsClientConfiguration",
10918 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010919
10920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10921 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10922 }
10923 if (!isImsAvailableOnDevice()) {
10924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10925 "IMS not available on device.");
10926 }
10927
10928 final long identity = Binder.clearCallingIdentity();
10929
10930 try {
10931 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10932 if (configBinder == null) {
10933 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010934 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10935 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010936 } else {
10937 configBinder.setRcsClientConfiguration(rcc);
10938 }
joonhunshin3e154242021-09-17 06:33:39 +000010939
10940 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10941 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010942 } catch (RemoteException e) {
10943 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010944 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10945 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
10950
10951 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010952 * Enables or disables the test mode for RCS VoLTE single registration.
10953 */
10954 @Override
10955 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10956 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10957 "setRcsSingleRegistrationTestModeEnabled");
10958
10959 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10960 }
10961
10962 /**
10963 * Gets the test mode for RCS VoLTE single registration.
10964 */
10965 @Override
10966 public boolean getRcsSingleRegistrationTestModeEnabled() {
10967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10968 "getRcsSingleRegistrationTestModeEnabled");
10969
10970 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10971 }
10972
10973 /**
Hui Wang761a6682020-10-31 05:12:53 +000010974 * Overrides the config of RCS VoLTE single registration enabled for the device.
10975 */
10976 @Override
10977 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10979 "setDeviceSingleRegistrationEnabledOverride");
10980 enforceModifyPermission();
10981
10982 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10983 : Boolean.parseBoolean(enabledStr);
10984 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010985 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010986 }
10987
10988 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010989 * Sends a device to device communication message. Only usable via shell.
10990 * @param message message to send.
10991 * @param value message value.
10992 */
10993 @Override
10994 public void sendDeviceToDeviceMessage(int message, int value) {
10995 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010996 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010997 enforceModifyPermission();
10998
10999 final long identity = Binder.clearCallingIdentity();
11000 try {
11001 TelephonyConnectionService service =
11002 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11003 if (service == null) {
11004 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11005 return;
11006 }
11007 service.sendTestDeviceToDeviceMessage(message, value);
11008 } finally {
11009 Binder.restoreCallingIdentity(identity);
11010 }
11011 }
11012
Tyler Gunnbabbda02021-02-10 11:05:02 -080011013 /**
11014 * Sets the specified device to device transport active.
11015 * @param transport The transport to set active.
11016 */
11017 @Override
11018 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11020 "setActiveDeviceToDeviceTransport");
11021 enforceModifyPermission();
11022
11023 final long identity = Binder.clearCallingIdentity();
11024 try {
11025 TelephonyConnectionService service =
11026 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11027 if (service == null) {
11028 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11029 return;
11030 }
11031 service.setActiveDeviceToDeviceTransport(transport);
11032 } finally {
11033 Binder.restoreCallingIdentity(identity);
11034 }
11035 }
Tyler Gunn92479152021-01-20 16:30:10 -080011036
Tyler Gunnd4339262021-05-03 14:46:49 -070011037 @Override
11038 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11040 "setDeviceToDeviceForceEnabled");
11041
11042 final long identity = Binder.clearCallingIdentity();
11043 try {
11044 Arrays.stream(PhoneFactory.getPhones()).forEach(
11045 p -> {
11046 Phone thePhone = p.getImsPhone();
11047 if (thePhone != null && thePhone instanceof ImsPhone) {
11048 ImsPhone imsPhone = (ImsPhone) thePhone;
11049 CallTracker tracker = imsPhone.getCallTracker();
11050 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11051 ImsPhoneCallTracker imsPhoneCallTracker =
11052 (ImsPhoneCallTracker) tracker;
11053 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11054 }
11055 }
11056 }
11057 );
11058 } finally {
11059 Binder.restoreCallingIdentity(identity);
11060 }
11061 }
11062
Tyler Gunn92479152021-01-20 16:30:10 -080011063 /**
Hui Wang761a6682020-10-31 05:12:53 +000011064 * Gets the config of RCS VoLTE single registration enabled for the device.
11065 */
11066 @Override
11067 public boolean getDeviceSingleRegistrationEnabled() {
11068 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11069 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11070 }
11071
11072 /**
11073 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11074 */
11075 @Override
11076 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11078 "setCarrierSingleRegistrationEnabledOverride");
11079 enforceModifyPermission();
11080
11081 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11082 : Boolean.parseBoolean(enabledStr);
11083 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11084 subId, enabled);
11085 }
11086
11087 /**
11088 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11089 */
11090 @Override
11091 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11092 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11093 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11094 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011095
11096 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011097 * Overrides the ims feature validation result
11098 */
11099 @Override
11100 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11102 "setImsFeatureValidationOverride");
11103
11104 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11105 : Boolean.parseBoolean(enabledStr);
11106 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11107 subId, enabled);
11108 }
11109
11110 /**
11111 * Gets the ims feature validation override value
11112 */
11113 @Override
11114 public boolean getImsFeatureValidationOverride(int subId) {
11115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11116 "getImsFeatureValidationOverride");
11117 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11118 }
11119
11120 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011121 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11122 * their mobile plan.
11123 */
11124 @Override
11125 public String getMobileProvisioningUrl() {
11126 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11127 final long identity = Binder.clearCallingIdentity();
11128 try {
11129 return getDefaultPhone().getMobileProvisioningUrl();
11130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011134
James.cf Linbcdf8b32021-01-14 16:44:13 +080011135 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011136 * Get the EAB contact from the EAB database.
11137 */
11138 @Override
11139 public String getContactFromEab(String contact) {
11140 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11141 enforceModifyPermission();
11142 final long identity = Binder.clearCallingIdentity();
11143 try {
11144 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11145 } finally {
11146 Binder.restoreCallingIdentity(identity);
11147 }
11148 }
11149
11150 /**
Calvin Pana1434322021-07-01 19:27:01 +080011151 * Get the EAB capability from the EAB database.
11152 */
11153 @Override
11154 public String getCapabilityFromEab(String contact) {
11155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11156 enforceModifyPermission();
11157 final long identity = Binder.clearCallingIdentity();
11158 try {
11159 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 }
11164
11165 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011166 * Remove the EAB contacts from the EAB database.
11167 */
11168 @Override
11169 public int removeContactFromEab(int subId, String contacts) {
11170 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11171 enforceModifyPermission();
11172 final long identity = Binder.clearCallingIdentity();
11173 try {
11174 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11175 } finally {
11176 Binder.restoreCallingIdentity(identity);
11177 }
11178 }
11179
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011180 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011181 public boolean getDeviceUceEnabled() {
11182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 return mApp.getDeviceUceEnabled();
11186 } finally {
11187 Binder.restoreCallingIdentity(identity);
11188 }
11189 }
11190
11191 @Override
11192 public void setDeviceUceEnabled(boolean isEnabled) {
11193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11194 final long identity = Binder.clearCallingIdentity();
11195 try {
11196 mApp.setDeviceUceEnabled(isEnabled);
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 }
11201
Brad Ebinger14d467f2021-02-12 06:18:28 +000011202 /**
11203 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11204 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11205 */
11206 // Used for SHELL command only right now.
11207 @Override
11208 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11209 List<String> featureTags) {
11210 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11211 "addUceRegistrationOverrideShell");
11212 final long identity = Binder.clearCallingIdentity();
11213 try {
11214 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11215 new ArraySet<>(featureTags));
11216 } catch (ImsException e) {
11217 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11218 } finally {
11219 Binder.restoreCallingIdentity(identity);
11220 }
11221 }
11222
11223 /**
11224 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11225 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11226 */
11227 // Used for SHELL command only right now.
11228 @Override
11229 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11230 List<String> featureTags) {
11231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11232 "removeUceRegistrationOverrideShell");
11233 final long identity = Binder.clearCallingIdentity();
11234 try {
11235 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11236 new ArraySet<>(featureTags));
11237 } catch (ImsException e) {
11238 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11239 } finally {
11240 Binder.restoreCallingIdentity(identity);
11241 }
11242 }
11243
11244 /**
11245 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11246 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11247 */
11248 // Used for SHELL command only right now.
11249 @Override
11250 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11252 "clearUceRegistrationOverrideShell");
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11256 } catch (ImsException e) {
11257 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11258 } finally {
11259 Binder.restoreCallingIdentity(identity);
11260 }
11261 }
11262
11263 /**
11264 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11265 */
11266 // Used for SHELL command only right now.
11267 @Override
11268 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11270 "getLatestRcsContactUceCapabilityShell");
11271 final long identity = Binder.clearCallingIdentity();
11272 try {
11273 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11274 } catch (ImsException e) {
11275 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11276 } finally {
11277 Binder.restoreCallingIdentity(identity);
11278 }
11279 }
11280
11281 /**
11282 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11283 * device does not have an active PUBLISH.
11284 */
11285 // Used for SHELL command only right now.
11286 @Override
11287 public String getLastUcePidfXmlShell(int subId) {
11288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11289 final long identity = Binder.clearCallingIdentity();
11290 try {
11291 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11292 } catch (ImsException e) {
11293 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11294 } finally {
11295 Binder.restoreCallingIdentity(identity);
11296 }
11297 }
11298
James.cf Line8713a42021-04-29 16:04:26 +080011299 /**
11300 * Remove UCE requests cannot be sent to the network status.
11301 */
11302 // Used for SHELL command only right now.
11303 @Override
11304 public boolean removeUceRequestDisallowedStatus(int subId) {
11305 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11306 final long identity = Binder.clearCallingIdentity();
11307 try {
11308 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11309 } catch (ImsException e) {
11310 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11311 } finally {
11312 Binder.restoreCallingIdentity(identity);
11313 }
11314 }
11315
James.cf Lin18bb9002021-05-25 01:37:38 +080011316 /**
11317 * Remove UCE requests cannot be sent to the network status.
11318 */
11319 // Used for SHELL command only.
11320 @Override
11321 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11322 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11323 final long identity = Binder.clearCallingIdentity();
11324 try {
11325 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11326 } catch (ImsException e) {
11327 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11328 } finally {
11329 Binder.restoreCallingIdentity(identity);
11330 }
11331 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011332
James.cf Lin4b784aa2021-01-31 03:25:15 +080011333 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011334 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11335 String callingPackage) {
11336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11337 mApp, subId, "setSignalStrengthUpdateRequest");
11338
11339 final int callingUid = Binder.getCallingUid();
11340 // Verify that tha callingPackage belongs to the calling UID
11341 mApp.getSystemService(AppOpsManager.class)
11342 .checkPackage(callingUid, callingPackage);
11343
Rambo Wang3607f502021-02-01 21:51:40 -080011344 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011345
11346 final long identity = Binder.clearCallingIdentity();
11347 try {
11348 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11349 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11350
11351 if (result instanceof IllegalStateException) {
11352 throw (IllegalStateException) result;
11353 }
11354 } finally {
11355 Binder.restoreCallingIdentity(identity);
11356 }
11357 }
11358
11359 @Override
11360 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11361 String callingPackage) {
11362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11363 mApp, subId, "clearSignalStrengthUpdateRequest");
11364
11365 final int callingUid = Binder.getCallingUid();
11366 // Verify that tha callingPackage belongs to the calling UID
11367 mApp.getSystemService(AppOpsManager.class)
11368 .checkPackage(callingUid, callingPackage);
11369
11370 final long identity = Binder.clearCallingIdentity();
11371 try {
11372 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11373 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11374
11375 if (result instanceof IllegalStateException) {
11376 throw (IllegalStateException) result;
11377 }
11378 } finally {
11379 Binder.restoreCallingIdentity(identity);
11380 }
11381 }
11382
Rambo Wang3607f502021-02-01 21:51:40 -080011383 private static void validateSignalStrengthUpdateRequest(Context context,
11384 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011385 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11386 // phone/system process do not have further restriction on request
11387 return;
11388 }
11389
11390 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011391 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011392 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011393 context.enforceCallingOrSelfPermission(
11394 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11395 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011396 }
11397
11398 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011399 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011400 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011401 || info.isEnabled()) {
11402 throw new IllegalArgumentException(
11403 "Only system can set hide fields in SignalThresholdInfo");
11404 }
11405
11406 // Thresholds length for each RAN need in range. This has been validated in
11407 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11408 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11409 final int[] thresholds = info.getThresholds();
11410 Objects.requireNonNull(thresholds);
11411 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11412 || thresholds.length
11413 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11414 throw new IllegalArgumentException(
11415 "thresholds length is out of range: " + thresholds.length);
11416 }
11417 }
11418 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011419
11420 /**
11421 * Gets the current phone capability.
11422 *
11423 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11424 * @return the PhoneCapability which describes the data connection capability of modem.
11425 * It's used to evaluate possible phone config change, for example from single
11426 * SIM device to multi-SIM device.
11427 */
11428 @Override
11429 public PhoneCapability getPhoneCapability() {
11430 enforceReadPrivilegedPermission("getPhoneCapability");
11431 final long identity = Binder.clearCallingIdentity();
11432 try {
11433 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11434 } finally {
11435 Binder.restoreCallingIdentity(identity);
11436 }
11437 }
Michele Berionne5e411512020-11-13 02:36:59 +000011438
11439 /**
11440 * Prepare TelephonyManager for an unattended reboot. The reboot is
11441 * required to be done shortly after the API is invoked.
11442 */
11443 @Override
11444 @TelephonyManager.PrepareUnattendedRebootResult
11445 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011446 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011447 enforceRebootPermission();
11448
11449 final long identity = Binder.clearCallingIdentity();
11450 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011451 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011452 } finally {
11453 Binder.restoreCallingIdentity(identity);
11454 }
11455 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011456
11457 /**
11458 * Request to get the current slicing configuration including URSP rules and
11459 * NSSAIs (configured, allowed and rejected).
11460 *
11461 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11462 */
11463 @Override
11464 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011465 TelephonyPermissions
11466 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11467 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011468
11469 final long identity = Binder.clearCallingIdentity();
11470 try {
11471 Phone phone = getDefaultPhone();
11472 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11473 } finally {
11474 Binder.restoreCallingIdentity(identity);
11475 }
11476 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011477
11478 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011479 * Check whether the given premium capability is available for purchase from the carrier.
11480 *
11481 * @param capability The premium capability to check.
11482 * @param subId The subId to check the premium capability for.
11483 *
11484 * @return Whether the given premium capability is available to purchase.
11485 */
11486 @Override
11487 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11488 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11489 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11490 log("Premium capability "
11491 + TelephonyManager.convertPremiumCapabilityToString(capability)
11492 + " is not available for purchase due to missing permissions.");
11493 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11494 + "permission READ_BASIC_PHONE_STATE.");
11495 }
11496
11497 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011498 if (phone == null) {
11499 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11500 return false;
11501 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011502 final long identity = Binder.clearCallingIdentity();
11503 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011504 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011505 .isPremiumCapabilityAvailableForPurchase(capability);
11506 } finally {
11507 Binder.restoreCallingIdentity(identity);
11508 }
11509 }
11510
11511 /**
11512 * Purchase the given premium capability from the carrier.
11513 *
11514 * @param capability The premium capability to purchase.
11515 * @param callback The result of the purchase request.
11516 * @param subId The subId to purchase the premium capability for.
11517 */
11518 @Override
11519 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11520 log("purchasePremiumCapability: capability="
11521 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11522 + getCurrentPackageName());
11523
11524 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11525 mApp, "purchasePremiumCapability")) {
11526 log("purchasePremiumCapability "
11527 + TelephonyManager.convertPremiumCapabilityToString(capability)
11528 + " failed due to missing permissions.");
11529 throw new SecurityException("purchasePremiumCapability requires permission "
11530 + "READ_BASIC_PHONE_STATE.");
11531 }
11532
11533 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011534 if (phone == null) {
11535 try {
11536 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11537 callback.accept(result);
11538 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11539 } catch (RemoteException e) {
11540 String logStr = "Purchase premium capability "
11541 + TelephonyManager.convertPremiumCapabilityToString(capability)
11542 + " failed due to RemoteException handling null phone: " + e;
11543 if (DBG) log(logStr);
11544 AnomalyReporter.reportAnomaly(
11545 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11546 }
11547 return;
11548 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011549 String appName;
11550 try {
11551 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11552 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11553 } catch (PackageManager.NameNotFoundException e) {
11554 appName = "An application";
11555 }
11556 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11557 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011558 }
11559
11560 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011561 * Register an IMS connection state callback
11562 */
11563 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011564 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11565 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011566 if (feature == ImsFeature.FEATURE_MMTEL) {
11567 // ImsMmTelManager
11568 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11569 TelephonyPermissions
11570 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11571 mApp, subId, "registerImsStateCallback");
11572 } else if (feature == ImsFeature.FEATURE_RCS) {
11573 // ImsRcsManager or SipDelegateManager
11574 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11575 Binder.getCallingUid(), "registerImsStateCallback",
11576 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11577 Manifest.permission.READ_PRECISE_PHONE_STATE,
11578 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11579 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11580 }
11581
11582 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11583 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11584 "IMS not available on device.");
11585 }
11586
11587 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11588 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11589 }
11590
11591 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11592 if (controller == null) {
11593 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11594 "IMS not available on device.");
11595 }
11596
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011597 if (callingPackage == null) {
11598 callingPackage = getCurrentPackageName();
11599 }
11600
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011601 final long token = Binder.clearCallingIdentity();
11602 try {
11603 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011604 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011605 } catch (ImsException e) {
11606 throw new ServiceSpecificException(e.getCode());
11607 } finally {
11608 Binder.restoreCallingIdentity(token);
11609 }
11610 }
11611
11612 /**
11613 * Unregister an IMS connection state callback
11614 */
11615 @Override
11616 public void unregisterImsStateCallback(IImsStateCallback cb) {
11617 final long token = Binder.clearCallingIdentity();
11618 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11619 if (controller == null) {
11620 return;
11621 }
11622 try {
11623 controller.unregisterImsStateCallback(cb);
11624 } finally {
11625 Binder.restoreCallingIdentity(token);
11626 }
11627 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011628
11629 /**
11630 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11631 *
11632 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11633 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11634 * SecurityException.
11635 * If there is current registered network this value will be same as the registered cell
11636 * identity. If the device goes out of service the previous cell identity is cached and
11637 * will be returned. If the cache age of the Cell identity is more than 24 hours
11638 * it will be cleared and null will be returned.
11639 *
11640 */
11641 @Override
11642 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11643 String callingFeatureId) {
11644 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11645 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11646 LocationAccessPolicy.checkLocationPermission(mApp,
11647 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11648 .setCallingPackage(callingPackage)
11649 .setCallingFeatureId(callingFeatureId)
11650 .setCallingPid(Binder.getCallingPid())
11651 .setCallingUid(Binder.getCallingUid())
11652 .setMethod("getLastKnownCellIdentity")
11653 .setLogAsInfo(true)
11654 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11655 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11656 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11657 .build());
11658
11659 boolean hasFinePermission =
11660 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11661 if (!hasFinePermission
11662 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11663 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011664 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011665 }
11666
11667 final long identity = Binder.clearCallingIdentity();
11668 try {
11669 Phone phone = getPhone(subId);
11670 if (phone == null) return null;
11671 ServiceStateTracker sst = phone.getServiceStateTracker();
11672 if (sst == null) return null;
11673 return sst.getLastKnownCellIdentity();
11674 } finally {
11675 Binder.restoreCallingIdentity(identity);
11676 }
11677 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011678
jimsun3b9ccac2021-10-26 15:01:23 +080011679 /**
11680 * Sets the modem service class Name that Telephony will bind to.
11681 *
11682 * @param serviceName The class name of the modem service.
11683 * @return true if the operation is succeed, otherwise false.
11684 */
11685 public boolean setModemService(String serviceName) {
11686 Log.d(LOG_TAG, "setModemService - " + serviceName);
11687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11689 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11690 "setModemService");
11691 return mPhoneConfigurationManager.setModemService(serviceName);
11692 }
11693
11694 /**
11695 * Return the class name of the currently bounded modem service.
11696 *
11697 * @return the class name of the modem service.
11698 */
11699 public String getModemService() {
11700 String result;
11701 Log.d(LOG_TAG, "getModemService");
11702 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11703 TelephonyPermissions
11704 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11705 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11706 "getModemService");
11707 result = mPhoneConfigurationManager.getModemService();
11708 Log.d(LOG_TAG, "result = " + result);
11709 return result;
11710 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011711
11712 @Override
11713 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11714 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11715 mApp.enforceCallingOrSelfPermission(
11716 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11718
11719 final long identity = Binder.clearCallingIdentity();
11720 try {
11721 Phone phone = getPhone(subId);
11722 if (phone == null) return;
11723 phone.setVoiceServiceStateOverride(hasService);
11724 } finally {
11725 Binder.restoreCallingIdentity(identity);
11726 }
11727 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011728
11729 /**
11730 * set removable eSIM as default eUICC.
11731 *
11732 * @hide
11733 */
11734 @Override
11735 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11736 enforceModifyPermission();
11737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11738
11739 final long identity = Binder.clearCallingIdentity();
11740 try {
11741 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11742 } finally {
11743 Binder.restoreCallingIdentity(identity);
11744 }
11745 }
11746
11747 /**
11748 * Returns whether the removable eSIM is default eUICC or not.
11749 *
11750 * @hide
11751 */
11752 @Override
11753 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11754 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11756
11757 final long identity = Binder.clearCallingIdentity();
11758 try {
11759 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11760 } finally {
11761 Binder.restoreCallingIdentity(identity);
11762 }
11763 }
11764
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011765 /**
11766 * Get the component name of the default app to direct respond-via-message intent for the
11767 * user associated with this subscription, update the cache if there is no respond-via-message
11768 * application currently configured for this user.
11769 * @return component name of the app and class to direct Respond Via Message intent to, or
11770 * {@code null} if the functionality is not supported.
11771 * @hide
11772 */
11773 @Override
11774 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11775 boolean updateIfNeeded) {
11776 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011777
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011778 Context context = getPhone(subId).getContext();
11779 UserHandle userHandle = null;
11780 final long identity = Binder.clearCallingIdentity();
11781 try {
11782 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11783 } finally {
11784 Binder.restoreCallingIdentity(identity);
11785 }
11786 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11787 updateIfNeeded, userHandle);
11788 }
Jack Yuf5badd92022-12-08 00:50:53 -080011789
11790 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011791 * Set whether the device is able to connect with null ciphering or integrity
11792 * algorithms. This is a global setting and will apply to all active subscriptions
11793 * and all new subscriptions after this.
11794 *
11795 * @param enabled when true, null cipher and integrity algorithms are allowed.
11796 * @hide
11797 */
11798 @Override
11799 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11800 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11801 enforceModifyPermission();
11802 checkForNullCipherAndIntegritySupport();
11803
11804 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11805 // for listening to these preference changes and applying them immediately.
11806 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11807 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11808 editor.apply();
11809
11810 for (Phone phone: PhoneFactory.getPhones()) {
11811 phone.handleNullCipherEnabledChange();
11812 }
11813 }
11814
11815
11816 /**
11817 * Get whether the device is able to connect with null ciphering or integrity
11818 * algorithms. Note that this retrieves the phone-global preference and not
11819 * the state of the radio.
11820 *
11821 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11822 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11823 * version for this feature.
11824 * @hide
11825 */
11826 @Override
11827 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11828 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11829 enforceReadPermission();
11830 checkForNullCipherAndIntegritySupport();
11831 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11832 }
11833
11834 private void checkForNullCipherAndIntegritySupport() {
11835 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11836 throw new UnsupportedOperationException(
11837 "Null cipher and integrity operations require HAL 2.1 or above");
11838 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011839 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11840 throw new UnsupportedOperationException(
11841 "Null cipher and integrity operations unsupported by modem");
11842 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011843 }
11844
11845 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011846 * Get the SIM state for the slot index.
11847 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11848 *
11849 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11850 */
11851 @Override
11852 @SimState
11853 public int getSimStateForSlotIndex(int slotIndex) {
11854 IccCardConstants.State simState;
11855 if (slotIndex < 0) {
11856 simState = IccCardConstants.State.UNKNOWN;
11857 } else {
11858 Phone phone = null;
11859 try {
11860 phone = PhoneFactory.getPhone(slotIndex);
11861 } catch (IllegalStateException e) {
11862 // ignore
11863 }
11864 if (phone == null) {
11865 simState = IccCardConstants.State.UNKNOWN;
11866 } else {
11867 IccCard icc = phone.getIccCard();
11868 if (icc == null) {
11869 simState = IccCardConstants.State.UNKNOWN;
11870 } else {
11871 simState = icc.getState();
11872 }
11873 }
11874 }
11875 return simState.ordinal();
11876 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011877
11878 /**
11879 * Get current cell broadcast ranges.
11880 */
11881 @Override
11882 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11883 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11884 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11885 "getCellBroadcastIdRanges");
11886 final long identity = Binder.clearCallingIdentity();
11887 try {
11888 return getPhone(subId).getCellBroadcastIdRanges();
11889 } finally {
11890 Binder.restoreCallingIdentity(identity);
11891 }
11892 }
11893
11894 /**
11895 * Set reception of cell broadcast messages with the list of the given ranges
11896 *
11897 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11898 */
11899 @Override
11900 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11901 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11902 @Nullable IIntegerConsumer callback) {
11903 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11904 "setCellBroadcastIdRanges");
11905 final long identity = Binder.clearCallingIdentity();
11906 try {
11907 Phone phone = getPhoneFromSubId(subId);
11908 if (DBG) {
11909 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11910 }
11911 phone.setCellBroadcastIdRanges(ranges, result -> {
11912 if (callback != null) {
11913 try {
11914 callback.accept(result);
11915 } catch (RemoteException e) {
11916 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
11917 }
11918 }
11919 });
11920 } finally {
11921 Binder.restoreCallingIdentity(identity);
11922 }
11923 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000011924
11925 /**
11926 * Returns whether the device supports the domain selection service.
11927 *
11928 * @return {@code true} if the device supports the domain selection service.
11929 */
11930 @Override
11931 public boolean isDomainSelectionSupported() {
11932 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11933 "isDomainSelectionSupported");
11934
11935 final long identity = Binder.clearCallingIdentity();
11936 try {
11937 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
11938 } finally {
11939 Binder.restoreCallingIdentity(identity);
11940 }
11941 }
arunvoddud5c6ce02022-12-11 06:03:12 +000011942
11943 /**
11944 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
11945 *
11946 * <p>This method behaves in one of the following ways:
11947 * <ul>
11948 * <li>return true : if the calling package has the appop permission {@link
11949 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
11950 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
11951 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
11952 * Owner device identifier access check, or the calling package has carrier privileges</>
11953 * <li>throw SecurityException: if the caller does not meet any of the requirements.
11954 * </ul>
11955 */
11956 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
11957 String callingPackage, @Nullable String callingFeatureId, String message) {
11958 for (Phone phone : PhoneFactory.getPhones()) {
11959 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
11960 phone.getSubId(), callingPackage, callingFeatureId, message)) {
11961 return true;
11962 }
11963 }
11964 return false;
11965 }
arunvoddud7401012022-12-15 16:08:12 +000011966
11967 /**
11968 * Class binds the consumer[callback] and carrierId.
11969 */
11970 private static class CallerCallbackInfo {
11971 private final Consumer<Integer> mConsumer;
11972 private final int mCarrierId;
11973
11974 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
11975 mConsumer = consumer;
11976 mCarrierId = carrierId;
11977 }
11978
11979 public Consumer<Integer> getConsumer() {
11980 return mConsumer;
11981 }
11982
11983 public int getCarrierId() {
11984 return mCarrierId;
11985 }
11986 }
arunvoddud5c6ce02022-12-11 06:03:12 +000011987}